changeset 1848:7a3dcb6148be

Fix GUI label for agent vm PR 2838 Reviewed-by: jerboaa, neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-October/016728.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-February/017658.html
author Omair Majid <omajid@redhat.com>
date Tue, 13 Oct 2015 11:49:15 -0400
parents 99efc6c1656f
children 1de83fee88ce
files client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecorator.java client/living-vm-filter/swing/src/test/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecoratorTest.java
diffstat 2 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecorator.java	Mon Dec 14 12:20:54 2015 -0500
+++ b/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecorator.java	Tue Oct 13 11:49:15 2015 -0400
@@ -36,6 +36,7 @@
 
 package com.redhat.thermostat.client.filter.host.swing;
 
+import java.util.Arrays;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -105,23 +106,25 @@
     }
 
     private String createLabelForRegularCommand(VmInfo info) {
-        String[]  s = info.getJavaCommandLine().split("\\."); //escaped dot
-        String afterDot = s[s.length - 1];
+        String commandLine = info.getJavaCommandLine();
 
-        // heuristic: take the first two non-option arguments
+        // heuristic: take the first non-option argument
 
         // FIXME this doesn't work if --boot-delegation appears before the
         // subcommand. --boot-delegation requires a separate value.
-        String[] parts = afterDot.split("\\s+");
+        String[] parts = commandLine.split("\\s+");
+        parts = Arrays.copyOfRange(parts, 1, parts.length);
+
         int argumentCount = 0;
         StringBuilder result = new StringBuilder();
+        result.append("Thermostat ");
         for (String part : parts) {
             if (part.startsWith("--")) {
                 continue;
             }
             result.append(part).append(" ");
             argumentCount++;
-            if (argumentCount == 2) {
+            if (argumentCount == 1) {
                 break;
             }
         }
--- a/client/living-vm-filter/swing/src/test/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecoratorTest.java	Mon Dec 14 12:20:54 2015 -0500
+++ b/client/living-vm-filter/swing/src/test/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecoratorTest.java	Tue Oct 13 11:49:15 2015 -0400
@@ -37,7 +37,6 @@
 package com.redhat.thermostat.client.filter.host.swing;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -81,7 +80,7 @@
         
         decorator = new ThermostatVmMainLabelDecorator(dao);
         String result = decorator.getLabel("originalLabel", vmRef);
-        assertTrue(result.equals("Thermostat service"));
+        assertEquals("Thermostat service", result);
     }
 
     @Test
@@ -119,6 +118,17 @@
     }
 
     @Test
+    public void verifyLabelForCliCommand2() {
+        when(vmRef.getName()).thenReturn(THERMOSTAT_MAIN_CLASS);
+        when(info.getMainClass()).thenReturn(THERMOSTAT_MAIN_CLASS);
+        when(info.getJavaCommandLine()).thenReturn("com.redhat.thermostat.main.Thermostat agent -d http://127.0.0.1:8999/thermostat/storage");
+
+        decorator = new ThermostatVmMainLabelDecorator(dao);
+        String result = decorator.getLabel("originalLabel", vmRef);
+        assertEquals("Thermostat agent", result);
+    }
+
+    @Test
     public void verifyLabelWhenGlobalOptionIsUsed() {
         when(vmRef.getName()).thenReturn(THERMOSTAT_MAIN_CLASS);
         when(info.getMainClass()).thenReturn(THERMOSTAT_MAIN_CLASS);