Service service = createNiceMock(Service.class);
ServiceComponent serviceComponent1 = createNiceMock(ServiceComponent.class);
ServiceComponent serviceComponent2 = createNiceMock(ServiceComponent.class);
ServiceComponent serviceComponent3 = createNiceMock(ServiceComponent.class);
StackId stackId = createNiceMock(StackId.class);
final ComponentInfo componentInfo1 = createNiceMock(ComponentInfo.class);
final ComponentInfo componentInfo2 = createNiceMock(ComponentInfo.class);
Map<String, ServiceComponent> serviceComponentMap = new HashMap<String, ServiceComponent>();
serviceComponentMap.put("Component101", serviceComponent1);
serviceComponentMap.put("Component102", serviceComponent2);
serviceComponentMap.put("Component103", serviceComponent3);
// set expectations
expect(managementController.getClusters()).andReturn(clusters);
expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stackId);
expect(cluster.getServices()).andReturn(Collections.singletonMap("Service100", service)).anyTimes();
expect(service.getServiceComponents()).andReturn(serviceComponentMap).anyTimes();
expect(serviceComponent1.convertToResponse()).andReturn(
new ServiceComponentResponse(100L, "Cluster100", "Service100", "Component100", null, "", 1, 1, 0));
expect(serviceComponent2.convertToResponse()).andReturn(
new ServiceComponentResponse(100L, "Cluster100", "Service100", "Component101", null, "", 1, 1, 0));
expect(serviceComponent3.convertToResponse()).andReturn(
new ServiceComponentResponse(100L, "Cluster100", "Service100", "Component102", null, "", 1, 1, 0));
expect(ambariMetaInfo.getComponentCategory((String) anyObject(),
(String) anyObject(), (String) anyObject(), (String) anyObject()))
.andReturn(componentInfo1).times(2).andReturn(componentInfo2);
expect(componentInfo1.getCategory()).andReturn("MASTER").anyTimes();
expect(componentInfo2.getCategory()).andReturn("SLAVE").anyTimes();
// replay
replay(managementController, clusters, cluster, ambariMetaInfo, service,
serviceComponent1, serviceComponent2, serviceComponent3, stackId,
componentInfo1, componentInfo2);