@Test
public void testGetHostComponents___ServiceComponentHostFilteredByState() throws Exception {

  // member state mocks
  Injector injector = createStrictMock(Injector.class);
  Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture();
  StackId stack = createNiceMock(StackId.class);
  Cluster cluster = createNiceMock(Cluster.class);
  final Host host = createNiceMock(Host.class);
  Service service = createNiceMock(Service.class);
  ServiceComponent component = createNiceMock(ServiceComponent.class);
  MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
  final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
  ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
  // requests
  ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
      "cluster1", null, "component1", "host1", null);
  request1.setState("INSTALLED");
  Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
  setRequests.add(request1);
  // expectations
  // constructor init
  injector.injectMembers(capture(controllerCapture));
  expect(injector.getInstance(Gson.class)).andReturn(null);
  expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper);
  expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class));
  expect(maintHelper.getEffectiveState(
      anyObject(ServiceComponentHost.class),
      anyObject(Host.class))).andReturn(MaintenanceState.OFF).anyTimes();
  // getHostComponent
  expect(clusters.getCluster("cluster1")).andReturn(cluster);
  expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
  expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
      new HashMap<String, Host>() {{
        put("host1", host);
      }}).anyTimes();
  expect(cluster.getDesiredStackVersion()).andReturn(stack);
  expect(cluster.getClusterName()).andReturn("cl1");
  expect(stack.getStackName()).andReturn("stackName");
  expect(stack.getStackVersion()).andReturn("stackVersion");
  expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
  expect(cluster.getService("service1")).andReturn(service);
  expect(service.getServiceComponent("component1")).andReturn(component);
  expect(component.getName()).andReturn("component1").anyTimes();
  expect(component.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>() {{
    put("host1", componentHost1);
  }});
  expect(componentHost1.getState()).andReturn(State.INSTALLED);
  expect(componentHost1.convertToResponse(null)).andReturn(response1);
  expect(componentHost1.getHostName()).andReturn("host1");
  // replay mocks
  replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo,
      service, component, componentHost1, response1);
  //test
  AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
  setAmbariMetaInfo(ambariMetaInfo, controller);
  Set<ServiceComponentHostResponse> responses = controller.getHostComponents(setRequests);
  // assert and verify
  assertSame(controller, controllerCapture.getValue());
  assertTrue(responses.size() == 1);
  verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1);
}