// member state mocks
Injector injector = createStrictMock(Injector.class);
Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
Clusters clusters = createNiceMock(Clusters.class);
StackId stack = createNiceMock(StackId.class);
AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
Cluster cluster = createNiceMock(Cluster.class);
Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
Service service2 = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
// requests
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
"cluster1", null, "component1", null, Collections.<String, String>emptyMap(), null);
ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
"cluster1", null, "component2", "host2", Collections.<String, String>emptyMap(), null);
ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
"cluster1", null, "component3", null, Collections.<String, String>emptyMap(), null);
Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
// expectations
// constructor init
injector.injectMembers(capture(controllerCapture));
expect(injector.getInstance(Gson.class)).andReturn(null);
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
//expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1");
expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost1));
expect(componentHost1.convertToResponse()).andReturn(response1);
expect(clusters.getClustersForHost("host2")).andThrow(new HostNotFoundException("host2"));
expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost2));
expect(componentHost2.convertToResponse()).andReturn(response2);