# HG changeset patch # User Omair Majid # Date 1444751355 14400 # Node ID 7a3dcb6148be3bd9fc79fda5496fe9a159129817 # Parent 99efc6c1656fb9ed31d6354da9f12a21026c42c4 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 diff -r 99efc6c1656f -r 7a3dcb6148be client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecorator.java --- 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; } } diff -r 99efc6c1656f -r 7a3dcb6148be client/living-vm-filter/swing/src/test/java/com/redhat/thermostat/client/filter/host/swing/ThermostatVmMainLabelDecoratorTest.java --- 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);