@Test public void testGetResources() throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> expected = new HashSet<Resource>(); expected.add(createJobResponse("Cluster100", "workflow1", "job1")); expected.add(createJobResponse("Cluster100", "workflow2", "job2")); expected.add(createJobResponse("Cluster100", "workflow2", "job3")); Resource.Type type = Resource.Type.Job; Set<String> propertyIds = PropertyHelper.getPropertyIds(type); JobFetcher jobFetcher = createMock(JobFetcher.class); expect(jobFetcher.fetchJobDetails(propertyIds, null, "workflow2", null)) .andReturn(expected).once(); replay(jobFetcher); Map<Resource.Type,String> keyPropertyIds = PropertyHelper .getKeyPropertyIds(type); ResourceProvider provider = new JobResourceProvider(propertyIds, keyPropertyIds, jobFetcher); Request request = PropertyHelper.getReadRequest(propertyIds); Predicate predicate = new PredicateBuilder() .property(JobResourceProvider.JOB_WORKFLOW_ID_PROPERTY_ID) .equals("workflow2").toPredicate(); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(3, resources.size()); Set<String> names = new HashSet<String>(); for (Resource resource : resources) { String clusterName = (String) resource .getPropertyValue(JobResourceProvider.JOB_CLUSTER_NAME_PROPERTY_ID); Assert.assertEquals("Cluster100", clusterName); names.add((String) resource .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID)); } for (Resource resource : expected) { Assert.assertTrue(names.contains(resource .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID))); } verify(jobFetcher); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resourceSet = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Map<String,Object>> predicatePropertieSet = getPropertyMaps(predicate); for (Map<String,Object> predicateProperties : predicatePropertieSet) { String clusterName = (String) predicateProperties .get(JOB_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(JOB_WORKFLOW_ID_PROPERTY_ID); String jobId = (String) predicateProperties.get(JOB_ID_PROPERTY_ID); resourceSet.addAll(jobFetcher.fetchJobDetails(requestedIds, clusterName, workflowId, jobId)); } return resourceSet; }
JobResourceProvider extends
    AbstractJDBCResourceProvider<JobResourceProvider.JobFields> { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resourceSet = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Map<String,Object>> predicatePropertieSet = getPropertyMaps(predicate); for (Map<String,Object> predicateProperties : predicatePropertieSet) { String clusterName = (String) predicateProperties .get(JOB_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(JOB_WORKFLOW_ID_PROPERTY_ID); String jobId = (String) predicateProperties.get(JOB_ID_PROPERTY_ID); resourceSet.addAll(jobFetcher.fetchJobDetails(requestedIds, clusterName, workflowId, jobId)); } return resourceSet; } }
JobResourceProvider extends
    AbstractJDBCResourceProvider<JobResourceProvider.JobFields> { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resourceSet = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Map<String,Object>> predicatePropertieSet = getPropertyMaps(predicate); for (Map<String,Object> predicateProperties : predicatePropertieSet) { String clusterName = (String) predicateProperties .get(JOB_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(JOB_WORKFLOW_ID_PROPERTY_ID); String jobId = (String) predicateProperties.get(JOB_ID_PROPERTY_ID); resourceSet.addAll(jobFetcher.fetchJobDetails(requestedIds, clusterName, workflowId, jobId)); } return resourceSet; } protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, JobFetcher jobFetcher); }
JobResourceProvider extends
    AbstractJDBCResourceProvider<JobResourceProvider.JobFields> { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resourceSet = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Map<String,Object>> predicatePropertieSet = getPropertyMaps(predicate); for (Map<String,Object> predicateProperties : predicatePropertieSet) { String clusterName = (String) predicateProperties .get(JOB_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(JOB_WORKFLOW_ID_PROPERTY_ID); String jobId = (String) predicateProperties.get(JOB_ID_PROPERTY_ID); resourceSet.addAll(jobFetcher.fetchJobDetails(requestedIds, clusterName, workflowId, jobId)); } return resourceSet; } protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, JobFetcher jobFetcher); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Map<Type,String> getKeyPropertyIds(); }
JobResourceProvider extends
    AbstractJDBCResourceProvider<JobResourceProvider.JobFields> { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resourceSet = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Map<String,Object>> predicatePropertieSet = getPropertyMaps(predicate); for (Map<String,Object> predicateProperties : predicatePropertieSet) { String clusterName = (String) predicateProperties .get(JOB_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(JOB_WORKFLOW_ID_PROPERTY_ID); String jobId = (String) predicateProperties.get(JOB_ID_PROPERTY_ID); resourceSet.addAll(jobFetcher.fetchJobDetails(requestedIds, clusterName, workflowId, jobId)); } return resourceSet; } protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  JobResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, JobFetcher jobFetcher); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Map<Type,String> getKeyPropertyIds();  }