KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
11
12 import com.inversoft.util.BaseException;
13 import com.inversoft.verge.mvc.controller.actionflow.config.ActionLink;
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.ExceptionLink;
18 import com.inversoft.verge.mvc.controller.actionflow.config.Link;
19 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace;
20 import com.inversoft.verge.mvc.controller.actionflow.config.RegexLink;
21
22
23 /**
24  * <p>
25  * This class contains the tests for BaseNode
26  * </p>
27  *
28  * @author Brian Pontarelli
29  * @since 2.0
30  * @version 2.0
31  */

32 public class BaseNodeTest extends TestCase {
33
34     /**
35      * Constructs a new <code>BaseNodeTest</code>
36      */

37     public BaseNodeTest(String JavaDoc name) {
38         super(name);
39     }
40
41
42     /**
43      * Tests the base node class
44      */

45     public void testBaseNode() {
46
47         // Tests the link methods
48
Namespace namespace = new BaseNamespace("namespace", DefaultTypes.NAMESPACE);
49         BaseNode node = new BaseNode("one", "actionHandler", namespace, null, null,
50             false, false, null);
51         BaseNode dest = new BaseNode("two", "actionHandler", namespace, null, null,
52             false, false, null);
53
54         Link submit = new ActionLink("submit", node, dest);
55         Link cancel = new ActionLink("cancel", node, dest);
56         node.addLink(submit);
57         node.addLink(cancel);
58
59         assertTrue("Should find submit link", node.findLink("submit") == submit);
60         assertTrue("Should find cancel link", node.findLink("cancel") == cancel);
61         assertTrue("Should NOT find login link", node.findLink("login") == null);
62
63         Link regex = new RegexLink("l.*", node, dest);
64         node.addLink(regex);
65         assertTrue("Should find login link", node.findLink("login") == regex);
66     }
67
68     /**
69      * Tests the methods of BaseNode WRT exception links
70      */

71     public void testExceptionLinks() {
72
73         // Tests the link methods
74
Namespace namespace = new BaseNamespace("namespace", DefaultTypes.NAMESPACE);
75         BaseNode node = new BaseNode("one", "actionHandler", namespace, null, null,
76             false, false, null);
77         BaseNode dest = new BaseNode("two", "actionHandler", namespace, null, null,
78             false, false, null);
79
80         Link generic = new ExceptionLink(new Exception JavaDoc(), node, dest);
81         Link specific = new ExceptionLink(new TestException(), node, dest);
82         node.addLink(generic);
83         node.addLink(specific);
84
85         assertTrue("Should find specific link first",
86             node.findLink(new TestException()) == specific);
87         assertTrue("Should NOT find specific link for BaseException",
88             node.findLink(new BaseException()) != specific);
89         assertTrue("Should find generic link for BaseException",
90             node.findLink(new BaseException()) == generic);
91         assertTrue("Should find generic link for ClassNotFoundException",
92             node.findLink(new ClassNotFoundException JavaDoc()) == generic);
93     }
94 }
95
Popular Tags