Package net.officefloor.server.http.mock
Class MockHttpServer
- java.lang.Object
-
- net.officefloor.server.http.mock.MockHttpServer
-
- All Implemented Interfaces:
HttpServerImplementation,HttpServerLocation
- Direct Known Subclasses:
MockWoofServer
public class MockHttpServer extends java.lang.Object implements HttpServerLocation, HttpServerImplementation
MockHttpServer.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceMockHttpServer.MockHttpRequestHTTP request details for theMockHttpResponse.protected static classMockHttpServer.MockHttpResponseImplMockHttpResponseimplementation.static classMockHttpServer.MockServerHttpConnectionImplMockServerHttpConnectionimplementation.
-
Field Summary
-
Fields inherited from interface net.officefloor.server.http.HttpServerLocation
PROPERTY_CLUSTER_HOST_NAME, PROPERTY_CLUSTER_HTTP_PORT, PROPERTY_CLUSTER_HTTPS_PORT, PROPERTY_DOMAIN, PROPERTY_HTTP_PORT, PROPERTY_HTTPS_PORT
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMockHttpServer()Instantiated via static methods or extending.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureHttpServer(HttpServerImplementationContext context)Configures theHttpServer.static MockHttpServerconfigureMockHttpServer(DeployedOfficeInput input)Configures theMockHttpServerto be serviced by theDeployedOfficeInput.protected static voidconfigureMockHttpServer(MockHttpServer httpServer, DeployedOfficeInput input)Enables extending implementations to configure themselves as theMockHttpServer.java.lang.StringcreateClientUrl(boolean isSecure, java.lang.String path)Creates the client URL to call theHttpServer.protected MockHttpResponsecreateMockHttpResponse(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)Creates theMockHttpResponse.protected MockHttpResponsecreateMockHttpResponse(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, java.util.List<WritableHttpHeader> headers, java.util.List<WritableHttpCookie> cookies, java.io.InputStream entityInputStream)Creates theMockHttpResponse.java.lang.StringgetClusterHostName()Obtains the name of the host for the server within the cluster.intgetClusterHttpPort()The cluster may be behind a load balancer and the server may be running on a different port than expected by the client.intgetClusterHttpsPort()The cluster may be behind a load balancer and the server may be running on a different port than expected by the client.java.lang.StringgetDomain()Obtains the domain for the server.intgetHttpPort()Obtains the HTTP port.intgetHttpsPort()Obtains the HTTPS port.static MockServerHttpConnectionmockConnection()Convenience method to create theMockServerHttpConnectionfor GET / with no headers nor entity.static MockServerHttpConnectionmockConnection(MockHttpRequestBuilder request)Creates theMockServerHttpConnection.static MockHttpRequestBuildermockRequest()Creates theMockHttpRequestBuilder.static MockHttpRequestBuildermockRequest(java.lang.String requestUri)Convenience method to create aMockHttpRequestBuilder.static MockHttpResponseBuildermockResponse()Creates theMockHttpRequestBuilder.static WritableHttpCookiemockResponseCookie(java.lang.String name, java.lang.String value)Creates a mockHttpResponseCookie.MockHttpResponsesend(MockHttpRequestBuilder request)Sends theMockHttpRequestBuilderand blocks waiting for theMockHttpResponse.voidsend(MockHttpRequestBuilder request, MockHttpRequestCallback callback)Sends theMockHttpRequestBuilder.MockHttpResponsesendFollowRedirect(MockHttpRequestBuilder request)Sends theMockHttpRequestBuilderand blocks following the redirect.MockHttpServertimeout(int timeout)Specifies the timeout for synchronous send.
-
-
-
Method Detail
-
configureMockHttpServer
public static MockHttpServer configureMockHttpServer(DeployedOfficeInput input) throws java.lang.Exception
Configures theMockHttpServerto be serviced by theDeployedOfficeInput.- Parameters:
input-DeployedOfficeInput.- Returns:
MockHttpServerto sendHttpRequestinstances.- Throws:
java.lang.Exception- If fails to configureMockHttpServer.
-
configureMockHttpServer
protected static void configureMockHttpServer(MockHttpServer httpServer, DeployedOfficeInput input) throws java.lang.Exception
Enables extending implementations to configure themselves as theMockHttpServer.- Parameters:
httpServer-MockHttpServer.input-DeployedOfficeInput.- Throws:
java.lang.Exception- If fails to configureMockHttpServer.
-
mockRequest
public static MockHttpRequestBuilder mockRequest()
Creates theMockHttpRequestBuilder.- Returns:
MockHttpRequestBuilder.
-
mockRequest
public static MockHttpRequestBuilder mockRequest(java.lang.String requestUri)
Convenience method to create aMockHttpRequestBuilder.- Parameters:
requestUri- Request URI.- Returns:
MockHttpRequestBuilder.
-
mockResponse
public static MockHttpResponseBuilder mockResponse()
Creates theMockHttpRequestBuilder.- Returns:
MockHttpRequestBuilder.
-
mockResponseCookie
public static WritableHttpCookie mockResponseCookie(java.lang.String name, java.lang.String value)
Creates a mockHttpResponseCookie.- Parameters:
name- Name.value- value.- Returns:
HttpResponseCookie.
-
mockConnection
public static MockServerHttpConnection mockConnection()
Convenience method to create theMockServerHttpConnectionfor GET / with no headers nor entity.- Returns:
MockServerHttpConnection.
-
mockConnection
public static MockServerHttpConnection mockConnection(MockHttpRequestBuilder request)
Creates theMockServerHttpConnection.- Parameters:
request-MockHttpRequestBuilderfor theHttpRequestof theMockServerHttpConnection.- Returns:
MockServerHttpConnection.
-
timeout
public MockHttpServer timeout(int timeout)
Specifies the timeout for synchronous send.- Parameters:
timeout- Timeout in milliseconds.- Returns:
this.
-
send
public void send(MockHttpRequestBuilder request, MockHttpRequestCallback callback)
Sends theMockHttpRequestBuilder.- Parameters:
request-MockHttpRequestBuilder.callback-MockHttpRequestCallbackto receive theMockHttpResponse.
-
send
public MockHttpResponse send(MockHttpRequestBuilder request)
Sends theMockHttpRequestBuilderand blocks waiting for theMockHttpResponse.- Parameters:
request-MockHttpRequestBuilder.- Returns:
MockHttpResponse.
-
sendFollowRedirect
public MockHttpResponse sendFollowRedirect(MockHttpRequestBuilder request)
Sends theMockHttpRequestBuilderand blocks following the redirect.- Parameters:
request-MockHttpRequestBuilder.- Returns:
- Redirect
MockHttpResponse.
-
createMockHttpResponse
protected MockHttpResponse createMockHttpResponse(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, java.util.List<WritableHttpHeader> headers, java.util.List<WritableHttpCookie> cookies, java.io.InputStream entityInputStream)
Creates theMockHttpResponse.- Parameters:
request-MockHttpServer.MockHttpRequest.version-HttpVersion.status-HttpStatus.headers-WritableHttpHeaderinstances.cookies-WritableHttpCookieinstances.entityInputStream- Entity.- Returns:
MockHttpResponse.
-
createMockHttpResponse
protected MockHttpResponse createMockHttpResponse(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Creates theMockHttpResponse.- Parameters:
request-MockHttpServer.MockHttpRequest.failure- Failure in servicing.- Returns:
MockHttpResponse.
-
getDomain
public java.lang.String getDomain()
Description copied from interface:HttpServerLocationObtains the domain for the server.
This is as the client will see the server.
- Specified by:
getDomainin interfaceHttpServerLocation- Returns:
- Domain for the server.
-
getHttpPort
public int getHttpPort()
Description copied from interface:HttpServerLocationObtains the HTTP port.
This is as the client will see the server.
- Specified by:
getHttpPortin interfaceHttpServerLocation- Returns:
- HTTP port.
-
getHttpsPort
public int getHttpsPort()
Description copied from interface:HttpServerLocationObtains the HTTPS port.
This is as the client will see the server.
- Specified by:
getHttpsPortin interfaceHttpServerLocation- Returns:
- HTTPS port.
-
getClusterHostName
public java.lang.String getClusterHostName()
Description copied from interface:HttpServerLocationObtains the name of the host for the server within the cluster. This name should be understood by all nodes within the cluster.- Specified by:
getClusterHostNamein interfaceHttpServerLocation- Returns:
- Name of the host within the cluster.
-
getClusterHttpPort
public int getClusterHttpPort()
Description copied from interface:HttpServerLocationThe cluster may be behind a load balancer and the server may be running on a different port than expected by the client.- Specified by:
getClusterHttpPortin interfaceHttpServerLocation- Returns:
- Actual port on the cluster host the server is running on.
-
getClusterHttpsPort
public int getClusterHttpsPort()
Description copied from interface:HttpServerLocationThe cluster may be behind a load balancer and the server may be running on a different port than expected by the client.- Specified by:
getClusterHttpsPortin interfaceHttpServerLocation- Returns:
- Actual secure port on the cluster host the server is running on.
-
createClientUrl
public java.lang.String createClientUrl(boolean isSecure, java.lang.String path)Description copied from interface:HttpServerLocationCreates the client URL to call theHttpServer.- Specified by:
createClientUrlin interfaceHttpServerLocation- Parameters:
isSecure- If secure URL.path- Path including query string and fragment.- Returns:
- URL for the client to call on the
HttpServer.
-
configureHttpServer
public void configureHttpServer(HttpServerImplementationContext context)
Description copied from interface:HttpServerImplementationConfigures theHttpServer.- Specified by:
configureHttpServerin interfaceHttpServerImplementation- Parameters:
context-HttpServerImplementationContext.
-
-