1 7 package com.inversoft.verge.mvc.controller.actionflow.config.test; 8 9 10 import java.util.Iterator ; 11 12 import junit.framework.TestCase; 13 14 import com.inversoft.verge.mvc.controller.actionflow.config.BaseNamespace; 15 import com.inversoft.verge.mvc.controller.actionflow.config.BaseNode; 16 import com.inversoft.verge.mvc.controller.actionflow.config.DefaultTypes; 17 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace; 18 import com.inversoft.verge.mvc.controller.actionflow.config.Node; 19 20 21 30 public class NamespaceTest extends TestCase { 31 32 37 public NamespaceTest(String name) { 38 super(name); 39 } 40 41 42 45 public void testNamespace() { 46 Namespace namespace = new BaseNamespace("namespace", DefaultTypes.NAMESPACE); 47 Node one = new BaseNode("one", "actionHandler", namespace, null, null, 48 false, false, null); 49 Node two = new BaseNode("two", "actionHandler", namespace, null, null, 50 false, false, null); 51 Node three = new BaseNode("three", "actionHandler", namespace, null, null, 52 false, false, null); 53 namespace.addNode(one); 54 namespace.addNode(two); 55 namespace.addNode(three); 56 57 assertTrue("Should have three nodes", countNodes(namespace) == 3); 58 assertTrue("Should get one", namespace.getNode("one") == one); 59 assertTrue("Should get two", namespace.getNode("two") == two); 60 assertTrue("Should get three", namespace.getNode("three") == three); 61 assertTrue("Should NOT get four", namespace.getNode("four") == null); 62 63 assertTrue("Should find one", namespace.findEntry("one") == one); 64 assertTrue("Should find two", namespace.findEntry("two") == two); 65 assertTrue("Should find three", namespace.findEntry("three") == three); 66 assertTrue("Should NOT find four", namespace.findEntry("four") == null); 67 68 namespace.addNode(new BaseNode("blah", "actionHandler", namespace, null, null, 70 false, false, null) { 71 public boolean acceptEntry(String name) { 72 if (name.equals("four")) { 73 return true; 74 } 75 76 return false; 77 } 78 }); 79 assertTrue("Should find four", namespace.findEntry("four") != null); 80 } 81 82 85 protected int countNodes(Namespace namespace) { 86 Iterator iter = namespace.nodeIterator(); 87 int count = 0; 88 while (iter.hasNext()) { 89 iter.next(); 90 count++; 91 } 92 93 return count; 94 } 95 } | Popular Tags |