com.meterware.servletunit
Class ServletUnitClient

java.lang.Object
  |
  +--com.meterware.httpunit.WebClient
        |
        +--com.meterware.servletunit.ServletUnitClient
All Implemented Interfaces:
FrameHolder

public class ServletUnitClient
extends WebClient

A client for use with the servlet runner class, allowing the testing of servlets without an actual servlet container. Testing can be done in one of two ways. End-to-end testing works much like the HttpUnit package, except that only servlets actually registered with the ServletRunner will be invoked. It is also possible to test servlets 'from the inside' by creating a ServletInvocationContext and then calling any servlet methods which may be desired. Even in this latter mode, end-to-end testing is supported, but requires a call to this class's getResponse method to update its cookies and frames.


Inner classes inherited from class com.meterware.httpunit.WebClient
WebClient.HeaderDictionary
 
Method Summary
 WebResponse getResponse(InvocationContext invocation)
          Updates this client and returns the response which would be displayed by the user agent.
static ServletUnitClient newClient(InvocationContextFactory factory)
          Creates and returns a new servlet unit client instance.
 InvocationContext newInvocation(String requestString)
          Creates and returns a new invocation context from a GET request.
 InvocationContext newInvocation(WebRequest request)
          Creates and returns a new invocation context to test calling of servlet methods.
protected  WebResponse newResponse(WebRequest request)
          Creates a web response object which represents the response to the specified web request.
 
Methods inherited from class com.meterware.httpunit.WebClient
addClientListener, addCookie, clearContents, getCookieHeaderField, getCookieNames, getCookieValue, getExceptionsThrownOnErrorStatus, getFrameContents, getFrameNames, getHeaderField, getHeaderFields, getResponse, getResponse, getUserAgent, removeClientListener, sendRequest, setAuthorization, setExceptionsThrownOnErrorStatus, setHeaderField, setUserAgent, updateClient, writeMessageBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newClient

public static ServletUnitClient newClient(InvocationContextFactory factory)
Creates and returns a new servlet unit client instance.

newInvocation

public InvocationContext newInvocation(String requestString)
                                throws IOException,
                                       MalformedURLException
Creates and returns a new invocation context from a GET request.

newInvocation

public InvocationContext newInvocation(WebRequest request)
                                throws IOException,
                                       MalformedURLException
Creates and returns a new invocation context to test calling of servlet methods.

getResponse

public WebResponse getResponse(InvocationContext invocation)
                        throws MalformedURLException,
                               IOException,
                               SAXException
Updates this client and returns the response which would be displayed by the user agent. Note that this will typically be the same as that returned by the servlet invocation unless that invocation results in a redirect request.

newResponse

protected WebResponse newResponse(WebRequest request)
                           throws MalformedURLException,
                                  IOException
Creates a web response object which represents the response to the specified web request.
Overrides:
newResponse in class WebClient