FeedEntityParser extends EntityParser<Feed> { @Override public void validate(Feed feed) throws IvoryException { if(feed.getTimezone() == null) feed.setTimezone(TimeZone.getTimeZone("UTC")); if (feed.getClusters() == null) throw new ValidationException("Feed should have atleast one cluster"); for (Cluster cluster : feed.getClusters().getClusters()) { validateEntityExists(EntityType.CLUSTER, cluster.getName()); validateClusterValidity(cluster.getValidity().getStart(), cluster.getValidity().getEnd(), cluster.getName()); validateFeedCutOffPeriod(feed, cluster); } validateFeedPartitionExpression(feed); validateFeedGroups(feed); Feed oldFeed = ConfigurationStore.get().get(EntityType.FEED, feed.getName()); if (oldFeed == null) return; EntityGraph graph = EntityGraph.get(); Set<Entity> referenced = graph.getDependents(oldFeed); Set<Process> processes = findProcesses(referenced); if (processes.isEmpty()) return; ensureValidityFor(feed, processes); } FeedEntityParser(); @Override void validate(Feed feed);  }
@Test(expectedExceptions = ValidationException.class) public void applyValidationInvalidFeed() throws Exception { Feed feed = (Feed) parser .parseAndValidate(ProcessEntityParserTest.class .getResourceAsStream(FEED_XML)); feed.getClusters().getClusters().get(0).setName("invalid cluster"); parser.validate(feed); }
@Test public void testPartitionExpression() throws IvoryException { Feed feed = (Feed) parser.parseAndValidate(ProcessEntityParserTest.class .getResourceAsStream(FEED_XML)); org.apache.ivory.entity.v0.feed.Cluster newCluster = new org.apache.ivory.entity.v0.feed.Cluster(); newCluster.setName("newCluster"); newCluster.setType(ClusterType.SOURCE); newCluster.setPartition("${cluster.colo}"); feed.getClusters().getClusters().add(newCluster); try { parser.validate(feed); Assert.fail("Expected ValidationException"); } catch(ValidationException e) { } feed.getClusters().getClusters().get(0).setPartition("*"); try { parser.validate(feed); Assert.fail("Expected ValidationException"); } catch(ValidationException e) { } newCluster.setType(ClusterType.TARGET); try { parser.validate(feed); Assert.fail("Expected ValidationException"); } catch(ValidationException e) { } feed.getClusters().getClusters().get(1).setPartition("*"); try { parser.validate(feed); Assert.fail("Expected ValidationException"); } catch(ValidationException e) { } feed.getClusters().getClusters().get(1).setPartition("*/*"); try { parser.validate(feed); Assert.fail("Expected ValidationException"); } catch(ValidationException e) { } feed.getClusters().getClusters().get(0).setPartition(null); feed.getClusters().getClusters().get(1).setPartition(null); feed.getClusters().getClusters().remove(2); feed.setPartitions(null); parser.validate(feed); }
@Test(expectedExceptions = ValidationException.class) public void testInvalidProcessValidity() throws Exception { Feed feed = parser.parseAndValidate((FeedEntityParserTest.class .getResourceAsStream(FEED_XML))); feed.getClusters().getClusters().get(0).getValidity() .setStart(SchemaHelper.parseDateUTC("2012-11-01T00:00Z")); parser.validate(feed); }