@Test public void testGetResources() throws Exception { Resource.Type type = Resource.Type.Extension; AmbariManagementController managementController = createMock(AmbariManagementController.class); Set<ExtensionResponse> allResponse = new HashSet<ExtensionResponse>(); allResponse.add(new ExtensionResponse("Extension1")); allResponse.add(new ExtensionResponse("Extension2")); expect(managementController.getExtensions(EasyMock.<Set<ExtensionRequest>>anyObject())).andReturn(allResponse).once(); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(ExtensionResourceProvider.EXTENSION_NAME_PROPERTY_ID); Request request = PropertyHelper.getReadRequest(propertyIds); Set<Resource> resources = provider.getResources(request, null); Assert.assertEquals(2, resources.size()); Set<String> extensionNames = new HashSet<String>(); extensionNames.add("Extension1"); extensionNames.add("Extension2"); for (Resource resource : resources) { String extensionName = (String) resource.getPropertyValue(ExtensionResourceProvider.EXTENSION_NAME_PROPERTY_ID); Assert.assertTrue(extensionNames.contains(extensionName)); } verify(managementController); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<ExtensionRequest> requests = new HashSet<ExtensionRequest>(); 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<ExtensionResponse> responses = getResources(new Command<Set<ExtensionResponse>>() { @Override public Set<ExtensionResponse> invoke() throws AmbariException { return getManagementController().getExtensions(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (ExtensionResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Extension); setResourceProperty(resource, EXTENSION_NAME_PROPERTY_ID, response.getExtensionName(), requestedIds); resource.setProperty(EXTENSION_NAME_PROPERTY_ID, response.getExtensionName()); resources.add(resource); } return resources; }
ExtensionResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<ExtensionRequest> requests = new HashSet<ExtensionRequest>(); 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<ExtensionResponse> responses = getResources(new Command<Set<ExtensionResponse>>() { @Override public Set<ExtensionResponse> invoke() throws AmbariException { return getManagementController().getExtensions(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (ExtensionResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Extension); setResourceProperty(resource, EXTENSION_NAME_PROPERTY_ID, response.getExtensionName(), requestedIds); resource.setProperty(EXTENSION_NAME_PROPERTY_ID, response.getExtensionName()); resources.add(resource); } return resources; } }
ExtensionResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<ExtensionRequest> requests = new HashSet<ExtensionRequest>(); 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<ExtensionResponse> responses = getResources(new Command<Set<ExtensionResponse>>() { @Override public Set<ExtensionResponse> invoke() throws AmbariException { return getManagementController().getExtensions(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (ExtensionResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Extension); setResourceProperty(resource, EXTENSION_NAME_PROPERTY_ID, response.getExtensionName(), requestedIds); resource.setProperty(EXTENSION_NAME_PROPERTY_ID, response.getExtensionName()); resources.add(resource); } return resources; } protected  ExtensionResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
ExtensionResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<ExtensionRequest> requests = new HashSet<ExtensionRequest>(); 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<ExtensionResponse> responses = getResources(new Command<Set<ExtensionResponse>>() { @Override public Set<ExtensionResponse> invoke() throws AmbariException { return getManagementController().getExtensions(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (ExtensionResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Extension); setResourceProperty(resource, EXTENSION_NAME_PROPERTY_ID, response.getExtensionName(), requestedIds); resource.setProperty(EXTENSION_NAME_PROPERTY_ID, response.getExtensionName()); resources.add(resource); } return resources; } protected  ExtensionResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); }
ExtensionResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<ExtensionRequest> requests = new HashSet<ExtensionRequest>(); 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<ExtensionResponse> responses = getResources(new Command<Set<ExtensionResponse>>() { @Override public Set<ExtensionResponse> invoke() throws AmbariException { return getManagementController().getExtensions(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (ExtensionResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Extension); setResourceProperty(resource, EXTENSION_NAME_PROPERTY_ID, response.getExtensionName(), requestedIds); resource.setProperty(EXTENSION_NAME_PROPERTY_ID, response.getExtensionName()); resources.add(resource); } return resources; } protected  ExtensionResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); static final String EXTENSION_NAME_PROPERTY_ID; }