@Test public void testGetResources() throws Exception{ Map<String, String> attributes = new HashMap<String, String>(); attributes.put("final", "true"); Resource.Type type = Resource.Type.StackLevelConfiguration; AmbariManagementController managementController = createMock(AmbariManagementController.class); Set<StackConfigurationResponse> allResponse = new HashSet<StackConfigurationResponse>(); allResponse.add(new StackConfigurationResponse(PROPERTY_NAME, PROPERTY_VALUE, PROPERTY_DESC, TYPE, attributes)); expect(managementController.getStackLevelConfigurations( AbstractResourceProviderTest.Matcher.getStackLevelConfigurationRequestSet(null, null, null))). andReturn(allResponse).times(1); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(StackLevelConfigurationResourceProvider.STACK_NAME_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.STACK_VERSION_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.PROPERTY_NAME_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.PROPERTY_VALUE_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.PROPERTY_DESCRIPTION_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.PROPERTY_TYPE_PROPERTY_ID); propertyIds.add(StackLevelConfigurationResourceProvider.PROPERTY_FINAL_PROPERTY_ID); Request request = PropertyHelper.getReadRequest(propertyIds); Set<Resource> resources = provider.getResources(request, null); Assert.assertEquals(allResponse.size(), resources.size()); for (Resource resource : resources) { String propertyName = (String) resource.getPropertyValue(StackLevelConfigurationResourceProvider.PROPERTY_NAME_PROPERTY_ID); String propertyValue = (String) resource.getPropertyValue(StackLevelConfigurationResourceProvider.PROPERTY_VALUE_PROPERTY_ID); String propertyDesc = (String) resource.getPropertyValue(StackLevelConfigurationResourceProvider.PROPERTY_DESCRIPTION_PROPERTY_ID); String propertyType = (String) resource.getPropertyValue(StackLevelConfigurationResourceProvider.PROPERTY_TYPE_PROPERTY_ID); String propertyIsFinal = (String) resource.getPropertyValue(StackLevelConfigurationResourceProvider.PROPERTY_FINAL_PROPERTY_ID); Assert.assertEquals(PROPERTY_NAME, propertyName); Assert.assertEquals(PROPERTY_VALUE, propertyValue); Assert.assertEquals(PROPERTY_DESC, propertyDesc); Assert.assertEquals(TYPE, propertyType); Assert.assertEquals("true", propertyIsFinal); } verify(managementController); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackLevelConfigurationRequest> requests = new HashSet<StackLevelConfigurationRequest>(); 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<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() { @Override public Set<StackConfigurationResponse> invoke() throws AmbariException { return getManagementController().getStackLevelConfigurations(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackConfigurationResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID, response.getPropertyName(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID, response.getPropertyValue(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID, response.getPropertyValueAttributes(), requestedIds); setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID, response.getDependsOnProperties(), requestedIds); setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID, response.getPropertyDescription(), requestedIds); if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) { setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID, response.getPropertyDisplayName(), requestedIds); } setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID, response.getPropertyType(), requestedIds); setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID, response.getType(), requestedIds); setDefaultPropertiesAttributes(resource, requestedIds); for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) { setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()), attribute.getValue(), requestedIds); } resources.add(resource); } return resources; }
StackLevelConfigurationResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackLevelConfigurationRequest> requests = new HashSet<StackLevelConfigurationRequest>(); 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<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() { @Override public Set<StackConfigurationResponse> invoke() throws AmbariException { return getManagementController().getStackLevelConfigurations(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackConfigurationResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID, response.getPropertyName(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID, response.getPropertyValue(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID, response.getPropertyValueAttributes(), requestedIds); setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID, response.getDependsOnProperties(), requestedIds); setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID, response.getPropertyDescription(), requestedIds); if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) { setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID, response.getPropertyDisplayName(), requestedIds); } setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID, response.getPropertyType(), requestedIds); setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID, response.getType(), requestedIds); setDefaultPropertiesAttributes(resource, requestedIds); for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) { setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()), attribute.getValue(), requestedIds); } resources.add(resource); } return resources; } }
StackLevelConfigurationResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackLevelConfigurationRequest> requests = new HashSet<StackLevelConfigurationRequest>(); 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<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() { @Override public Set<StackConfigurationResponse> invoke() throws AmbariException { return getManagementController().getStackLevelConfigurations(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackConfigurationResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID, response.getPropertyName(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID, response.getPropertyValue(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID, response.getPropertyValueAttributes(), requestedIds); setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID, response.getDependsOnProperties(), requestedIds); setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID, response.getPropertyDescription(), requestedIds); if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) { setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID, response.getPropertyDisplayName(), requestedIds); } setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID, response.getPropertyType(), requestedIds); setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID, response.getType(), requestedIds); setDefaultPropertiesAttributes(resource, requestedIds); for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) { setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()), attribute.getValue(), requestedIds); } resources.add(resource); } return resources; } protected  StackLevelConfigurationResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
StackLevelConfigurationResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackLevelConfigurationRequest> requests = new HashSet<StackLevelConfigurationRequest>(); 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<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() { @Override public Set<StackConfigurationResponse> invoke() throws AmbariException { return getManagementController().getStackLevelConfigurations(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackConfigurationResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID, response.getPropertyName(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID, response.getPropertyValue(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID, response.getPropertyValueAttributes(), requestedIds); setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID, response.getDependsOnProperties(), requestedIds); setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID, response.getPropertyDescription(), requestedIds); if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) { setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID, response.getPropertyDisplayName(), requestedIds); } setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID, response.getPropertyType(), requestedIds); setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID, response.getType(), requestedIds); setDefaultPropertiesAttributes(resource, requestedIds); for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) { setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()), attribute.getValue(), requestedIds); } resources.add(resource); } return resources; } protected  StackLevelConfigurationResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); }
StackLevelConfigurationResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<StackLevelConfigurationRequest> requests = new HashSet<StackLevelConfigurationRequest>(); 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<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() { @Override public Set<StackConfigurationResponse> invoke() throws AmbariException { return getManagementController().getStackLevelConfigurations(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (StackConfigurationResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID, response.getPropertyName(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID, response.getPropertyValue(), requestedIds); setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID, response.getPropertyValueAttributes(), requestedIds); setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID, response.getDependsOnProperties(), requestedIds); setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID, response.getPropertyDescription(), requestedIds); if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) { setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID, response.getPropertyDisplayName(), requestedIds); } setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID, response.getPropertyType(), requestedIds); setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID, response.getType(), requestedIds); setDefaultPropertiesAttributes(resource, requestedIds); for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) { setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()), attribute.getValue(), requestedIds); } resources.add(resource); } return resources; } protected  StackLevelConfigurationResourceProvider(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; static final String PROPERTY_NAME_PROPERTY_ID; static final String PROPERTY_DISPLAY_NAME_PROPERTY_ID; static final String PROPERTY_VALUE_PROPERTY_ID; static final String PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID; static final String DEPENDS_ON_PROPERTY_ID; static final String PROPERTY_DESCRIPTION_PROPERTY_ID; static final String PROPERTY_PROPERTY_TYPE_PROPERTY_ID; static final String PROPERTY_TYPE_PROPERTY_ID; static final String PROPERTY_FINAL_PROPERTY_ID; }