FeedResourceProvider extends AbstractDRResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> feedNames = service.getFeedNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String feedName : feedNames ) { Feed feed = service.getFeed(feedName); Resource resource = new ResourceImpl(Resource.Type.DRFeed); setResourceProperty(resource, FEED_NAME_PROPERTY_ID, feed.getName(), requestedIds); setResourceProperty(resource, FEED_DESCRIPTION_PROPERTY_ID, feed.getDescription(), requestedIds); setResourceProperty(resource, FEED_STATUS_PROPERTY_ID, feed.getStatus(), requestedIds); setResourceProperty(resource, FEED_SCHEDULE_PROPERTY_ID, feed.getSchedule(), requestedIds); setResourceProperty(resource, FEED_SOURCE_CLUSTER_NAME_PROPERTY_ID, feed.getSourceClusterName(), requestedIds); setResourceProperty(resource, FEED_SOURCE_CLUSTER_START_PROPERTY_ID, feed.getSourceClusterStart(), requestedIds); setResourceProperty(resource, FEED_SOURCE_CLUSTER_END_PROPERTY_ID, feed.getSourceClusterEnd(), requestedIds); setResourceProperty(resource, FEED_SOURCE_CLUSTER_LIMIT_PROPERTY_ID, feed.getSourceClusterLimit(), requestedIds); setResourceProperty(resource, FEED_SOURCE_CLUSTER_ACTION_PROPERTY_ID, feed.getSourceClusterAction(), requestedIds); setResourceProperty(resource, FEED_TARGET_CLUSTER_NAME_PROPERTY_ID, feed.getTargetClusterName(), requestedIds); setResourceProperty(resource, FEED_TARGET_CLUSTER_START_PROPERTY_ID, feed.getTargetClusterStart(), requestedIds); setResourceProperty(resource, FEED_TARGET_CLUSTER_END_PROPERTY_ID, feed.getTargetClusterEnd(), requestedIds); setResourceProperty(resource, FEED_TARGET_CLUSTER_LIMIT_PROPERTY_ID, feed.getTargetClusterLimit(), requestedIds); setResourceProperty(resource, FEED_TARGET_CLUSTER_ACTION_PROPERTY_ID, feed.getTargetClusterAction(), requestedIds); setResourceProperty(resource, FEED_PROPERTIES_PROPERTY_ID, feed.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; } FeedResourceProvider(IvoryService ivoryService,
                              Set<String> propertyIds,
                              Map<Resource.Type, String> keyPropertyIds); @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);  }
@Test public void testGetResources() throws Exception { IvoryService service = createMock(IvoryService.class); Set<Map<String, Object>> propertySet = new HashSet<Map<String, Object>>(); Map<String, Object> properties = new HashMap<String, Object>(); List<String> feedNames = new LinkedList<String>(); feedNames.add("Feed1"); feedNames.add("Feed2"); feedNames.add("Feed3"); Map<String,String> props = new HashMap<String, String>(); Feed feed1 = new Feed("Feed1", "d", "s", "sch", "source", "st", "end", "l", "a", "target", "st", "end", "l", "a", props); Feed feed2 = new Feed("Feed2", "d", "s", "sch", "source", "st", "end", "l", "a", "target", "st", "end", "l", "a", props); Feed feed3 = new Feed("Feed3", "d", "s", "sch", "source", "st", "end", "l", "a", "target", "st", "end", "l", "a", props); expect(service.getFeedNames()).andReturn(feedNames); expect(service.getFeed("Feed1")).andReturn(feed1); expect(service.getFeed("Feed2")).andReturn(feed2); expect(service.getFeed("Feed3")).andReturn(feed3); replay(service); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, Collections.<String,String>emptyMap()); FeedResourceProvider provider = new FeedResourceProvider(service, PropertyHelper.getPropertyIds(Resource.Type.DRFeed), PropertyHelper.getKeyPropertyIds(Resource.Type.DRFeed)); Set<Resource> resources = provider.getResources(request, null); Assert.assertEquals(3, resources.size()); verify(service); }