1 56 57 58 package org.hamletsoft.enhydra.cactus.business; 59 60 import java.io.*; 61 import java.lang.reflect.*; 62 import java.net.*; 63 import java.util.*; 64 import javax.servlet.*; 65 import javax.servlet.http.*; 66 import org.apache.cactus.*; 67 import org.apache.log4j.Logger; 68 import org.hamletsoft.enhydra.cactus.data.*; 69 import org.apache.cactus.server.AbstractWebTestCaller; 70 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 71 import javax.servlet.http.HttpServletRequest ; 72 import org.hamletsoft.enhydra.cactus.spec.*; 73 74 82 public class EnhydraAppTestCaller extends AbstractWebTestCaller { 83 86 protected static Logger logger = Logger.getLogger(EnhydraAppTestCaller.class.getName()); 87 88 91 public EnhydraAppTestCaller (EnhydraAppImplicitObjectsImpl theObjects) { 92 super(theObjects); 93 } 94 95 100 protected Writer getResponseWriter () throws IOException { 101 HttpPresentationComms comms = ((EnhydraAppImplicitObjects)this.webImplicitObjects).getPresentationComms(); 102 return comms.response.getHttpServletResponse().getWriter(); 103 } 104 105 109 protected void setTestCaseFields (AbstractTestCase theTestInstance) throws Exception { 110 logger.info("setTestCaseFields([" + theTestInstance + "])"); 111 EnhydraAppTestCase servletInstance = (EnhydraAppTestCase)theTestInstance; 112 EnhydraAppImplicitObjects servletImplicitObjects = (EnhydraAppImplicitObjects)this.webImplicitObjects; 113 HttpPresentationComms comms = servletImplicitObjects.getPresentationComms(); 117 Field commsField = servletInstance.getClass().getField("comms"); 120 commsField.set(servletInstance, comms); 121 Field requestField = servletInstance.getClass().getField("request"); 122 requestField.set(servletInstance, comms.request); 123 Field responseField = servletInstance.getClass().getField("response"); 126 responseField.set(servletInstance, comms.response); 127 Field applicationField = servletInstance.getClass().getField("application"); 130 applicationField.set(servletInstance, comms.application); 131 logger.info("setTestCaseFields"); 132 } 133 134 141 protected Class getTestClassClass (String theClassName) throws ServletException { 142 logger.info("getTestClassClass([" + theClassName + "])"); 143 Class testClass = null; 145 try { 146 EnhydraAppImplicitObjects servletImplicitObjects = (EnhydraAppImplicitObjects)this.webImplicitObjects; 147 HttpPresentationComms comms = servletImplicitObjects.getPresentationComms(); 148 testClass = Class.forName(theClassName, true, comms.application.getHttpPresentationManager().getAppClassLoader()); 149 } catch (Exception e) { 150 e.printStackTrace(); 151 String message = "Error finding class [" + theClassName + "] in classpath"; 152 logger.error(message, e); 153 throw new ServletException(message, e); 154 } 155 logger.info("getTestClassClass"); 156 return testClass; 157 } 158 } 159 160 161 162 | Popular Tags |