@Test public void testGetResources_instance() throws Exception { Set<String> propertyIds = new HashSet<String>(); TreeMap<String, String> foreignKeys = new TreeMap<String, String>(); foreignKeys.put("cluster", "500"); Map<String, Object> childMap = new TreeMap<String, Object>(); childMap.put("childKey", "childValue"); Map<String, Object> child2Map = new TreeMap<String, Object>(); childMap.put("child2", child2Map); child2Map.put("child2Key", "child2Value"); Map<String, Object> child3Map = new TreeMap<String, Object>(); child2Map.put("child3", child3Map); Map<String, Object> child4Map = new TreeMap<String, Object>(); child3Map.put("child4", child4Map); child4Map.put("child4Key", "child4Value"); Map<String, Object> artifact_data = new TreeMap<String, Object>(); artifact_data.put("foo", "bar"); artifact_data.put("child", childMap); Map<String, String> responseForeignKeys = new HashMap<String, String>(); responseForeignKeys.put("cluster", "500"); expect(controller.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("test-cluster")).andReturn(cluster).anyTimes(); expect(clusters.getClusterById(500L)).andReturn(cluster).anyTimes(); expect(cluster.getClusterId()).andReturn(500L).anyTimes(); expect(cluster.getClusterName()).andReturn("test-cluster").anyTimes(); expect(request.getPropertyIds()).andReturn(propertyIds).anyTimes(); expect(dao.findByNameAndForeignKeys(eq("test-artifact"), eq(foreignKeys))).andReturn(entity).once(); expect(entity.getArtifactName()).andReturn("test-artifact").anyTimes(); expect(entity.getForeignKeys()).andReturn(responseForeignKeys).anyTimes(); expect(entity.getArtifactData()).andReturn(artifact_data).anyTimes(); replay(dao, em, controller, request, clusters, cluster, entity, entity2); PredicateBuilder pb = new PredicateBuilder(); Predicate predicate = pb.begin().property("Artifacts/cluster_name").equals("test-cluster").and(). property("Artifacts/artifact_name").equals("test-artifact").end().toPredicate(); Set<Resource> response = resourceProvider.getResources(request, predicate); assertEquals(1, response.size()); Resource resource = response.iterator().next(); Map<String, Map<String, Object>> responseProperties = resource.getPropertiesMap(); assertEquals(5, responseProperties.size()); Map<String, Object> artifactDataMap = responseProperties.get("artifact_data"); assertEquals("bar", artifactDataMap.get("foo")); assertEquals("test-artifact", resource.getPropertyValue("Artifacts/artifact_name")); assertEquals("test-cluster", resource.getPropertyValue("Artifacts/cluster_name")); assertEquals("bar", resource.getPropertyValue("artifact_data/foo")); assertEquals("childValue", resource.getPropertyValue("artifact_data/child/childKey")); assertEquals("child2Value", resource.getPropertyValue("artifact_data/child/child2/child2Key")); assertEquals("child4Value", resource.getPropertyValue("artifact_data/child/child2/child3/child4/child4Key")); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); Set<Resource> resources = new LinkedHashSet<Resource>(); for (Map<String, Object> props : requestProps) { resources.addAll(getResources(getGetCommand(request, predicate, props))); } if (resources.isEmpty() && isInstanceRequest(requestProps)) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); Set<Resource> resources = new LinkedHashSet<Resource>(); for (Map<String, Object> props : requestProps) { resources.addAll(getResources(getGetCommand(request, predicate, props))); } if (resources.isEmpty() && isInstanceRequest(requestProps)) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); Set<Resource> resources = new LinkedHashSet<Resource>(); for (Map<String, Object> props : requestProps) { resources.addAll(getResources(getGetCommand(request, predicate, props))); } if (resources.isEmpty() && isInstanceRequest(requestProps)) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); Set<Resource> resources = new LinkedHashSet<Resource>(); for (Map<String, Object> props : requestProps) { resources.addAll(getResources(getGetCommand(request, predicate, props))); } if (resources.isEmpty() && isInstanceRequest(requestProps)) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); Set<Resource> resources = new LinkedHashSet<Resource>(); for (Map<String, Object> props : requestProps) { resources.addAll(getResources(getGetCommand(request, predicate, props))); } if (resources.isEmpty() && isInstanceRequest(requestProps)) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static final String ARTIFACT_NAME_PROPERTY; static final String ARTIFACT_DATA_PROPERTY; }