ComponentResourceProvider extends AbstractControllerResourceProvider { protected Set<ServiceComponentResponse> getComponents(Set<ServiceComponentRequest> requests) throws AmbariException { Set<ServiceComponentResponse> response = new HashSet<>(); for (ServiceComponentRequest request : requests) { try { response.addAll(getComponents(request)); } catch (ObjectNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  ComponentResourceProvider(@Assisted Set<String> propertyIds,
                            @Assisted Map<Resource.Type, String> keyPropertyIds,
                            @Assisted AmbariManagementController managementController,
                            MaintenanceStateHelper maintenanceStateHelper); @Override @Transactional Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResourcesAuthorized(final Request request, Predicate predicate); void createComponents(Set<ServiceComponentRequest> requests);  }
@Test public void testGetComponents() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); Clusters clusters = createNiceMock(Clusters.class); AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); StackId stackId = createNiceMock(StackId.class); Cluster cluster = createNiceMock(Cluster.class); Service service = createNiceMock(Service.class); ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); ServiceComponent component = createNiceMock(ServiceComponent.class); ServiceComponentResponse response = createNiceMock(ServiceComponentResponse.class); ServiceComponentRequest request1 = new ServiceComponentRequest("cluster1", "service1", "component1", null, String.valueOf(true )); Set<ServiceComponentRequest> setRequests = new HashSet<ServiceComponentRequest>(); setRequests.add(request1); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); expect(stackId.getStackName()).andReturn("stackName").anyTimes(); expect(stackId.getStackVersion()).andReturn("1").anyTimes(); expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(cluster.getService("service1")).andReturn(service); expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes(); expect(service.getName()).andReturn("service1").anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component); expect(ambariMetaInfo.getComponent("stackName", "1", "service1", "component1")).andReturn(componentInfo); expect(componentInfo.getCategory()).andReturn(null); expect(component.convertToResponse()).andReturn(response); replay(clusters, cluster, service, componentInfo, component, response, ambariMetaInfo, stackId, managementController); Set<ServiceComponentResponse> setResponses = getComponentResourceProvider(managementController).getComponents(setRequests); assertEquals(1, setResponses.size()); assertTrue(setResponses.contains(response)); verify(clusters, cluster, service, componentInfo, component, response, ambariMetaInfo, stackId, managementController); }