@Test public void testGetResources() throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> expected = new HashSet<Resource>(); expected.add(createWorkflowResponse("Cluster100", "workflow1")); expected.add(createWorkflowResponse("Cluster100", "workflow2")); expected.add(createWorkflowResponse("Cluster100", "workflow3")); Resource.Type type = Resource.Type.Workflow; Set<String> propertyIds = PropertyHelper.getPropertyIds(type); WorkflowFetcher workflowFetcher = createMock(WorkflowFetcher.class); expect(workflowFetcher.fetchWorkflows(propertyIds, "Cluster100", null)) .andReturn(expected).once(); replay(workflowFetcher); Map<Resource.Type,String> keyPropertyIds = PropertyHelper .getKeyPropertyIds(type); ResourceProvider provider = new WorkflowResourceProvider(propertyIds, keyPropertyIds, workflowFetcher); Request request = PropertyHelper.getReadRequest(propertyIds); Predicate predicate = new PredicateBuilder() .property(WorkflowResourceProvider.WORKFLOW_CLUSTER_NAME_PROPERTY_ID) .equals("Cluster100").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(WorkflowResourceProvider.WORKFLOW_CLUSTER_NAME_PROPERTY_ID); Assert.assertEquals("Cluster100", clusterName); names.add((String) resource .getPropertyValue(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID)); } for (Resource resource : expected) { Assert.assertTrue(names.contains(resource .getPropertyValue(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID))); } verify(workflowFetcher); }
@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(WORKFLOW_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(WORKFLOW_ID_PROPERTY_ID); resourceSet.addAll(workflowFetcher.fetchWorkflows(requestedIds, clusterName, workflowId)); } return resourceSet; }
WorkflowResourceProvider extends
    AbstractJDBCResourceProvider<WorkflowResourceProvider.WorkflowFields> { @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(WORKFLOW_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(WORKFLOW_ID_PROPERTY_ID); resourceSet.addAll(workflowFetcher.fetchWorkflows(requestedIds, clusterName, workflowId)); } return resourceSet; } }
WorkflowResourceProvider extends
    AbstractJDBCResourceProvider<WorkflowResourceProvider.WorkflowFields> { @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(WORKFLOW_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(WORKFLOW_ID_PROPERTY_ID); resourceSet.addAll(workflowFetcher.fetchWorkflows(requestedIds, clusterName, workflowId)); } return resourceSet; } protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, WorkflowFetcher workflowFetcher); }
WorkflowResourceProvider extends
    AbstractJDBCResourceProvider<WorkflowResourceProvider.WorkflowFields> { @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(WORKFLOW_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(WORKFLOW_ID_PROPERTY_ID); resourceSet.addAll(workflowFetcher.fetchWorkflows(requestedIds, clusterName, workflowId)); } return resourceSet; } protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, WorkflowFetcher workflowFetcher); @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(); }
WorkflowResourceProvider extends
    AbstractJDBCResourceProvider<WorkflowResourceProvider.WorkflowFields> { @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(WORKFLOW_CLUSTER_NAME_PROPERTY_ID); String workflowId = (String) predicateProperties .get(WORKFLOW_ID_PROPERTY_ID); resourceSet.addAll(workflowFetcher.fetchWorkflows(requestedIds, clusterName, workflowId)); } return resourceSet; } protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds); protected  WorkflowResourceProvider(Set<String> propertyIds,
      Map<Type,String> keyPropertyIds, WorkflowFetcher workflowFetcher); @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();  }