Package org.eclipse.jgit.junit.http
Class AppServer
java.lang.Object
org.eclipse.jgit.junit.http.AppServer
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
Role for authentication.private final org.eclipse.jetty.server.HttpConfiguration
private final org.eclipse.jetty.server.ServerConnector
private final org.eclipse.jetty.server.handler.ContextHandlerCollection
private static final String
SSL keystore password; must have at least 6 characters.private final TestRequestLog
static final String
Password forusername
in secured access areas.static final String
Realm name for the secure access areas.private final org.eclipse.jetty.server.HttpConfiguration
private final org.eclipse.jetty.server.ServerConnector
private final org.eclipse.jetty.server.Server
static final String
Username for secured access areas. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.eclipse.jetty.servlet.ServletContextHandler
addContext
(String path) Create a new servlet context within the server.private void
private void
private void
auth
(org.eclipse.jetty.servlet.ServletContextHandler ctx, org.eclipse.jetty.security.Authenticator authType, String... methods) org.eclipse.jetty.servlet.ServletContextHandler
Configure basic authentication.private org.eclipse.jetty.security.ConstraintMapping
private org.eclipse.jetty.util.ssl.SslContextFactory
createTestSslContextFactory
(String hostName) int
getPort()
Get port.Get requests.getRequests
(String path) Get requests.getRequests
(URIish base, String path) Get requests.int
Get secure port.getURI()
Get the URI to reference this server.private void
makePrivate
(File file) void
setUp()
Start the server on a random local port.void
tearDown()
Shutdown the server.
-
Field Details
-
realm
Realm name for the secure access areas.- See Also:
-
username
Username for secured access areas.- See Also:
-
password
Password forusername
in secured access areas.- See Also:
-
keyPassword
SSL keystore password; must have at least 6 characters.- See Also:
-
authRole
Role for authentication.- See Also:
-
server
private final org.eclipse.jetty.server.Server server -
config
private final org.eclipse.jetty.server.HttpConfiguration config -
connector
private final org.eclipse.jetty.server.ServerConnector connector -
secureConfig
private final org.eclipse.jetty.server.HttpConfiguration secureConfig -
secureConnector
private final org.eclipse.jetty.server.ServerConnector secureConnector -
contexts
private final org.eclipse.jetty.server.handler.ContextHandlerCollection contexts -
log
-
filesToDelete
-
-
Constructor Details
-
AppServer
public AppServer()Constructor forAppServer
. -
AppServer
public AppServer(int port) Constructor forAppServer
.- Parameters:
port
- the http port number; may be zero to allocate a port dynamically- Since:
- 4.2
-
AppServer
public AppServer(int port, int sslPort) Constructor forAppServer
.- Parameters:
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.- Since:
- 4.9
-
-
Method Details
-
createTestSslContextFactory
-
makePrivate
-
addContext
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, String... methods) Configure basic authentication.- Parameters:
ctx
-methods
-- Returns:
- servlet context handler
-
createConstraintMapping
private org.eclipse.jetty.security.ConstraintMapping createConstraintMapping() -
auth
private void auth(org.eclipse.jetty.servlet.ServletContextHandler ctx, org.eclipse.jetty.security.Authenticator authType, String... methods) -
setUp
Start the server on a random local port.- Throws:
Exception
- the server cannot be started, testing is not possible.
-
tearDown
Shutdown the server.- Throws:
Exception
- the server refuses to halt, or wasn't running.
-
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()Get port.- Returns:
- the local port number the server is listening on.
-
getSecurePort
public int getSecurePort()Get secure port.- Returns:
- the HTTPS port or -1 if not configured.
-
getRequests
Get requests.- Returns:
- all requests since the server was started.
-
getRequests
Get requests.- Parameters:
base
- base URI used to access the server.path
- the path to locate requests for, relative tobase
.- Returns:
- all requests which match the given path.
-
getRequests
Get requests.- Parameters:
path
- the path to locate requests for.- Returns:
- all requests which match the given path.
-
assertNotYetSetUp
private void assertNotYetSetUp() -
assertAlreadySetUp
private void assertAlreadySetUp()
-