Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mortbay.jetty.testing
Class ServletTester

    java.lang.Object
      org.mortbay.jetty.testing.ServletTester

    public class ServletTester

extends Object

Testing support for servlets and filters. Allows a programatic setup of a context with servlets and filters for testing. Raw HTTP requests may be sent to the context and responses received. To avoid handling raw HTTP see `HttpTester`.

          ServletTester tester=new ServletTester();
          tester.setContextPath("/context");
          tester.addServlet(TestServlet.class, "/servlet/*");
          tester.addServlet("org.mortbay.jetty.servlet.DefaultServlet", "/");
          tester.start();
          String response = tester.getResponses("GET /context/servlet/info HTTP/1.0\r\n\r\n");

Author:
  gregw
See Also:
  `HttpTester`

Constructor Summary
`ServletTester()`

Method Summary
`void` | `addEventListener(EventListener listener)`
`FilterHolder` | `addFilter(Class filterClass, String pathSpec, int dispatches)`
`FilterHolder` | `addFilter(String filterClass, String pathSpec, int dispatches)`
`ServletHolder` | `addServlet(Class servlet, String pathSpec)`
`ServletHolder` | `addServlet(String className, String pathSpec)`
`LocalConnector` | `createLocalConnector()` Create a Socket connector.
`String` | `createSocketConnector(boolean localhost)` Create a Socket connector.
`Object` | `getAttribute(String name)`
`Enumeration` | `getAttributeNames()`
`Attributes` | `getAttributes()`
`Context` | `getContext()`
`String` | `getResourceBase()`
`ByteArrayBuffer` | `getResponses(ByteArrayBuffer rawRequests)` Get raw HTTP responses from raw HTTP requests.
`ByteArrayBuffer` | `getResponses(ByteArrayBuffer rawRequests, LocalConnector connector)` Get raw HTTP responses from raw HTTP requests.
`String` | `getResponses(String rawRequests)` Get raw HTTP responses from raw HTTP requests.
`String` | `getResponses(String rawRequests, LocalConnector connector)` Get raw HTTP responses from raw HTTP requests.
`void` | `setAttribute(String name, Object value)`
`void` | `setClassLoader(ClassLoader classLoader)`
`void` | `setContextPath(String contextPath)`
`void` | `setEventListeners(EventListener[] eventListeners)`
`void` | `setResourceBase(String resourceBase)`
`void` | `start()`
`void` | `stop()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ServletTester

    public ServletTester()

Method Detail

### start

    public void start()
               throws Exception

  Throws:
    `Exception`

### stop

    public void stop()
              throws Exception

  Throws:
    `Exception`

### getContext

    public Context getContext()

### getResponses

    public String getResponses(String rawRequests)
                        throws Exception

  Get raw HTTP responses from raw HTTP requests. Multiple requests and responses may be handled, but only if persistent connections conditions apply.

  Parameters:
    `rawRequests` - String of raw HTTP requests
  Returns:
    String of raw HTTP responses
  Throws:
    `Exception`

### getResponses

    public String getResponses(String rawRequests,
                               LocalConnector connector)
                        throws Exception

  Get raw HTTP responses from raw HTTP requests. Multiple requests and responses may be handled, but only if persistent connections conditions apply.

  Parameters:
    `rawRequests` - String of raw HTTP requests
    `connector` - The connector to handle the responses
  Returns:
    String of raw HTTP responses
  Throws:
    `Exception`

### getResponses

    public ByteArrayBuffer getResponses(ByteArrayBuffer rawRequests)
                                 throws Exception

  Get raw HTTP responses from raw HTTP requests. Multiple requests and responses may be handled, but only if persistent connections conditions apply.

  Parameters:
    `rawRequests` - String of raw HTTP requests
  Returns:
    String of raw HTTP responses
  Throws:
    `Exception`

### getResponses

    public ByteArrayBuffer getResponses(ByteArrayBuffer rawRequests,
                                        LocalConnector connector)
                                 throws Exception

  Get raw HTTP responses from raw HTTP requests. Multiple requests and responses may be handled, but only if persistent connections conditions apply.

  Parameters:
    `rawRequests` - String of raw HTTP requests
    `connector` - The connector to handle the responses
  Returns:
    String of raw HTTP responses
  Throws:
    `Exception`

### createSocketConnector

    public String createSocketConnector(boolean localhost)
                                 throws Exception

  Create a Socket connector. This methods adds a socket connector to the server

  Parameters:
    `locahost` - if true, only listen on local host, else listen on all interfaces.
  Returns:
    A URL to access the server via the socket connector.
  Throws:
    `Exception`

### createLocalConnector

    public LocalConnector createLocalConnector()
                                        throws Exception

  Create a Socket connector. This methods adds a socket connector to the server

  Parameters:
    `locahost` - if true, only listen on local host, else listen on all interfaces.
  Returns:
    A URL to access the server via the socket connector.
  Throws:
    `Exception`

### addEventListener

    public void addEventListener(EventListener listener)

  Parameters:
    `listener` -
  See Also:
    `ContextHandler.addEventListener(java.util.EventListener)`

### addFilter

    public FilterHolder addFilter(Class filterClass,
                                  String pathSpec,
                                  int dispatches)

  Parameters:
    `filterClass` -
    `pathSpec` -
    `dispatches` -
  Returns:
  See Also:
    `Context.addFilter(java.lang.Class, java.lang.String, int)`

### addFilter

    public FilterHolder addFilter(String filterClass,
                                  String pathSpec,
                                  int dispatches)

  Parameters:
    `filterClass` -
    `pathSpec` -
    `dispatches` -
  Returns:
  See Also:
    `Context.addFilter(java.lang.String, java.lang.String, int)`

### addServlet

    public ServletHolder addServlet(Class servlet,
                                    String pathSpec)

  Parameters:
    `servlet` -
    `pathSpec` -
  Returns:
  See Also:
    `Context.addServlet(java.lang.Class, java.lang.String)`

### addServlet

    public ServletHolder addServlet(String className,
                                    String pathSpec)

  Parameters:
    `className` -
    `pathSpec` -
  Returns:
  See Also:
    `Context.addServlet(java.lang.String, java.lang.String)`

### getAttribute

    public Object getAttribute(String name)

  Parameters:
    `name` -
  Returns:
  See Also:
    `ContextHandler.getAttribute(java.lang.String)`

### getAttributeNames

    public Enumeration getAttributeNames()

  Returns:
  See Also:
    `ContextHandler.getAttributeNames()`

### getAttributes

    public Attributes getAttributes()

  Returns:
  See Also:
    `ContextHandler.getAttributes()`

### getResourceBase

    public String getResourceBase()

  Returns:
  See Also:
    `ContextHandler.getResourceBase()`

### setAttribute

    public void setAttribute(String name,
                             Object value)

  Parameters:
    `name` -
    `value` -
  See Also:
    `ContextHandler.setAttribute(java.lang.String, java.lang.Object)`

### setClassLoader

    public void setClassLoader(ClassLoader classLoader)

  Parameters:
    `classLoader` -
  See Also:
    `ContextHandler.setClassLoader(java.lang.ClassLoader)`

### setContextPath

    public void setContextPath(String contextPath)

  Parameters:
    `contextPath` -
  See Also:
    `ContextHandler.setContextPath(java.lang.String)`

### setEventListeners

    public void setEventListeners(EventListener[] eventListeners)

  Parameters:
    `eventListeners` -
  See Also:
    `ContextHandler.setEventListeners(java.util.EventListener[])`

### setResourceBase

    public void setResourceBase(String resourceBase)

  Parameters:
    `resourceBase` -
  See Also:
    `ContextHandler.setResourceBase(java.lang.String)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2008 Mort Bay Consulting. All Rights Reserved.