package io.pcp.parfait;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;

import org.junit.Test;

public class MonitoringViewNamesTest {
    @Test
    public void checkJvmProcessString() {
        // expecting to be of form "pid@host" (need new JVM-specific code if not)
        String name = MonitoringViewProperties.getRuntimeName();
        assertNotNull(name);
        assertNotSame(name, "");

        String[] pidAndHost = name.split("@", 2);
        assertNotNull(pidAndHost);
        assertEquals(pidAndHost.length, 2);

        int pid = Integer.parseInt(pidAndHost[0]);
        assertEquals(pidAndHost.length, 2);
    }

    @Test
    public void checkProcessIdentifierExtraction() {
        assertEquals(MonitoringViewProperties.getFallbackName(""), MonitoringViewProperties.PARFAIT);
        assertEquals(MonitoringViewProperties.getFallbackName("12345"), MonitoringViewProperties.PARFAIT);
        assertEquals(MonitoringViewProperties.getFallbackName("@localhost"), MonitoringViewProperties.PARFAIT);
        assertEquals(MonitoringViewProperties.getFallbackName("12345@localhost"), MonitoringViewProperties.PARFAIT + "12345");
    }

    @Test
    public void checkDefaultNameResults() {
        assertEquals(MonitoringViewProperties.getDefaultName(null, null, null), MonitoringViewProperties.PARFAIT);
        assertEquals(MonitoringViewProperties.getDefaultName("foo", null, null), "foo");
        assertEquals(MonitoringViewProperties.getDefaultName("foo", "bar", null), "foo");
        assertEquals(MonitoringViewProperties.getDefaultName(null, "bar", null), "bar");
        assertEquals(MonitoringViewProperties.getDefaultName(null, null, "baz"), MonitoringViewProperties.PARFAIT);
    }
}

@@ -154,16 +154,59 @@
 NotSame;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -723,35 +723,20 @@
 sert
-Equals(pidAndHost.length, 2
+True(pid %3E 0
 );%0A 

Fix cut+paste error on parfait-agent MonitoringViewNames test