KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > config > test > NamespaceTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow.config.test;
8
9
10 import java.util.Iterator JavaDoc;
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 /**
22  * <p>
23  * This class has the tests for the namespace object
24  * </p>
25  *
26  * @author Brian Pontarelli
27  * @since 2.0
28  * @version 2.0
29  */

30 public class NamespaceTest extends TestCase {
31
32     /**
33      * Construct a new <code>NamespaceTest</code> running the given test
34      *
35      * @param name
36      */

37     public NamespaceTest(String JavaDoc name) {
38         super(name);
39     }
40
41
42     /**
43      * This method tests the namespace methods inside BaseNamespace
44      */

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         // Add a wilcard type node to test the acceptEntry method on Node
69
namespace.addNode(new BaseNode("blah", "actionHandler", namespace, null, null,
70             false, false, null) {
71                 public boolean acceptEntry(String JavaDoc 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     /**
83      * Counts the number of Nodes in the given namespace
84      */

85     protected int countNodes(Namespace namespace) {
86         Iterator JavaDoc 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