@Test public void testGetServiceProperties() throws Exception { AmbariManagementController managementController = createNiceMock(AmbariManagementController.class); Resource.Type type = Resource.Type.StackService; StackServiceResponse stackServiceResponse = createNiceMock(StackServiceResponse.class); expect(stackServiceResponse.getServiceProperties()).andReturn(TEST_SERVICE_PROPERTIES); expect(managementController.getStackServices(EasyMock.<Set<StackServiceRequest>>anyObject())) .andReturn(ImmutableSet.of(stackServiceResponse)); replay(managementController, stackServiceResponse); Request request = PropertyHelper.getReadRequest(SERVICE_PROPERTIES_PROPERTY_ID); ResourceProvider stackServiceResourceProvider = AbstractControllerResourceProvider.getResourceProvider(type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<Resource> resources = stackServiceResourceProvider.getResources(request, null); Resource expected = new ResourceImpl(type); BaseProvider.setResourceProperty(expected, SERVICE_PROPERTIES_PROPERTY_ID, TEST_SERVICE_PROPERTIES, ImmutableSet.of(SERVICE_PROPERTIES_PROPERTY_ID)); assertEquals(ImmutableSet.of(expected), resources); verify(managementController, stackServiceResponse); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<StackServiceRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() { @Override public Set<StackServiceResponse> invoke() throws AmbariException { return getManagementController().getStackServices(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; }
StackServiceResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<StackServiceRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() { @Override public Set<StackServiceResponse> invoke() throws AmbariException { return getManagementController().getStackServices(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; } }
StackServiceResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<StackServiceRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() { @Override public Set<StackServiceResponse> invoke() throws AmbariException { return getManagementController().getStackServices(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; } protected  StackServiceResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
StackServiceResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<StackServiceRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() { @Override public Set<StackServiceResponse> invoke() throws AmbariException { return getManagementController().getStackServices(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; } protected  StackServiceResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); }
StackServiceResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<StackServiceRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() { @Override public Set<StackServiceResponse> invoke() throws AmbariException { return getManagementController().getStackServices(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; } protected  StackServiceResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; }