org.eclipse.jgit.junit.http
Class AppServer

java.lang.Object
  extended by org.eclipse.jgit.junit.http.AppServer

public class AppServer
extends java.lang.Object

Tiny web application server for unit testing.

Tests should start the server in their setUp() method and stop the server in their tearDown() method. Only while started the server's URL and/or port number can be obtained.


Field Summary
static java.lang.String password
          Password for username in secured access areas.
static java.lang.String realm
          Realm name for the secure access areas.
static java.lang.String username
          Username for secured access areas.
 
Constructor Summary
AppServer()
           
 
Method Summary
 org.eclipse.jetty.servlet.ServletContextHandler addContext(java.lang.String path)
          Create a new servlet context within the server.
 org.eclipse.jetty.servlet.ServletContextHandler authBasic(org.eclipse.jetty.servlet.ServletContextHandler ctx)
           
 int getPort()
           
 java.util.List<AccessEvent> getRequests()
           
 java.util.List<AccessEvent> getRequests(java.lang.String path)
           
 java.util.List<AccessEvent> getRequests(URIish base, java.lang.String path)
           
 java.net.URI getURI()
          Get the URI to reference this server.
 void setUp()
          Start the server on a random local port.
 void tearDown()
          Shutdown the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

realm

public static final java.lang.String realm
Realm name for the secure access areas.

See Also:
Constant Field Values

username

public static final java.lang.String username
Username for secured access areas.

See Also:
Constant Field Values

password

public static final java.lang.String password
Password for username in secured access areas.

See Also:
Constant Field Values
Constructor Detail

AppServer

public AppServer()
Method Detail

addContext

public org.eclipse.jetty.servlet.ServletContextHandler addContext(java.lang.String path)
Create a new servlet context within the server.

This method should be invoked before the server is started, once for each context the caller wants to register.

Parameters:
path - path of the context; use "/" for the root context if binding to the root is desired.
Returns:
the context to add servlets into.

authBasic

public org.eclipse.jetty.servlet.ServletContextHandler authBasic(org.eclipse.jetty.servlet.ServletContextHandler ctx)

setUp

public void setUp()
           throws java.lang.Exception
Start the server on a random local port.

Throws:
java.lang.Exception - the server cannot be started, testing is not possible.

tearDown

public void tearDown()
              throws java.lang.Exception
Shutdown the server.

Throws:
java.lang.Exception - the server refuses to halt, or wasn't running.

getURI

public java.net.URI getURI()
Get the URI to reference this server.

The returned URI includes the proper host name and port number, but does not contain a path.

Returns:
URI to reference this server's root context.

getPort

public int getPort()
Returns:
the local port number the server is listening on.

getRequests

public java.util.List<AccessEvent> getRequests()
Returns:
all requests since the server was started.

getRequests

public java.util.List<AccessEvent> getRequests(URIish base,
                                               java.lang.String path)
Parameters:
base - base URI used to access the server.
path - the path to locate requests for, relative to base.
Returns:
all requests which match the given path.

getRequests

public java.util.List<AccessEvent> getRequests(java.lang.String path)
Parameters:
path - the path to locate requests for.
Returns:
all requests which match the given path.


Copyright © 2011. All Rights Reserved.