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 29 import junit.framework.TestCase; 30 31 import org.apache.cactus.FilterTestCase; 32 import org.apache.cactus.ServletURL; 33 import org.apache.cactus.server.FilterConfigWrapper; 34 import org.apache.cactus.server.HttpServletRequestWrapper; 35 36 42 public class FilterTestCaller extends AbstractWebTestCaller 43 { 44 47 public FilterTestCaller(FilterImplicitObjects theObjects) 48 { 49 super(theObjects); 50 } 51 52 55 protected void setTestCaseFields(TestCase theTestInstance) 56 throws Exception 57 { 58 if (!(theTestInstance instanceof FilterTestCase)) 59 { 60 return; 61 } 62 63 FilterTestCase filterInstance = (FilterTestCase) theTestInstance; 64 FilterImplicitObjects filterImplicitObjects = 65 (FilterImplicitObjects) this.webImplicitObjects; 66 67 HttpServletRequest request = 71 filterImplicitObjects.getHttpServletRequest(); 72 73 ServletURL url = ServletURL.loadFromRequest(request); 74 75 Field requestField = filterInstance.getClass().getField("request"); 76 77 requestField.set(filterInstance, 78 new HttpServletRequestWrapper(request, url)); 79 80 Field responseField = filterInstance.getClass().getField("response"); 83 84 responseField.set(filterInstance, 85 filterImplicitObjects.getHttpServletResponse()); 86 87 Field configField = filterInstance.getClass().getField("config"); 90 91 configField.set(filterInstance, 92 new FilterConfigWrapper(filterImplicitObjects.getFilterConfig())); 93 94 Field chainField = filterInstance.getClass().getField("filterChain"); 97 98 chainField.set(filterInstance, filterImplicitObjects.getFilterChain()); 99 } 100 101 104 protected Writer getResponseWriter() throws IOException 105 { 106 return this.webImplicitObjects.getHttpServletResponse().getWriter(); 107 } 108 } 109 | Popular Tags |