1 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 27 public class NodeExecutorTest extends ActionFlowExecutorTest { 28 29 32 public NodeExecutorTest(String name) { 33 super(name); 34 setLocal(true); 35 } 36 37 38 44 45 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 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 t) { 64 fail(t.toString()); 65 } 66 } 67 68 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 ()); 81 82 try { 83 Object 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 t) { 89 fail(t.toString()); 90 } 91 } 92 93 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 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 e) { 114 fail("Should have thrown a NodeExecutorException"); 115 } 116 } 117 118 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 result = executor.execute(namespace, index, state, null); 134 assertTrue("Result should be null this is an exit node", result == null); 135 } catch (NullPointerException npe) { 136 throw npe; 137 } catch (Throwable t) { 138 fail(t.toString()); 139 } 140 } 141 } 142 143 | Popular Tags |