com.meterware.servletunit

Class ServletRunner

public class ServletRunner extends Object

This class acts as a test environment for servlets.

Author: Russell Gold

Nested Class Summary
static classServletRunner.JasperJSPServletDescriptor
Field Summary
static JSPServletDescriptorJASPER_DESCRIPTOR
Constructor Summary
ServletRunner()
Default constructor, which defines no servlets.
ServletRunner(String webXMLFileSpec)
Constructor which expects the full path to the web.xml for the application.
ServletRunner(String webXMLFileSpec, String contextPath)
Constructor which expects the full path to the web.xml for the application and a context path under which to mount it.
ServletRunner(File webXml)
Constructor which expects a File object representing the web.xml for the application.
ServletRunner(File webXml, String contextPath)
Constructor which expects a File object representing the web.xml for the application and a context path under which to mount it.
ServletRunner(InputStream webXML)
Constructor which expects an input stream containing the web.xml for the application.
ServletRunner(InputStream webXML, String contextPath)
Constructor which expects an input stream containing the web.xml for the application.
Method Summary
StringgetContextParameter(String name)
Returns the value of the named context parameter found in the application definition.
WebResponsegetResponse(WebRequest request)
Returns the response from the specified servlet.
WebResponsegetResponse(String url)
Returns the response from the specified servlet using GET.
HttpSessiongetSession(boolean create)
Returns the session to be used by the next request.
ServletUnitClientnewClient()
Creates and returns a new web client that communicates with this servlet runner.
voidregisterServlet(String resourceName, String servletClassName)
Registers a servlet class to be run.
voidregisterServlet(String resourceName, String servletClassName, Hashtable initParameters)
Registers a servlet class to be run, specifying initialization parameters.
voidshutDown()
Shuts down the servlet container, returning any resources held by it.

Field Detail

JASPER_DESCRIPTOR

public static final JSPServletDescriptor JASPER_DESCRIPTOR

Constructor Detail

ServletRunner

public ServletRunner()
Default constructor, which defines no servlets.

ServletRunner

public ServletRunner(String webXMLFileSpec)

Deprecated: as of 1.6, use ServletRunner

Constructor which expects the full path to the web.xml for the application.

Parameters: webXMLFileSpec the full path to the web.xml file

ServletRunner

public ServletRunner(String webXMLFileSpec, String contextPath)

Deprecated: as of 1.6, use ServletRunner

Constructor which expects the full path to the web.xml for the application and a context path under which to mount it.

Parameters: webXMLFileSpec the full path to the web.xml file contextPath the context path

ServletRunner

public ServletRunner(File webXml)
Constructor which expects a File object representing the web.xml for the application.

Parameters: webXml the web.xml file

Since: 1.6

ServletRunner

public ServletRunner(File webXml, String contextPath)
Constructor which expects a File object representing the web.xml for the application and a context path under which to mount it.

Parameters: webXml the web.xml file contextPath the context path

Since: 1.6

ServletRunner

public ServletRunner(InputStream webXML)
Constructor which expects an input stream containing the web.xml for the application.

ServletRunner

public ServletRunner(InputStream webXML, String contextPath)
Constructor which expects an input stream containing the web.xml for the application.

Method Detail

getContextParameter

public String getContextParameter(String name)
Returns the value of the named context parameter found in the application definition.

getResponse

public WebResponse getResponse(WebRequest request)
Returns the response from the specified servlet.

Throws: SAXException thrown if there is an error parsing the response

getResponse

public WebResponse getResponse(String url)
Returns the response from the specified servlet using GET.

Throws: SAXException thrown if there is an error parsing the response

getSession

public HttpSession getSession(boolean create)
Returns the session to be used by the next request.

Parameters: create if true, will create a new session if no valid session is defined.

Since: 1.6

newClient

public ServletUnitClient newClient()
Creates and returns a new web client that communicates with this servlet runner.

registerServlet

public void registerServlet(String resourceName, String servletClassName)
Registers a servlet class to be run.

registerServlet

public void registerServlet(String resourceName, String servletClassName, Hashtable initParameters)
Registers a servlet class to be run, specifying initialization parameters.

shutDown

public void shutDown()
Shuts down the servlet container, returning any resources held by it. Calls the destroy method of each active servlet, then notifies ContextListeners of server shutdown.