1 7 package com.inversoft.verge.mvc.controller.test; 8 9 10 import com.inversoft.beans.BeanException; 11 import com.inversoft.junit.WebTestCase; 12 import com.inversoft.verge.mvc.controller.Action; 13 import com.inversoft.verge.mvc.controller.ActionHandlerException; 14 import com.inversoft.verge.mvc.controller.BeanHandle; 15 import com.inversoft.verge.mvc.controller.WebBeanHandle; 16 import com.inversoft.verge.util.ScopeConstants; 17 18 19 26 public class WebBeanHandleTest extends WebTestCase { 27 28 31 public WebBeanHandleTest(String name) { 32 super(name); 33 setLocal(true); 34 } 35 36 37 40 public void testCreate() { 41 42 try { 43 WebBeanHandle handle = new WebBeanHandle("testId.testSimple", 44 ScopeConstants.REQUEST_INT, 45 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 46 assertTrue("Should have id of testId", handle.getWebBean().getID().equals("testId")); 47 assertTrue("Should have handle of testSimple", handle.getHandleName().equals("testSimple")); 48 assertTrue("Should request scoped", handle.getWebBean().getScope() == ScopeConstants.REQUEST_INT); 49 assertTrue("Should have correct className", 50 handle.getWebBean().getClassName().equals( 51 "com.inversoft.verge.mvc.controller.test.TestActionHandler")); 52 assertTrue("Should have bean class", 53 handle.getWebBean().getBeanClass() == TestActionHandler.class); 54 } catch (BeanException be) { 55 fail(be.toString()); 56 } 57 58 try { 59 WebBeanHandle handle = new WebBeanHandle("testId.testSimple", 60 ScopeConstants.REQUEST_INT, TestActionHandler.class); 61 assertTrue("Should have id of testId", handle.getWebBean().getID().equals("testId")); 62 assertTrue("Should have handle of testSimple", handle.getHandleName().equals("testSimple")); 63 assertTrue("Should request scoped", handle.getWebBean().getScope() == ScopeConstants.REQUEST_INT); 64 assertTrue("Should have correct className", 65 handle.getWebBean().getClassName().equals( 66 "com.inversoft.verge.mvc.controller.test.TestActionHandler")); 67 assertTrue("Should have bean class", 68 handle.getWebBean().getBeanClass() == TestActionHandler.class); 69 } catch (BeanException be) { 70 fail(be.toString()); 71 } 72 73 try { 74 WebBeanHandle handle = new WebBeanHandle("testId.property.testSimple2", 75 ScopeConstants.REQUEST_INT, 76 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 77 assertTrue("Should have id of testId", handle.getWebBean().getID().equals("testId")); 78 assertTrue("Should have handle of testSimple2", handle.getHandleName().equals("testSimple2")); 79 assertTrue("Should request scoped", handle.getWebBean().getScope() == ScopeConstants.REQUEST_INT); 80 assertTrue("Should have correct className", 81 handle.getWebBean().getClassName().equals( 82 "com.inversoft.verge.mvc.controller.test.TestActionHandler")); 83 assertTrue("Should have bean class", 84 handle.getWebBean().getBeanClass() == TestActionHandler.class); 85 } catch (BeanException be) { 86 fail(be.toString()); 87 } 88 } 89 90 93 public void testCall() { 94 95 try { 96 WebBeanHandle handle = new WebBeanHandle("testId.testSimple", 97 ScopeConstants.REQUEST_INT, 98 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 99 handle.invokeHandle(new Action("", request, response), request); 100 TestActionHandler handler = (TestActionHandler) request.getAttribute("testId"); 101 102 assertTrue("Should be in request", handler != null); 103 assertTrue("Should have called handle method", handler.simple); 104 } catch (BeanException be) { 105 fail(be.toString()); 106 } 107 108 try { 109 WebBeanHandle handle = new WebBeanHandle("testId.property.testSimple2", 110 ScopeConstants.REQUEST_INT, 111 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 112 handle.invokeHandle(new Action("", request, response), request); 113 TestActionHandler handler = (TestActionHandler) request.getAttribute("testId"); 114 TestActionHandler2 handler2 = handler.getProperty(); 115 116 assertTrue("Should not be null", handler2 != null); 117 assertTrue("Should have called second handle method", handler2.simple2); 118 } catch (Exception e) { 119 fail(e.toString()); 120 } 121 } 122 123 126 public void testException() { 127 128 try { 129 WebBeanHandle handle = new WebBeanHandle("testId.testException", 130 ScopeConstants.REQUEST_INT, 131 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 132 handle.invokeHandle(new Action("", request, response), request); 133 fail("Should have thrown a ActionHandlerException"); 134 } catch (Exception e) { 135 TestActionHandler handler = (TestActionHandler) request.getAttribute("testId"); 136 assertTrue("Should have called exception handle", handler.exception); 137 assertTrue("Should be an ActionHandlerException", 138 e.getCause() instanceof ActionHandlerException); 139 } 140 141 try { 142 WebBeanHandle handle = new WebBeanHandle("testId.property.testException2", 143 ScopeConstants.REQUEST_INT, 144 "com.inversoft.verge.mvc.controller.test.TestActionHandler"); 145 handle.invokeHandle(new Action("", request, response), request); 146 fail("Should have thrown a ActionHandlerException"); 147 } catch (Exception e) { 148 TestActionHandler handler = (TestActionHandler) request.getAttribute("testId"); 149 TestActionHandler2 handler2 = handler.getProperty(); 150 assertTrue("Should have called exception handle2", handler2.exception2); 151 assertTrue("Should be an ActionHandlerException", 152 e.getCause() instanceof ActionHandlerException); 153 } 154 } 155 156 159 public void testFailure() { 160 161 try { 162 new BeanHandle("notValid", TestActionHandler.class, 163 new Class []{Action.class}); 164 fail("Should have failed to find handle method"); 165 } catch (Exception e) { 166 assertTrue("Should be an BeanException", e instanceof BeanException); 167 } 168 169 try { 170 WebBeanHandle handle = new WebBeanHandle("testId.property.notValid", 171 ScopeConstants.REQUEST_INT, 172 "com.inversoft.verge.mvc.controller.form.test.TestActionHandler"); 173 handle.invokeHandle((Action) null, request); 174 fail("Should have failed to invoke the handler"); 175 } catch (Exception e) { 176 assertTrue("Should be an BeanException", e instanceof BeanException); 177 } 178 179 try { 180 WebBeanHandle handle = new WebBeanHandle("testId.notValid", 181 ScopeConstants.REQUEST_INT, 182 "com.inversoft.verge.mvc.controller.form.test.TestActionHandler"); 183 handle.invokeHandle((Action) null, request); 184 fail("Should have failed to invoke the handler"); 185 } catch (Exception e) { 186 assertTrue("Should be an BeanException", e instanceof BeanException); 187 } 188 } 189 } 190 | Popular Tags |