EPNValidator { protected static boolean validateNodes(Network epn, EPNValidationListener l) { boolean ret=true; for (Node node : epn.getNodes()) { if (node.getName() == null) { l.error(epn, node, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Node", "name")); ret = false; } else if (epn.getNode(node.getName()) != node) { l.error(epn, node, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-8"), node.getName())); ret = false; } if (node.getEventProcessor() == null) { l.error(epn, node, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Node", "eventProcessor")); ret = false; } if (node.getName() != null) { java.util.List<String> path=new java.util.Vector<String>(); path.add(node.getName()); for (String sourceNode : node.getSourceNodes()) { if (epn.getNode(sourceNode) == null) { l.error(epn, node, MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-9"), sourceNode, node.getName())); ret = false; } if (!checkCyclicDependency(epn, path, sourceNode, l)) { ret = false; } } } if (!validateNotifications(epn, node, l)) { ret = false; } } return (ret); } private  EPNValidator(); static boolean validate(Network epn, EPNValidationListener l);  }
@Test public void testValidateNode() { TestNetwork epn=new TestNetwork(); 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.validateNodes(epn, l)) { fail("Should be valid"); } String[] expected=new String[] { }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateEmptyNode() { Network epn=new Network(); Node node=new Node(); epn.getNodes().add(node); TestListener l=new TestListener(); if (EPNValidator.validateNodes(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Node", "name"), MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-6"), "Node", "eventProcessor") }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateNodeDuplicateName() { TestNetwork epn=new TestNetwork(); Node node1=new Node(); node1.setName("node"); node1.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); epn.getNodes().add(node1); Node node2=new Node(); node2.setName("node"); node2.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); epn.getNodes().add(node2); epn.init(); TestListener l=new TestListener(); if (EPNValidator.validateNodes(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-8"), node1.getName()) }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateNodeCyclicDependencyImmediate() { TestNetwork epn=new TestNetwork(); Node node1=new Node(); node1.setName("node1"); node1.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); node1.getSourceNodes().add(node1.getName()); epn.getNodes().add(node1); epn.init(); TestListener l=new TestListener(); if (EPNValidator.validateNodes(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-10"), "node1->node1") }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateNodeCyclicDependencyIndirect() { TestNetwork epn=new TestNetwork(); Node node0=new Node(); node0.setName("node0"); node0.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); Node node1=new Node(); node1.setName("node1"); node1.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); Node node2=new Node(); node2.setName("node2"); node2.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); Node node3=new Node(); node3.setName("node3"); node3.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); node0.getSourceNodes().add(node2.getName()); epn.getNodes().add(node0); node1.getSourceNodes().add(node0.getName()); epn.getNodes().add(node1); node2.getSourceNodes().add(node1.getName()); epn.getNodes().add(node2); node3.getSourceNodes().add(node2.getName()); epn.getNodes().add(node3); epn.init(); TestListener l=new TestListener(); if (EPNValidator.validateNodes(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-10"), "node1->node0->node2->node1"), MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-10"), "node0->node2->node1->node0"), MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-10"), "node2->node1->node0->node2") }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateNodeSourceExists() { TestNetwork epn=new TestNetwork(); Node node1=new Node(); node1.setName("node1"); node1.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); epn.getNodes().add(node1); Node node2=new Node(); node2.setName("node2"); node2.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); node2.getSourceNodes().add("node1"); epn.getNodes().add(node2); epn.init(); TestListener l=new TestListener(); if (!EPNValidator.validateNodes(epn, l)) { fail("Should be valid"); } String[] expected=new String[] { }; validateIssues(expected, l.getIssues()); }
@Test public void testValidateNodeSourceDoesNotExist() { TestNetwork epn=new TestNetwork(); Node node1=new Node(); node1.setName("node"); node1.setEventProcessor(new EventProcessor() { public Serializable process(String source, Serializable event, int retriesLeft) throws Exception { return null; }}); node1.getSourceNodes().add("other"); epn.getNodes().add(node1); epn.init(); TestListener l=new TestListener(); if (EPNValidator.validateNodes(epn, l)) { fail("Should be invalid"); } String[] expected=new String[] { MessageFormat.format(java.util.PropertyResourceBundle.getBundle( "epn-core.Messages").getString("EPN-CORE-9"), "other", node1.getName()) }; validateIssues(expected, l.getIssues()); }