### Question:
StackServiceResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackServiceRequest> requests = new HashSet<>(); if (predicate == null) { requests.add(getRequest(Collections.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<>(); for (StackServiceResponse response : responses) { Resource resource = createResource(response, requestedIds); resources.add(resource); } return resources; } protected  StackServiceResourceProvider(AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; }### Answer:
@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.anyObject())) .andReturn(ImmutableSet.of(stackServiceResponse)); replay(managementController, stackServiceResponse); Request request = PropertyHelper.getReadRequest(SERVICE_PROPERTIES_PROPERTY_ID); ResourceProvider stackServiceResourceProvider = AbstractControllerResourceProvider.getResourceProvider(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); }
@Test public void testGetVisibilityServiceProperties() throws Exception { AmbariManagementController managementController = createNiceMock(AmbariManagementController.class); Resource.Type type = Resource.Type.StackService; ServiceInfo serviceInfo = new ServiceInfo() ; serviceInfo.setServicePropertyList(TEST_SERVICE_PROPERTY_LIST); StackServiceResponse stackServiceResponse = new StackServiceResponse(serviceInfo); expect(managementController.getStackServices(EasyMock.anyObject())) .andReturn(ImmutableSet.of(stackServiceResponse)); replay(managementController); Request request = PropertyHelper.getReadRequest(SERVICE_PROPERTIES_PROPERTY_ID); ResourceProvider stackServiceResourceProvider = AbstractControllerResourceProvider.getResourceProvider(type, managementController); Set<Resource> resources = stackServiceResourceProvider.getResources(request, null); Map<String, String> expectedServiceProperties = ImmutableMap.<String, String>builder() .putAll(TEST_SERVICE_PROPERTIES) .put(ServiceInfo.DEFAULT_SERVICE_INSTALLABLE_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MANAGED_PROPERTY) .put(ServiceInfo.DEFAULT_SERVICE_MONITORED_PROPERTY) .build(); Resource expected = new ResourceImpl(type); BaseProvider.setResourceProperty(expected, SERVICE_PROPERTIES_PROPERTY_ID, expectedServiceProperties, ImmutableSet.of(SERVICE_PROPERTIES_PROPERTY_ID)); assertEquals(ImmutableSet.of(expected), resources); verify(managementController); }