1 7 package com.inversoft.junit.internal; 8 9 10 import javax.servlet.jsp.JspFactory ; 11 12 import com.inversoft.junit.JspTestCase; 13 import com.inversoft.junit.Request; 14 import com.inversoft.junit.Response; 15 import com.inversoft.junit.WebTestCase; 16 import com.inversoft.junit.internal.http.MockHttpServletRequest; 17 import com.inversoft.junit.internal.http.MockHttpServletResponse; 18 import com.inversoft.junit.internal.http.MockJspFactory; 19 import com.inversoft.junit.internal.http.MockPageContext; 20 21 22 30 public class LocalMediator implements Mediator { 31 32 35 public LocalMediator() { 36 } 37 38 39 45 public void mediate(WebTestCase testCase) throws Throwable { 46 47 Request request = new Request(); 50 ClientCaller client = new ClientCaller(); 51 52 client.callBeginMethod(testCase, request); 53 54 setupTestCase(testCase, request); 57 58 LocationCaller location = new LocationCaller(); 59 location.callTestMethod(testCase); 60 61 MockHttpServletResponse mockResponse = testCase.getResponse(); 64 Response response = new Response(request, mockResponse.getStatus(), 65 mockResponse.getText(), null, null, mockResponse.getCookiesMap()); 66 67 client.callEndMethod(testCase, response); 68 } 69 70 74 protected void setupTestCase(WebTestCase testCase, Request request) { 75 testCase.setRequest(new MockHttpServletRequest(request)); 76 testCase.setResponse(new MockHttpServletResponse()); 77 testCase.setContext(testCase.getRequest().getSession().getServletContext()); 78 79 if (testCase instanceof JspTestCase) { 81 JspTestCase jtc = (JspTestCase) testCase; 82 jtc.pageContext = new MockPageContext(testCase.createConfig(), 83 testCase.getRequest(), testCase.getResponse()); 84 JspFactory.setDefaultFactory(new MockJspFactory()); 85 } 86 } 87 } 88 | Popular Tags |