1 7 package com.inversoft.verge.mvc.servlet.test; 8 9 10 import javax.servlet.ServletException ; 11 12 import junit.framework.AssertionFailedError; 13 14 import com.inversoft.junit.Request; 15 import com.inversoft.junit.WebTestCase; 16 import com.inversoft.junit.internal.http.MockServletConfig; 17 import com.inversoft.junit.internal.http.MockServletContext; 18 import com.inversoft.verge.mvc.MVCConstants; 19 import com.inversoft.verge.mvc.servlet.MVCServlet; 20 21 22 28 public class MVCServletTest extends WebTestCase { 29 30 33 public MVCServletTest(String name) { 34 super(name); 35 setLocal(true); 36 } 37 38 39 42 public void testSuccess() { 43 44 MockServletConfig config = createConfig(); 45 MVCServlet servlet = new MVCServlet(); 46 try { 47 servlet.init(config); 48 } catch (ServletException se) { 49 fail(se.toString()); 50 } 51 } 52 53 56 public void testDefault() { 57 58 MockServletConfig config = createConfig(); 59 if (isLocal()) { 60 MockServletContext context = 61 (MockServletContext) config.getServletContext(); 62 context.setInitParameter(MVCConstants.CONTEXT_PARAM, 63 "com.inversoft.verge.mvc.servlet.test.TestMVCMediator"); 64 } 65 66 MVCServlet servlet = new MVCServlet(); 67 try { 68 servlet.init(config); 69 } catch (ServletException se) { 70 fail(se.toString()); 71 } 72 } 73 74 77 public void testFailure() { 78 79 MockServletConfig config = createConfig(); 80 if (isLocal()) { 81 MockServletContext context = 82 (MockServletContext) config.getServletContext(); 83 context.setInitParameter(MVCConstants.CONTEXT_PARAM, 84 "com.inversoft.verge.mvc.servlet.test.NotAClass"); 85 } 86 87 try { 88 MVCServlet servlet = new MVCServlet(); 89 servlet.init(config); 90 fail("Should have asserted"); 91 } catch (AssertionFailedError afe) { 92 } catch (Throwable t) { 94 assertTrue("Should be assertion error", t instanceof AssertionError ); 95 } 96 } 97 98 102 public void testSuccessCall() { 103 104 MockServletConfig config = createConfig(); 105 if (isLocal()) { 106 MockServletContext context = 107 (MockServletContext) config.getServletContext(); 108 context.setInitParameter(MVCConstants.CONTEXT_PARAM, 109 "com.inversoft.verge.mvc.servlet.test.TestMVCMediator"); 110 } 111 112 try { 113 MVCServlet servlet = new MVCServlet(); 114 servlet.init(config); 115 servlet.doGet(request, response); 116 } catch (Throwable t) { 117 fail(t.toString()); 118 } 119 } 120 121 124 public void beginFailureCall(Request request) { 125 request.addParameter(TestMVCMediator.FAIL, TestMVCMediator.FAIL); 126 } 127 128 132 public void testFailureCall() { 133 134 MockServletConfig config = createConfig(); 135 if (isLocal()) { 136 MockServletContext context = 137 (MockServletContext) config.getServletContext(); 138 context.setInitParameter(MVCConstants.CONTEXT_PARAM, 139 "com.inversoft.verge.mvc.servlet.test.TestMVCMediator"); 140 } 141 142 try { 143 MVCServlet servlet = new MVCServlet(); 144 servlet.init(config); 145 servlet.doGet(request, response); 146 fail("Should have failed inside the call the TestMVCMediator"); 147 } catch (Throwable t) { 148 assertTrue("Should have been a ServletException", 149 t instanceof ServletException ); 150 assertTrue("Should have message of fail", 151 t.getMessage().equals(TestMVCMediator.FAIL)); 152 } 153 } 154 } 155 | Popular Tags |