EPNValidator { protected static boolean validateSubscriptions(Network epn, EPNValidationListener l) { boolean ret=true; java.util.List<String> dups=new java.util.Vector<String>(); for (Subscription sub : epn.getSubscriptions()) { if (sub.getSubject() == null) { l.error(epn, sub, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Subscription", "nodeName")); ret = false; } if (sub.getNodeName() == null) { l.error(epn, sub, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Subscription", "subject")); ret = false; } if (sub.getNodeName() != null && sub.getSubject() != null) { String field=sub.getSubject()+":"+sub.getNodeName(); if (dups.contains(field)) { l.error(epn, sub, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-5"), sub.getSubject(), sub.getNodeName())); ret = false; } else { dups.add(field); } if (epn.getNode(sub.getNodeName()) == null) { l.error(epn, sub, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-7"), sub.getNodeName(), sub.getSubject())); ret = false; } } } return (ret); } private  EPNValidator(); static boolean validate(Network epn, EPNValidationListener l);  }
@Test public void testValidateSubscriptions() { TestNetwork epn=new TestNetwork(); Subscription sub=new Subscription(); sub.setNodeName("node"); sub.setSubject("sub"); epn.getSubscriptions().add(sub); Node node=new Node(); node.setName("node"); node.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; } }); epn.getNodes().add(node); epn.init(); TestListener l=new TestListener(); if (!EPNValidator.validateSubscriptions(epn, l)) { fail("Should be valid"); } String[] expected=new String[] { }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateEmptySubscriptions() { Network epn=new Network(); Subscription sub=new Subscription(); epn.getSubscriptions().add(sub); TestListener l=new TestListener(); if (EPNValidator.validateSubscriptions(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Subscription", "nodeName"), MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Subscription", "subject") }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateSubscriptionsNoDuplicate() { TestNetwork epn=new TestNetwork(); Subscription sub1=new Subscription(); sub1.setNodeName("n1"); sub1.setSubject("sub1"); epn.getSubscriptions().add(sub1); Node n1=new Node(); n1.setName("n1"); epn.getNodes().add(n1); Subscription sub2=new Subscription(); sub2.setNodeName("n2"); sub2.setSubject("sub2"); epn.getSubscriptions().add(sub2); Node n2=new Node(); n2.setName("n2"); epn.getNodes().add(n2); epn.init(); TestListener l=new TestListener(); if (!EPNValidator.validateSubscriptions(epn, l)) { fail("Should be valid"); } String[] expected=new String[] { }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateSubscriptionsDuplicate() { TestNetwork epn=new TestNetwork(); Subscription sub1=new Subscription(); sub1.setNodeName("n1"); sub1.setSubject("sub1"); epn.getSubscriptions().add(sub1); Node n1=new Node(); n1.setName("n1"); epn.getNodes().add(n1); Subscription sub2=new Subscription(); sub2.setNodeName("n1"); sub2.setSubject("sub1"); epn.getSubscriptions().add(sub2); epn.init(); TestListener l=new TestListener(); if (EPNValidator.validateSubscriptions(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-5"), sub1.getSubject(), sub1.getNodeName()) }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateSubscriptionsNodeMissing() { Network epn=new Network(); Subscription sub1=new Subscription(); sub1.setNodeName("n1"); sub1.setSubject("sub1"); epn.getSubscriptions().add(sub1); TestListener l=new TestListener(); if (EPNValidator.validateSubscriptions(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-7"), sub1.getNodeName(), sub1.getSubject()) }; validateIssues(expected, l.getIssues()); }