KickJava   Java API By Example, From Geeks To Geeks.

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


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.test;
8
9
10 import com.inversoft.beans.BeanException;
11 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowAction;
12 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowActionTestHelper;
13 import com.inversoft.verge.mvc.controller.actionflow.NodeExecutor;
14 import com.inversoft.verge.mvc.controller.actionflow.NodeExecutorException;
15 import com.inversoft.verge.mvc.controller.actionflow.config.ActionFlowConfigRegistry;
16 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace;
17 import com.inversoft.verge.mvc.controller.actionflow.config.Node;
18
19
20 /**
21  * This class tests the NodeExecutors.
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

27 public class NodeExecutorTest extends ActionFlowExecutorTest {
28
29     /**
30      * Constructs a new <code>NodeExecutorTest</code>.
31      */

32     public NodeExecutorTest(String JavaDoc name) {
33         super(name);
34         setLocal(true);
35     }
36
37
38     /**
39      * Sets up the defaults and the config store
40     public void setUp() {
41         // All setup done by parent
42     }
43      */

44
45     /**
46      * Tests the action handler node executor with a String action
47      */

48     public void testActionHandlerAction() {
49         Namespace namespace =
50             ActionFlowConfigRegistry.getInstance(request).lookup("namespace");
51         Node handler = namespace.getNode("login");
52         NodeExecutor executor = handler.getExecutor();
53         ActionFlowAction state = new ActionFlowAction(request, response);
54         ActionFlowActionTestHelper stateHelper = new ActionFlowActionTestHelper(state);
55
56         stateHelper.setNode(handler);
57         stateHelper.setAction("login");
58
59         try {
60             Object JavaDoc result = executor.execute(namespace, handler, state, null);
61             assertTrue("Should be success", result != null && result.toString().equals("success"));
62             assertTrue("Should have been called", ActionHandler.isCalled());
63         } catch (Throwable JavaDoc t) {
64             fail(t.toString());
65         }
66     }
67
68     /**
69      * Tests the action handler node executor with an Exception action
70      */

71     public void testActionHandlerException() {
72         Namespace namespace =
73             ActionFlowConfigRegistry.getInstance(request).lookup("namespace");
74         Node handler = namespace.getNode("failure");
75         NodeExecutor executor = handler.getExecutor();
76         ActionFlowAction state = new ActionFlowAction(request, response);
77         ActionFlowActionTestHelper stateHelper = new ActionFlowActionTestHelper(state);
78
79         stateHelper.setNode(handler);
80         stateHelper.setAction(new Exception JavaDoc());
81
82         try {
83             Object JavaDoc result = executor.execute(namespace, handler, state, null);
84             assertTrue("Should be success",
85                 result != null && result.toString().equals("successException"));
86             assertTrue("Should have been exceptionCalled",
87                 ActionHandler2.isExceptionCalled());
88         } catch (Throwable JavaDoc t) {
89             fail(t.toString());
90         }
91     }
92
93     /**
94      * Tests the action handler node executor fails correctly
95      */

96     public void testActionHandlerFailure() {
97         Namespace namespace =
98             ActionFlowConfigRegistry.getInstance(request).lookup("namespace");
99         Node handler = namespace.getNode("login");
100         NodeExecutor executor = handler.getExecutor();
101         ActionFlowAction state = new ActionFlowAction(request, response);
102         ActionFlowActionTestHelper stateHelper = new ActionFlowActionTestHelper(state);
103
104         stateHelper.setNode(handler);
105         stateHelper.setAction("notAnAction");
106
107         try {
108             /*Object result =*/ executor.execute(namespace, handler, state, null);
109             fail("Should have thrown a NodeExecutorException");
110         } catch (NodeExecutorException nee) {
111             assertSame("Should be a NodeExecutorException with a cause of BeanException",
112                 BeanException.class, nee.getCause().getClass());
113         } catch (Exception JavaDoc e) {
114             fail("Should have thrown a NodeExecutorException");
115         }
116     }
117
118     /**
119      * Tests the presentation node executor
120      */

121     public void testPresentationNodeExecutor() {
122         Namespace namespace =
123             ActionFlowConfigRegistry.getInstance(request).lookup("namespace");
124         Node index = namespace.getNode("/index.jsp");
125         NodeExecutor executor = index.getExecutor();
126         ActionFlowAction state = new ActionFlowAction(request, response);
127         ActionFlowActionTestHelper stateHelper = new ActionFlowActionTestHelper(state);
128
129         stateHelper.setNode(index);
130         stateHelper.setAction("login");
131
132         try {
133             Object JavaDoc result = executor.execute(namespace, index, state, null);
134             assertTrue("Result should be null this is an exit node", result == null);
135         } catch (NullPointerException JavaDoc npe) {
136             throw npe;
137         } catch (Throwable JavaDoc t) {
138             fail(t.toString());
139         }
140     }
141 }
142
143
Popular Tags