1 7 package com.inversoft.verge.mvc.controller.test; 8 9 10 import java.lang.reflect.Method ; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.junit.WebTestCase; 14 import com.inversoft.util.ReflectionException; 15 import com.inversoft.util.ReflectionTools; 16 import com.inversoft.verge.mvc.controller.Action; 17 import com.inversoft.verge.mvc.controller.BeanHandle; 18 19 20 27 public class BeanHandleTest extends WebTestCase { 28 29 32 public BeanHandleTest(String name) { 33 super(name); 34 setLocal(true); 35 } 36 37 38 41 public void testCallHandle() { 42 try { 43 BeanHandle bh = new BeanHandle("testSimple", TestActionHandler.class, 44 new Class []{Action.class}); 45 Method method = ReflectionTools.getMethod(TestActionHandler.class, 46 "handleTestSimple", new Class []{Action.class}); 47 assertEquals("testSimple", bh.getHandleName()); 48 assertEquals(method, bh.getHandleMethod()); 49 50 TestActionHandler tah = new TestActionHandler(); 51 52 tah.simple = false; 53 bh.invokeHandle(tah, new Object []{null}); 54 assertTrue(tah.simple); 55 56 tah.simple = false; 57 bh.invokeHandle(tah, new Object []{new Action("foo", request, response)}); 58 assertTrue(tah.simple); 59 } catch (BeanException be) { 60 fail(be.toString()); 61 } catch (ReflectionException re) { 62 fail(re.toString()); 63 } 64 } 65 66 69 public void testException() { 70 try { 71 BeanHandle bh = new BeanHandle("exception", TestActionHandler.class, 72 new Class []{Action.class}); 73 TestActionHandler tah = new TestActionHandler(); 74 75 bh.invokeHandle(tah, new Object []{null}); 76 fail("Should have thrown exception"); 77 } catch (BeanException be) { 78 assertEquals(Exception .class, be.getCause().getClass()); 79 } 80 } 81 82 85 public void testRuntimeException() { 86 try { 87 BeanHandle bh = new BeanHandle("runtimeException", TestActionHandler.class, 88 new Class []{Action.class}); 89 TestActionHandler tah = new TestActionHandler(); 90 91 bh.invokeHandle(tah, new Object []{null}); 92 fail("Should have thrown RuntimeException"); 93 } catch (BeanException be) { 94 fail("Should not have thrown this"); 95 } catch (RuntimeException re) { 96 assertEquals("test", re.getMessage()); 97 } 98 } 99 100 103 public void testError() { 104 try { 105 BeanHandle bh = new BeanHandle("error", TestActionHandler.class, 106 new Class []{Action.class}); 107 TestActionHandler tah = new TestActionHandler(); 108 109 bh.invokeHandle(tah, new Object []{null}); 110 fail("Should have thrown Error"); 111 } catch (BeanException be) { 112 fail("Should not have thrown this"); 113 } catch (Error e) { 114 assertEquals("test", e.getMessage()); 115 } 116 } 117 118 121 public void testThrowable() { 122 try { 123 BeanHandle bh = new BeanHandle("throwable", TestActionHandler.class, 124 new Class []{Action.class}); 125 TestActionHandler tah = new TestActionHandler(); 126 127 bh.invokeHandle(tah, new Object []{null}); 128 fail("Should have thrown Throwable"); 129 } catch (BeanException be) { 130 assertEquals(Throwable .class, be.getCause().getClass()); 131 } 132 } 133 } | Popular Tags |