HostCommands implements CommandMarker { @CliCommand(value = "host focus", help = "Sets the useHost to the specified host") public String focusHost( @CliOption(key = "host", mandatory = true, help = "hostname") Host host) { String message; String hostName = host.getName(); if (client.getHostNames().keySet().contains(hostName)) { context.setFocus(hostName, FocusType.HOST); message = "Focus set to: " + hostName; } else { message = hostName + " is not a valid host name"; } return message; } @Autowired  HostCommands(AmbariClient client, AmbariContext context); @CliAvailabilityIndicator("host list") boolean isHostsCommandAvailable(); @CliCommand(value = "host list", help = "Lists the available hosts") String hosts(); @CliAvailabilityIndicator("host focus") boolean isFocusHostCommandAvailable(); @CliCommand(value = "host focus", help = "Sets the useHost to the specified host") String focusHost(
    @CliOption(key = "host", mandatory = true, help = "hostname") Host host); @CliAvailabilityIndicator("host components") boolean isHostComponentsCommandAvailable(); @CliCommand(value = "host components", help = "Lists the components assigned to the selected host") String hostComponents();  }
@Test public void testFocusHostForValidHost() { when(client.getHostNames()).thenReturn(singletonMap("host1", "HEALTHY")); String result = hostCommands.focusHost(new Host("host1")); verify(context).setFocus("host1", FocusType.HOST); assertEquals("Focus set to: host1", result); }
@Test public void testFocusHostForInvalidHost() { when(client.getHostNames()).thenReturn(singletonMap("host3", "HEALTHY")); String result = hostCommands.focusHost(new Host("host1")); verify(context, times(0)).setFocus("host1", FocusType.HOST); assertEquals("host1 is not a valid host name", result); }