1 20 package org.apache.cactus.internal.server; 21 22 import java.io.IOException ; 23 import java.io.Writer ; 24 25 import java.lang.reflect.Field ; 26 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpSession ; 29 30 import junit.framework.TestCase; 31 32 import org.apache.cactus.ServletTestCase; 33 import org.apache.cactus.ServletURL; 34 import org.apache.cactus.server.HttpServletRequestWrapper; 35 import org.apache.cactus.server.ServletConfigWrapper; 36 37 43 public class ServletTestCaller extends AbstractWebTestCaller 44 { 45 48 public ServletTestCaller(ServletImplicitObjects theObjects) 49 { 50 super(theObjects); 51 } 52 53 56 protected void setTestCaseFields(TestCase theTestInstance) 57 throws Exception 58 { 59 if (!(theTestInstance instanceof ServletTestCase)) 60 { 61 return; 62 } 63 64 ServletTestCase servletInstance = (ServletTestCase) theTestInstance; 65 ServletImplicitObjects servletImplicitObjects = 66 (ServletImplicitObjects) this.webImplicitObjects; 67 68 HttpServletRequest request = 72 servletImplicitObjects.getHttpServletRequest(); 73 74 ServletURL url = ServletURL.loadFromRequest(request); 75 76 Field requestField = servletInstance.getClass().getField("request"); 77 78 requestField.set(servletInstance, 79 new HttpServletRequestWrapper(request, url)); 80 81 Field responseField = servletInstance.getClass().getField("response"); 84 85 responseField.set(servletInstance, 86 servletImplicitObjects.getHttpServletResponse()); 87 88 Field configField = servletInstance.getClass().getField("config"); 91 92 configField.set(servletInstance, new ServletConfigWrapper( 93 servletImplicitObjects.getServletConfig())); 94 95 if (isAutoSession()) 99 { 100 HttpSession session = servletImplicitObjects.getHttpServletRequest() 101 .getSession(true); 102 103 Field sessionField = servletInstance.getClass().getField("session"); 104 105 sessionField.set(servletInstance, session); 106 } 107 } 108 109 112 protected Writer getResponseWriter() throws IOException 113 { 114 return this.webImplicitObjects.getHttpServletResponse().getWriter(); 115 } 116 } 117 | Popular Tags |