@Test public void testGetResources_collection() throws Exception { Set<String> propertyIds = new HashSet<String>(); TreeMap<String, String> foreignKeys = new TreeMap<String, String>(); foreignKeys.put("cluster", "500"); List<ArtifactEntity> entities = new ArrayList<ArtifactEntity>(); entities.add(entity); entities.add(entity2); Map<String, Object> artifact_data = Collections.<String, Object>singletonMap("foo", "bar"); Map<String, Object> artifact_data2 = Collections.<String, Object>singletonMap("foo2", "bar2"); 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.findByForeignKeys(eq(foreignKeys))).andReturn(entities).anyTimes(); expect(entity.getArtifactName()).andReturn("test-artifact").anyTimes(); expect(entity.getForeignKeys()).andReturn(responseForeignKeys).anyTimes(); expect(entity.getArtifactData()).andReturn(artifact_data).anyTimes(); expect(entity2.getArtifactName()).andReturn("test-artifact2").anyTimes(); expect(entity2.getForeignKeys()).andReturn(responseForeignKeys).anyTimes(); expect(entity2.getArtifactData()).andReturn(artifact_data2).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").end().toPredicate(); Set<Resource> response = resourceProvider.getResources(request, predicate); assertEquals(2, response.size()); boolean artifact1Returned = false; boolean artifact2Returned = false; for (Resource resource : response) { if (resource.getPropertyValue("Artifacts/artifact_name").equals("test-artifact")) { artifact1Returned = true; assertEquals("bar", resource.getPropertyValue("artifact_data/foo")); assertEquals("test-cluster", resource.getPropertyValue("Artifacts/cluster_name")); } else if (resource.getPropertyValue("Artifacts/artifact_name").equals("test-artifact2")) { artifact2Returned = true; assertEquals("bar2", resource.getPropertyValue("artifact_data/foo2")); assertEquals("test-cluster", resource.getPropertyValue("Artifacts/cluster_name")); } else { fail("unexpected artifact name"); } } assertTrue(artifact1Returned); assertTrue(artifact2Returned); }
@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; }