vmassol 01/08/19 09:12:56 Modified: cactus/src/framework/share/org/apache/commons/cactus AbstractTestCase.java JspTestCase.java overview.html package.html ServiceDefinition.java ServiceEnumeration.java ServletTestCase.java ServletTestRequest.java ServletURL.java WebRequest.java WebResponse.java Log: align with coding conventions Revision Changes Path 1.4 +14 -8 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/AbstractTestCase.java Index: AbstractTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/AbstractTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractTestCase.java 2001/08/11 13:33:07 1.3 +++ AbstractTestCase.java 2001/08/19 16:12:55 1.4 @@ -70,7 +70,9 @@ * <code>FilterTestCase</code>, ...) must extend. Provides generally useful * methods fro writing a specific test case. * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: AbstractTestCase.java,v 1.4 2001/08/19 16:12:55 vmassol Exp $ */ public abstract class AbstractTestCase extends TestCase { @@ -111,7 +113,7 @@ public AbstractTestCase(String theName) { super(theName); - currentTestMethod = name(); + this.currentTestMethod = name(); } /** @@ -155,7 +157,8 @@ * @param theRequest the <code>ServletTestRequest</code> object to * pass to the begin method. */ - protected void callBeginMethod(ServletTestRequest theRequest) throws Throwable + protected void callBeginMethod(ServletTestRequest theRequest) + throws Throwable { // First, verify if a begin method exist. If one is found, verify if // it has the correct signature. If not, send a warning. @@ -283,7 +286,7 @@ // Has a method to call already been found ? if (methodToCall != null) { fail("There can only be one end method per test case. " + - "Test case [" + currentTestMethod + + "Test case [" + this.currentTestMethod + "] has two at least !"); } @@ -354,7 +357,8 @@ // on the client side. if (!LogService.getInstance().isInitialized()) { LogService.getInstance().init("/log_client.properties"); - logger = LogService.getInstance().getLog(this.getClass().getName()); + this.logger = + LogService.getInstance().getLog(this.getClass().getName()); } runTest(); @@ -393,14 +397,16 @@ // methods. getDeclaredMethods returns all // methods of this class but excludes the // inherited ones. - runMethod = getClass().getMethod(currentTestMethod, new Class[0]); + runMethod = getClass().getMethod(this.currentTestMethod, + new Class[0]); + } catch (NoSuchMethodException e) { - fail("Method [" + currentTestMethod + + fail("Method [" + this.currentTestMethod + "()] does not exist for class [" + this.getClass().getName() + "]."); } if (runMethod != null && !Modifier.isPublic(runMethod.getModifiers())) { - fail("Method [" + currentTestMethod + "()] should be public"); + fail("Method [" + this.currentTestMethod + "()] should be public"); } try { 1.3 +7 -5 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/JspTestCase.java Index: JspTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/JspTestCase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JspTestCase.java 2001/04/19 23:22:09 1.2 +++ JspTestCase.java 2001/08/19 16:12:55 1.3 @@ -62,14 +62,16 @@ * page context, the output jsp writer, the HTTP request, ...) must subclass * this class. * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: JspTestCase.java,v 1.3 2001/08/19 16:12:55 vmassol Exp $ */ public class JspTestCase extends ServletTestCase { /** * Valid <code>PageContext</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ @@ -77,8 +79,8 @@ /** * Valid <code>JspWriter</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ 1.2 +7 -7 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/overview.html Index: overview.html =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/overview.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- overview.html 2001/04/09 11:52:36 1.1 +++ overview.html 2001/08/19 16:12:55 1.2 @@ -6,14 +6,14 @@ <body> -<p>Cactus is a JUnit extension to unit test server-side java code. A server- -side java code is some code that is called either by a JSP or by a Servlet. -Server-side code is also code that may need to have access to valid -<code>HttpServletRequest</code>, <code>HttpServletResponse</code> and -<code>HttpSession</code> objects.</p> +<p> + Cactus is a JUnit extension to unit test server-side java code. +</p> -<p>Go to the <a href="http://jakarta.apache.org/commons/cactus">Cactus web site</a> -for all documentation and tutorials for installing and running Cactus</p> +<p> + Go to the <a href="http://jakarta.apache.org/commons/cactus">Cactus web + site</a> for all documentation on Cactus. +</p> </body> </html> 1.2 +3 -2 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/package.html Index: package.html =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- package.html 2001/04/09 11:52:36 1.1 +++ package.html 2001/08/19 16:12:55 1.2 @@ -6,8 +6,9 @@ <body> -<p>Base package for the Cactus project. All the framework classes are located -under subpackages of this package. +<p> + Contains all classes needed for Writing Cactus test classes. +</p> </body> </html> 1.2 +16 -8 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceDefinition.java Index: ServiceDefinition.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceDefinition.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServiceDefinition.java 2001/04/09 11:52:36 1.1 +++ ServiceDefinition.java 2001/08/19 16:12:55 1.2 @@ -56,28 +56,35 @@ /** * Constants that define HTTP parameters required for defining a service that * is performed by the <code>ServletTestRedirector</code> servlet. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: ServiceDefinition.java,v 1.2 2001/08/19 16:12:55 vmassol Exp $ */ public class ServiceDefinition { /** * Name of the parameter in the HTTP request that represents the name of the - * Test class to call. The name is voluntarily long so that it will not clash - * with a user-defined parameter. + * Test class to call. The name is voluntarily long so that it will not + * clash with a user-defined parameter. */ - public final static String CLASS_NAME_PARAM = "ServletTestRedirector_TestClass"; + public final static String CLASS_NAME_PARAM = + "ServletTestRedirector_TestClass"; /** * Name of the parameter in the HTTP request that represents the name of the - * Test method to call. The name is voluntarily long so that it will not clash - * with a user-defined parameter. + * Test method to call. The name is voluntarily long so that it will not + * clash with a user-defined parameter. */ - public final static String METHOD_NAME_PARAM = "ServletTestRedirector_TestMethod"; + public final static String METHOD_NAME_PARAM = + "ServletTestRedirector_TestMethod"; /** * Name of the parameter in the HTTP request that specify if a session * should be automatically created for the user or not. */ - public final static String AUTOSESSION_NAME_PARAM = "ServletTestRedirector_AutomaticSession"; + public final static String AUTOSESSION_NAME_PARAM = + "ServletTestRedirector_AutomaticSession"; /** * Name of the parameter in the HTTP request that specify the service asked @@ -87,6 +94,7 @@ * * @see ServiceEnumeration */ - public final static String SERVICE_NAME_PARAM = "ServletTestRedirector_Service"; + public final static String SERVICE_NAME_PARAM = + "ServletTestRedirector_Service"; } 1.2 +17 -8 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceEnumeration.java Index: ServiceEnumeration.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceEnumeration.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServiceEnumeration.java 2001/04/09 11:52:36 1.1 +++ ServiceEnumeration.java 2001/08/19 16:12:55 1.2 @@ -54,37 +54,46 @@ package org.apache.commons.cactus; /** - * List of valid services that the <code>ServletTestRedirector</code> can perform. + * List of valid services that the <code>ServletTestRedirector</code> can + * perform. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: ServiceEnumeration.java,v 1.2 2001/08/19 16:12:55 vmassol Exp $ */ public class ServiceEnumeration { /** * Call test method Service. */ - public static final ServiceEnumeration CALL_TEST_SERVICE = new ServiceEnumeration("CALL_TEST"); + public static final ServiceEnumeration CALL_TEST_SERVICE = + new ServiceEnumeration("CALL_TEST"); /** * Get the previous test results Service. */ - public static final ServiceEnumeration GET_RESULTS_SERVICE = new ServiceEnumeration("GET_RESULTS"); + public static final ServiceEnumeration GET_RESULTS_SERVICE = + new ServiceEnumeration("GET_RESULTS"); /** * The service's name */ - private String m_Name; + private String name; public ServiceEnumeration(String theServiceName) { - m_Name = theServiceName; + this.name = theServiceName; } /** - * Compares a string representing the name of the service with the Service enumerated type. + * Compares a string representing the name of the service with the Service + * enumerated type. + * * @return true if the string corresponds to the current Service */ public boolean equals(String theString) { - return theString.equals(m_Name); + return theString.equals(this.name); } /** @@ -92,7 +101,7 @@ */ public String toString() { - return m_Name; + return this.name; } } 1.5 +24 -13 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestCase.java Index: ServletTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletTestCase.java 2001/06/17 13:41:32 1.4 +++ ServletTestCase.java 2001/08/19 16:12:55 1.5 @@ -68,14 +68,16 @@ * the HTTP request, the HTTP response, the servlet config, ...) must subclass * this class. * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: ServletTestCase.java,v 1.5 2001/08/19 16:12:55 vmassol Exp $ */ public class ServletTestCase extends AbstractTestCase { /** * Valid <code>HttpServletRequest</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ @@ -83,8 +85,8 @@ /** * Valid <code>HttpServletResponse</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ @@ -92,8 +94,8 @@ /** * Valid <code>HttpSession</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ @@ -101,8 +103,8 @@ /** * Valid <code>ServletConfig</code> object that you can access from - * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> - * methods. If you try to access it from either the + * the <code>testXXX()</code>, <code>setUp</code> and + * <code>tearDown()</code> methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ @@ -128,12 +130,21 @@ runGenericTest(new ServletHttpClient()); } - protected void runGenericTest(AbstractHttpClient theHttpClient) throws Throwable + /** + * Execute the test case begin method, then connect to the server proxy + * redirector (where the test case test method is executed) and then + * executes the test case end method. + * + * @param theHttpClient the HTTP client class to use to connect to the + * proxy redirector. + */ + protected void runGenericTest(AbstractHttpClient theHttpClient) + throws Throwable { - logger.entry("runGenericTest(...)"); + this.logger.entry("runGenericTest(...)"); // Log the test name - logger.debug("Test case = " + currentTestMethod); + this.logger.debug("Test case = " + currentTestMethod); // Call the begin method to fill the request object ServletTestRequest request = new ServletTestRequest(); @@ -165,7 +176,7 @@ connection.getInputStream().close(); //connection.disconnect(); - logger.exit("runGenericTest"); + this.logger.exit("runGenericTest"); } } 1.5 +3 -1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestRequest.java Index: ServletTestRequest.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletTestRequest.java 2001/08/11 13:33:07 1.4 +++ ServletTestRequest.java 2001/08/19 16:12:55 1.5 @@ -77,7 +77,9 @@ * use a POST or GET method. Default is POST</li> * </ul> * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: ServletTestRequest.java,v 1.5 2001/08/19 16:12:55 vmassol Exp $ * @deprecated As of Cactus 1.2, replaced by WebRequest * @see WebRequest */ 1.3 +86 -62 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletURL.java Index: ServletURL.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletURL.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletURL.java 2001/07/04 09:17:37 1.2 +++ ServletURL.java 2001/08/19 16:12:55 1.3 @@ -81,7 +81,9 @@ * <li><b>PathInfo</b>: The part of the request path that is not part of the * Context Path or the Servlet Path.</li></ul></pre></code> * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: ServletURL.java,v 1.3 2001/08/19 16:12:55 vmassol Exp $ */ public class ServletURL { @@ -90,65 +92,70 @@ * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ - public final static String URL_SERVER_NAME_PARAM = "ServletTestCase_URL_Server"; + public final static String URL_SERVER_NAME_PARAM = + "ServletTestCase_URL_Server"; /** - * Name of the parameter in the HTTP request that represents the context path - * in the URL to simulate. The name is voluntarily long so that it will not - * clash with a user-defined parameter. + * Name of the parameter in the HTTP request that represents the context + * path in the URL to simulate. The name is voluntarily long so that it + * will not clash with a user-defined parameter. */ - public final static String URL_CONTEXT_PATH_PARAM = "ServletTestCase_URL_ContextPath"; + public final static String URL_CONTEXT_PATH_PARAM = + "ServletTestCase_URL_ContextPath"; /** * Name of the parameter in the HTTP request that represents the Servlet - * Path in the URL to simulate. The name is voluntarily long so that it will not - * clash with a user-defined parameter. + * Path in the URL to simulate. The name is voluntarily long so that it + * will not clash with a user-defined parameter. */ - public final static String URL_SERVLET_PATH_PARAM = "ServletTestCase_URL_ServletPath"; + public final static String URL_SERVLET_PATH_PARAM = + "ServletTestCase_URL_ServletPath"; /** * Name of the parameter in the HTTP request that represents the Path Info * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ - public final static String URL_PATH_INFO_PARAM = "ServletTestCase_URL_PathInfo"; + public final static String URL_PATH_INFO_PARAM = + "ServletTestCase_URL_PathInfo"; /** - * Name of the parameter in the HTTP request that represents the Query String - * in the URL to simulate. The name is voluntarily long so that it will not - * clash with a user-defined parameter. + * Name of the parameter in the HTTP request that represents the Query + * String in the URL to simulate. The name is voluntarily long so that it + * will not clash with a user-defined parameter. */ - public final static String URL_QUERY_STRING_PARAM = "ServletTestCase_URL_QueryString"; + public final static String URL_QUERY_STRING_PARAM = + "ServletTestCase_URL_QueryString"; /** * The server name to simulate (including port number) */ - private String m_URL_ServerName; + private String serverName; /** * The context path to simulate */ - private String m_URL_ContextPath; + private String contextPath; /** * The servlet path to simulate */ - private String m_URL_ServletPath; + private String servletPath; /** * The Path Info to simulate */ - private String m_URL_PathInfo; + private String pathInfo; /** * The Query string */ - private String m_URL_QueryString; + private String queryString; /** * The logger */ - private static Log m_Logger = + private static Log logger = LogService.getInstance().getLog(ServletURL.class.getName()); /** @@ -180,14 +187,14 @@ * <code>HttpServletResquest.getQueryString()</code>. * Can be null. */ - public ServletURL(String theServerName, String theContextPath, String theServletPath, - String thePathInfo, String theQueryString) + public ServletURL(String theServerName, String theContextPath, + String theServletPath, String thePathInfo, String theQueryString) { - m_URL_ServerName = theServerName; - m_URL_ContextPath = theContextPath; - m_URL_ServletPath = theServletPath; - m_URL_PathInfo = thePathInfo; - m_URL_QueryString = theQueryString; + this.serverName = theServerName; + this.contextPath = theContextPath; + this.servletPath = theServletPath; + this.pathInfo = thePathInfo; + this.queryString = theQueryString; } /** @@ -195,7 +202,7 @@ */ public String getServerName() { - return m_URL_ServerName; + return this.serverName; } /** @@ -203,12 +210,16 @@ */ public String getHost() { - int pos = m_URL_ServerName.indexOf(":"); - if (pos > 0) { - return m_URL_ServerName.substring(0, pos + 1); + String host = this.serverName; + + if (this.serverName != null) { + int pos = this.serverName.indexOf(":"); + if (pos > 0) { + host = this.serverName.substring(0, pos + 1); + } } - return m_URL_ServerName; + return host; } /** @@ -217,20 +228,24 @@ */ public int getPort() { - int pos = m_URL_ServerName.indexOf(":"); - int result; + int port = -1; - if (pos < 0) { - return -1; - } + if (this.serverName != null) { + + int pos = this.serverName.indexOf(":"); - try { - result = Integer.parseInt(m_URL_ServerName.substring(pos + 1)); - } catch (NumberFormatException e) { - return -1; + if (pos < 0) { + return -1; + } + + try { + port = Integer.parseInt(this.serverName.substring(pos + 1)); + } catch (NumberFormatException e) { + port = -1; + } } - return result; + return port; } /** @@ -238,7 +253,7 @@ */ public String getContextPath() { - return m_URL_ContextPath; + return this.contextPath; } /** @@ -246,7 +261,7 @@ */ public String getServletPath() { - return m_URL_ServletPath; + return this.servletPath; } /** @@ -254,7 +269,7 @@ */ public String getPathInfo() { - return m_URL_PathInfo; + return this.pathInfo; } /** @@ -262,7 +277,7 @@ */ public String getQueryString() { - return m_URL_QueryString; + return this.queryString; } /** @@ -272,19 +287,19 @@ */ public void saveToRequest(ServletTestRequest theRequest) { - if (m_URL_ServerName != null) { + if (getServerName() != null) { theRequest.addParameter(URL_SERVER_NAME_PARAM, getServerName()); } - if (m_URL_ContextPath != null) { + if (getContextPath() != null) { theRequest.addParameter(URL_CONTEXT_PATH_PARAM, getContextPath()); } - if (m_URL_ServletPath != null) { + if (getServletPath() != null) { theRequest.addParameter(URL_SERVLET_PATH_PARAM, getServletPath()); } - if (m_URL_PathInfo != null) { + if (getPathInfo() != null) { theRequest.addParameter(URL_PATH_INFO_PARAM, getPathInfo()); } - if (m_URL_QueryString != null) { + if (getQueryString() != null) { theRequest.addParameter(URL_QUERY_STRING_PARAM, getQueryString()); } } @@ -297,28 +312,37 @@ */ public static ServletURL loadFromRequest(HttpServletRequest theRequest) { - m_Logger.entry("loadFromRequest(...)"); + logger.entry("loadFromRequest(...)"); String serverName = theRequest.getParameter(URL_SERVER_NAME_PARAM); - m_Logger.debug("serverName = [" + serverName + "]"); - String contextPath = theRequest.getParameter(URL_CONTEXT_PATH_PARAM); - m_Logger.debug("contextPath = [" + contextPath + "]"); - String servletPath = theRequest.getParameter(URL_SERVLET_PATH_PARAM); - m_Logger.debug("servletPath = [" + servletPath + "]"); - String pathInfo = theRequest.getParameter(URL_PATH_INFO_PARAM); - m_Logger.debug("pathInfo = [" + pathInfo + "]"); - String queryString = theRequest.getParameter(URL_QUERY_STRING_PARAM); - m_Logger.debug("queryString = [" + queryString + "]"); ServletURL url = new ServletURL(serverName, contextPath, servletPath, pathInfo, queryString); - m_Logger.entry("loadFromRequest(...)"); + logger.debug("URL = [" + url + "]"); + + logger.entry("loadFromRequest(...)"); return url; + } + + /** + * @return a string representation + */ + public String toString() + { + StringBuffer buffer = new StringBuffer(); + buffer.append("host name = [" + getHost() + "], "); + buffer.append("port = [" + getPort() + "], "); + buffer.append("context path = [" + getContextPath() + "], "); + buffer.append("servlet path = [" + getServletPath() + "], "); + buffer.append("path info = [" + getPathInfo() + "], "); + buffer.append("query string = [" + getQueryString() + "]"); + + return buffer.toString(); } } 1.2 +110 -44 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/WebRequest.java Index: WebRequest.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/WebRequest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebRequest.java 2001/08/11 13:33:07 1.1 +++ WebRequest.java 2001/08/19 16:12:55 1.2 @@ -77,14 +77,16 @@ * use a POST or GET method. Default is POST</li> * </ul> * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: WebRequest.java,v 1.2 2001/08/19 16:12:55 vmassol Exp $ */ public class WebRequest { /** * The request parameters. */ - private Hashtable m_Parameters = new Hashtable(); + private Hashtable parameters = new Hashtable(); /** * GET Method identifier. @@ -99,27 +101,27 @@ /** * The Cookies */ - private Hashtable m_Cookies = new Hashtable(); + private Hashtable cookies = new Hashtable(); /** * HTTP Headers. */ - private Hashtable m_Headers = new Hashtable(); + private Hashtable headers = new Hashtable(); /** * The URL to simulate */ - private ServletURL m_URL; + private ServletURL url; /** * Automatic session creation flag (default is true). */ - private boolean m_isAutomaticSession = true; + private boolean isAutomaticSession = true; /** * The chosen method for posting data (GET or POST) */ - private String m_Method = POST_METHOD; + private String method = POST_METHOD; /** * @param theMethod the method to use to post data (GET or POST) @@ -127,9 +129,9 @@ public void setMethod(String theMethod) { if (theMethod.equalsIgnoreCase(GET_METHOD)) { - m_Method = GET_METHOD; + this.method = GET_METHOD; } else if (theMethod.equalsIgnoreCase(POST_METHOD)) { - m_Method = POST_METHOD; + this.method = POST_METHOD; } } @@ -138,16 +140,16 @@ */ public String getMethod() { - return m_Method; + return this.method; } /** - * @param isAutomaticSession whether the redirector servlet will automatically - * create the HTTP session or not. Default is true. + * @param isAutomaticSession whether the redirector servlet will + * automatically create the HTTP session or not. Default is true. */ public void setAutomaticSession(boolean isAutomaticSession) { - m_isAutomaticSession = isAutomaticSession; + this.isAutomaticSession = isAutomaticSession; } /** @@ -156,7 +158,7 @@ */ public boolean getAutomaticSession() { - return m_isAutomaticSession; + return this.isAutomaticSession; } /** @@ -166,15 +168,18 @@ * requestURI = contextPath + servletPath + pathInfo * </b></pre></code> * From the Servlet 2.2 specification :<br> - * <code><pre><ul><li><b>Context Path</b>: The path prefix associated with the + * <code><pre><ul> + * <li><b>Context Path</b>: The path prefix associated with the * ServletContext that this servlet is a part of. If this context is the - * default context rooted at the base of the web server's URL namespace, this - * path will be an empty string. Otherwise, this path starts with a character - * but does not end with a character.</li> - * <li><b>Servlet Path</b>: The path section that directly corresponds to the - * mapping which activated this request. This path starts with a character.</li> - * <li><b>PathInfo</b>: The part of the request path that is not part of the - * Context Path or the Servlet Path.</li></ul></pre></code> + * default context rooted at the base of the web server's URL namespace, + * this path will be an empty string. Otherwise, this path starts with a + * character but does not end with a character.</li> + * <li><b>Servlet Path</b>: The path section that directly corresponds to + * the mapping which activated this request. This path starts with a + * character.</li> + * <li><b>PathInfo</b>: The part of the request path that is not part of the + * Context Path or the Servlet Path.</li> + * </ul></pre></code> * * @param theServerName the server name (and port) in the URL to simulate, * i.e. this is the name that will be returned by the @@ -201,7 +206,7 @@ public void setURL(String theServerName, String theContextPath, String theServletPath, String thePathInfo, String theQueryString) { - m_URL = new ServletURL(theServerName, theContextPath, + this.url = new ServletURL(theServerName, theContextPath, theServletPath, thePathInfo, theQueryString); // Now automatically add all HTTP parameters to the list of passed @@ -214,12 +219,13 @@ */ public ServletURL getURL() { - return m_URL; + return this.url; } /** * Adds a parameter to the request. It is possible to add several times the - * the same parameter name (the same as for the <code>HttpServletRequest</code>). + * the same parameter name (the same as for the + * <code>HttpServletRequest</code>). * * @param theName the parameter's name * @param theValue the parameter's value @@ -230,13 +236,13 @@ // new value to the Vector. If not, create a Vector an add it to the // hashtable - if (m_Parameters.containsKey(theName)) { - Vector v = (Vector)m_Parameters.get(theName); + if (this.parameters.containsKey(theName)) { + Vector v = (Vector)this.parameters.get(theName); v.addElement(theValue); } else { Vector v = new Vector(); v.addElement(theValue); - m_Parameters.put(theName, v); + this.parameters.put(theName, v); } } @@ -245,15 +251,15 @@ */ public Enumeration getParameterNames() { - return m_Parameters.keys(); + return this.parameters.keys(); } /** * Returns the first value corresponding to this parameter's name. * * @param theName the parameter's name - * @return the first value corresponding to this parameter's name or null if not - * found + * @return the first value corresponding to this parameter's name or null + * if not found */ public String getParameter(String theName) { @@ -275,9 +281,9 @@ */ public String[] getParameterValues(String theName) { - if (m_Parameters.containsKey(theName)) { + if (this.parameters.containsKey(theName)) { - Vector v = (Vector)m_Parameters.get(theName); + Vector v = (Vector)this.parameters.get(theName); Object[] objs = new Object[v.size()]; v.copyInto(objs); @@ -301,7 +307,7 @@ */ public void addCookie(String theName, String theValue) { - m_Cookies.put(theName, theValue); + this.cookies.put(theName, theValue); } /** @@ -309,7 +315,7 @@ */ public Enumeration getCookieNames() { - return m_Cookies.keys(); + return this.cookies.keys(); } /** @@ -319,7 +325,7 @@ */ public String getCookieValue(String theName) { - return (String)m_Cookies.get(theName); + return (String)this.cookies.get(theName); } /** @@ -335,13 +341,13 @@ // new header to the Vector. If not, create a Vector an add it to the // hashtable - if (m_Headers.containsKey(theName)) { - Vector v = (Vector)m_Headers.get(theName); + if (this.headers.containsKey(theName)) { + Vector v = (Vector)this.headers.get(theName); v.addElement(theValue); } else { Vector v = new Vector(); v.addElement(theValue); - m_Headers.put(theName, v); + this.headers.put(theName, v); } } @@ -350,15 +356,15 @@ */ public Enumeration getHeaderNames() { - return m_Headers.keys(); + return this.headers.keys(); } /** * Returns the first value corresponding to this header's name. * * @param theName the header's name - * @return the first value corresponding to this header's name or null if not - * found + * @return the first value corresponding to this header's name or null if + * not found */ public String getHeader(String theName) { @@ -380,9 +386,9 @@ */ public String[] getHeaderValues(String theName) { - if (m_Headers.containsKey(theName)) { + if (this.headers.containsKey(theName)) { - Vector v = (Vector)m_Headers.get(theName); + Vector v = (Vector)this.headers.get(theName); Object[] objs = new Object[v.size()]; v.copyInto(objs); @@ -428,6 +434,66 @@ theQueryString + "] NameValue pair: [" + nameValue + "]"); } } + } + + /** + * @return a string representation of the request + */ + public String toString() + { + StringBuffer buffer = new StringBuffer(); + buffer.append("simulation URL = [" + getURL() + "], "); + buffer.append("automatic session = [" + getAutomaticSession() + "], "); + + // Append cookies + buffer.append("cookies = ["); + Enumeration cookies = getCookieNames(); + while (cookies.hasMoreElements()) { + buffer.append("["); + String cookieName = (String)cookies.nextElement(); + String cookieValue = getCookieValue(cookieName); + buffer.append("[" + cookieName + "] = [" + cookieValue + "]"); + buffer.append("]"); + } + buffer.append("], "); + + // Append headers + buffer.append("headers = ["); + Enumeration headers = getHeaderNames(); + while (headers.hasMoreElements()) { + buffer.append("["); + String headerName = (String)headers.nextElement(); + String[] headerValues = getHeaderValues(headerName); + buffer.append("[" + headerName + "] = ["); + for (int i = 0; i < headerValues.length - 1; i++) { + buffer.append("[" + headerValues[i] + "], "); + } + buffer.append("[" + headerValues[headerValues.length - 1] + "]]"); + buffer.append("]"); + } + buffer.append("], "); + + buffer.append("method = [" + getMethod() + "], "); + + + // Append parameters + buffer.append("parameters = ["); + Enumeration parameters = getParameterNames(); + while (parameters.hasMoreElements()) { + buffer.append("["); + String parameterName = (String)parameters.nextElement(); + String[] parameterValues = getParameterValues(parameterName); + buffer.append("[" + parameterName + "] = ["); + for (int i = 0; i < parameterValues.length - 1; i++) { + buffer.append("[" + parameterValues[i] + "], "); + } + buffer.append("[" + parameterValues[parameterValues.length - 1] + + "]]"); + buffer.append("]"); + } + buffer.append("]"); + + return buffer.toString(); } } 1.3 +15 -13 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/WebResponse.java Index: WebResponse.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/WebResponse.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebResponse.java 2001/08/11 16:42:06 1.2 +++ WebResponse.java 2001/08/19 16:12:55 1.3 @@ -66,14 +66,16 @@ * complex assertions, use an <code>com.meterware.httpunit.WebResponse</code> * instead as parameter of your <code>endXXX()</code> methods. * - * @version @version@ + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> + * + * @version $Id: WebResponse.java,v 1.3 2001/08/19 16:12:55 vmassol Exp $ */ public class WebResponse { /** * The connection object that was used to call the URL */ - private HttpURLConnection m_Connection; + private HttpURLConnection connection; /** * @param theConnection the original <code>HttpURLConnection</code> used @@ -81,7 +83,7 @@ */ public WebResponse(HttpURLConnection theConnection) { - m_Connection = theConnection; + this.connection = theConnection; } /** @@ -90,7 +92,7 @@ */ public HttpURLConnection getConnection() { - return m_Connection; + return this.connection; } /** @@ -102,7 +104,7 @@ try { BufferedReader input = new BufferedReader( - new InputStreamReader(m_Connection.getInputStream())); + new InputStreamReader(this.connection.getInputStream())); char[] buffer = new char[2048]; int nb; while (-1 != (nb = input.read(buffer, 0, 2048))) { @@ -126,7 +128,7 @@ try { BufferedReader input = new BufferedReader( - new InputStreamReader(m_Connection.getInputStream())); + new InputStreamReader(this.connection.getInputStream())); String str; while (null != (str = input.readLine())) { lines.addElement(str); @@ -148,7 +150,7 @@ public InputStream getInputStream() { try { - return m_Connection.getInputStream(); + return this.connection.getInputStream(); } catch (IOException e) { throw new ChainedRuntimeException(e); } @@ -180,8 +182,8 @@ // There can be several headers named "Set-Cookie", so loop through all // the headers, looking for cookies - String headerName = m_Connection.getHeaderFieldKey(0); - String headerValue = m_Connection.getHeaderField(0); + String headerName = this.connection.getHeaderFieldKey(0); + String headerValue = this.connection.getHeaderField(0); for (int i = 1; (headerName != null) || (headerValue != null); i++) { if ((headerName != null) && headerName.equals("Set-Cookie")) { @@ -196,7 +198,8 @@ // Check if the cookie name already exist in the hashtable. // If so, then add it to the vector of cookies for that name. - String name = ((ClientCookie)clientCookies.elementAt(0)).getName(); + String name = + ((ClientCookie)clientCookies.elementAt(0)).getName(); if (cookies.containsKey(name)) { Vector cookieValues = (Vector)cookies.get(name); @@ -208,8 +211,8 @@ } } - headerName = m_Connection.getHeaderFieldKey(i); - headerValue = m_Connection.getHeaderField(i); + headerName = this.connection.getHeaderFieldKey(i); + headerValue = this.connection.getHeaderField(i); } @@ -307,6 +310,5 @@ return cookies; } - }