public class AppServer
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AppServer.TestMappedLoginService |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
authRole
Role for authentication.
|
private org.eclipse.jetty.server.HttpConfiguration |
config |
private org.eclipse.jetty.server.ServerConnector |
connector |
private org.eclipse.jetty.server.handler.ContextHandlerCollection |
contexts |
private java.util.List<java.io.File> |
filesToDelete |
private static java.lang.String |
keyPassword
SSL keystore password; must have at least 6 characters.
|
private TestRequestLog |
log |
static java.lang.String |
password
Password for
username in secured access areas. |
static java.lang.String |
realm
Realm name for the secure access areas.
|
private org.eclipse.jetty.server.HttpConfiguration |
secureConfig |
private org.eclipse.jetty.server.ServerConnector |
secureConnector |
private org.eclipse.jetty.server.Server |
server |
static java.lang.String |
username
Username for secured access areas.
|
Constructor and Description |
---|
AppServer()
Constructor for
AppServer . |
AppServer(int port)
Constructor for
AppServer . |
AppServer(int port,
int sslPort)
Constructor for
AppServer . |
Modifier and Type | Method and Description |
---|---|
org.eclipse.jetty.servlet.ServletContextHandler |
addContext(java.lang.String path)
Create a new servlet context within the server.
|
private void |
assertAlreadySetUp() |
private void |
assertNotYetSetUp() |
private void |
auth(org.eclipse.jetty.servlet.ServletContextHandler ctx,
org.eclipse.jetty.security.Authenticator authType,
java.lang.String... methods) |
org.eclipse.jetty.servlet.ServletContextHandler |
authBasic(org.eclipse.jetty.servlet.ServletContextHandler ctx,
java.lang.String... methods)
Configure basic authentication.
|
private org.eclipse.jetty.security.ConstraintMapping |
createConstraintMapping() |
private org.eclipse.jetty.util.ssl.SslContextFactory |
createTestSslContextFactory(java.lang.String hostName) |
int |
getPort()
Get port.
|
java.util.List<AccessEvent> |
getRequests()
Get requests.
|
java.util.List<AccessEvent> |
getRequests(java.lang.String path)
Get requests.
|
java.util.List<AccessEvent> |
getRequests(URIish base,
java.lang.String path)
Get requests.
|
int |
getSecurePort()
Get secure port.
|
java.net.URI |
getURI()
Get the URI to reference this server.
|
private void |
makePrivate(java.io.File file) |
void |
setUp()
Start the server on a random local port.
|
void |
tearDown()
Shutdown the server.
|
public static final java.lang.String realm
public static final java.lang.String username
public static final java.lang.String password
username
in secured access areas.private static final java.lang.String keyPassword
private static final java.lang.String authRole
private final org.eclipse.jetty.server.Server server
private final org.eclipse.jetty.server.HttpConfiguration config
private final org.eclipse.jetty.server.ServerConnector connector
private final org.eclipse.jetty.server.HttpConfiguration secureConfig
private final org.eclipse.jetty.server.ServerConnector secureConnector
private final org.eclipse.jetty.server.handler.ContextHandlerCollection contexts
private final TestRequestLog log
private java.util.List<java.io.File> filesToDelete
public AppServer()
AppServer
.public AppServer(int port)
AppServer
.port
- the http port number; may be zero to allocate a port
dynamicallypublic AppServer(int port, int sslPort)
AppServer
.port
- for http, may be zero to allocate a port dynamicallysslPort
- for https,may be zero to allocate a port dynamically. If
negative, the server will be set up without https support.private org.eclipse.jetty.util.ssl.SslContextFactory createTestSslContextFactory(java.lang.String hostName)
private void makePrivate(java.io.File file)
public org.eclipse.jetty.servlet.ServletContextHandler addContext(java.lang.String path)
This method should be invoked before the server is started, once for each context the caller wants to register.
path
- path of the context; use "/" for the root context if binding
to the root is desired.public org.eclipse.jetty.servlet.ServletContextHandler authBasic(org.eclipse.jetty.servlet.ServletContextHandler ctx, java.lang.String... methods)
ctx
- methods
- private org.eclipse.jetty.security.ConstraintMapping createConstraintMapping()
private void auth(org.eclipse.jetty.servlet.ServletContextHandler ctx, org.eclipse.jetty.security.Authenticator authType, java.lang.String... methods)
public void setUp() throws java.lang.Exception
java.lang.Exception
- the server cannot be started, testing is not possible.public void tearDown() throws java.lang.Exception
java.lang.Exception
- the server refuses to halt, or wasn't running.public java.net.URI getURI()
The returned URI includes the proper host name and port number, but does not contain a path.
public int getPort()
public int getSecurePort()
public java.util.List<AccessEvent> getRequests()
public java.util.List<AccessEvent> getRequests(URIish base, java.lang.String path)
base
- base URI used to access the server.path
- the path to locate requests for, relative to base
.public java.util.List<AccessEvent> getRequests(java.lang.String path)
path
- the path to locate requests for.private void assertNotYetSetUp()
private void assertAlreadySetUp()