org.apache.commons.cactus
Class ServletTestRequest

java.lang.Object
  |
  +--org.apache.commons.cactus.ServletTestRequest

public class ServletTestRequest
extends java.lang.Object

Contains all HTTP request data for a test case. It is the data that will be sent to the server redirector and that will be available to the test methods through the HttpServletRequest object.

Namely, it is :

Version:
1.1

Field Summary
static java.lang.String GET_METHOD
          GET Method identifier.
static java.lang.String POST_METHOD
          POST Method identifier.
 
Constructor Summary
ServletTestRequest()
           
 
Method Summary
 void addCookie(java.lang.String theName, java.lang.String theValue)
          Adds a cookie to the request.
 void addHeader(java.lang.String theName, java.lang.String theValue)
          Adds a header to the request.
 void addParameter(java.lang.String theName, java.lang.String theValue)
          Adds a parameter to the request.
 boolean getAutomaticSession()
           
 java.util.Enumeration getCookieNames()
           
 java.lang.String getCookieValue(java.lang.String theName)
           
 java.lang.String getHeader(java.lang.String theName)
          Returns the first value corresponding to this header's name.
 java.util.Enumeration getHeaderNames()
           
 java.lang.String[] getHeaderValues(java.lang.String theName)
          Returns all the values associated with this header's name.
 java.lang.String getMethod()
           
 java.lang.String getParameter(java.lang.String theName)
          Returns the first value corresponding to this parameter's name.
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String theName)
          Returns all the values associated with this parameter's name.
 ServletURL getURL()
           
 void setAutomaticSession(boolean isAutomaticSession)
           
 void setMethod(java.lang.String theMethod)
           
 void setURL(java.lang.String theServerName, java.lang.String theContextPath, java.lang.String theServletPath, java.lang.String thePathInfo, java.lang.String theQueryString)
          Sets the simulated URL.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_METHOD

public static final java.lang.String GET_METHOD
GET Method identifier.

POST_METHOD

public static final java.lang.String POST_METHOD
POST Method identifier.
Constructor Detail

ServletTestRequest

public ServletTestRequest()
Method Detail

setMethod

public void setMethod(java.lang.String theMethod)
Parameters:
theMethod - the method to use to post data (GET or POST)

getMethod

public java.lang.String getMethod()
Returns:
the method to use for posting data to the server redirector.

setAutomaticSession

public void setAutomaticSession(boolean isAutomaticSession)
Parameters:
isAutomaticSession - whether the redirector servlet will automatically create the HTTP session or not. Default is true.

getAutomaticSession

public boolean getAutomaticSession()
Returns:
true if session will be automatically created for the user or false otherwise.

setURL

public void setURL(java.lang.String theServerName,
                   java.lang.String theContextPath,
                   java.lang.String theServletPath,
                   java.lang.String thePathInfo,
                   java.lang.String theQueryString)
Sets the simulated URL. A URL is of the form :

 URL        = "http://" + serverName (including port) + requestURI ? queryString
requestURI = contextPath + servletPath + pathInfo
From the Servlet 2.2 specification :
  • Context Path: 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.
  • Servlet Path: The path section that directly corresponds to the mapping which activated this request. This path starts with a character.
  • PathInfo: The part of the request path that is not part of the Context Path or the Servlet Path.
Parameters:
theServerName - the server name (and port) in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getServerName() and HttpServletRequest.getServerPort().
theContextPath - the webapp context path in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getContextPath(). Can be null. Format: "/" + name or an empty string for the default context.
theServletPath - the servlet path in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getServletPath(). Can be null. Format : "/" + name.
thePathInfo - the path info in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getPathInfo(). Can be null. Format : "/" + name.
theQueryString - the Query string in the URL to simulate, i.e. this is the string that will be returned by the HttpServletResquest.getQueryString(). Can be null.

getURL

public ServletURL getURL()
Returns:
the simulated URL

addParameter

public void addParameter(java.lang.String theName,
                         java.lang.String theValue)
Adds a parameter to the request. It is possible to add several times the the same parameter name (the same as for the HttpServletRequest).
Parameters:
theName - the parameter's name
theValue - the parameter's value

getParameterNames

public java.util.Enumeration getParameterNames()
Returns:
the parameter names

getParameter

public java.lang.String getParameter(java.lang.String theName)
Returns the first value corresponding to this parameter's name.
Parameters:
theName - the parameter's name
Returns:
the first value corresponding to this parameter's name or null if not found

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String theName)
Returns all the values associated with this parameter's name.
Parameters:
theName - the parameter's name
Returns:
the values corresponding to this parameter's name or null if not found

addCookie

public void addCookie(java.lang.String theName,
                      java.lang.String theValue)
Adds a cookie to the request.
Parameters:
theName - the cookie's name
theValue - the cookie's value

getCookieNames

public java.util.Enumeration getCookieNames()
Returns:
the cookie names

getCookieValue

public java.lang.String getCookieValue(java.lang.String theName)
Parameters:
theName - the cookie's name
Returns:
the value corresponding to this cookie's name or null if not found

addHeader

public void addHeader(java.lang.String theName,
                      java.lang.String theValue)
Adds a header to the request. Supports adding several values for the same header name.
Parameters:
theName - the header's name
theValue - the header's value

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns:
the header names

getHeader

public java.lang.String getHeader(java.lang.String theName)
Returns the first value corresponding to this header's name.
Parameters:
theName - the header's name
Returns:
the first value corresponding to this header's name or null if not found

getHeaderValues

public java.lang.String[] getHeaderValues(java.lang.String theName)
Returns all the values associated with this header's name.
Parameters:
theName - the header's name
Returns:
the values corresponding to this header's name or null if not found


Copyright © 2000-2001 Apache Software Foundation. All Rights Reserved.