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
Mock
HttpServer.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceHTTP request details for theMockHttpResponse.protected static classMockHttpResponseimplementation.static classMockServerHttpConnectionimplementation. -
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
ConstructorsModifierConstructorDescriptionprotectedInstantiated via static methods or extending. -
Method Summary
Modifier and TypeMethodDescriptionvoidConfigures theHttpServer.static MockHttpServerConfigures theMockHttpServerto be serviced by theDeployedOfficeInput.static MockHttpServerconfigureMockHttpServer(DeployedOfficeInput input, String typeQualifier) Configures theMockHttpServerto be serviced by theDeployedOfficeInput.protected static voidconfigureMockHttpServer(MockHttpServer httpServer, String typeQualifier, DeployedOfficeInput input) Enables extending implementations to configure themselves as theMockHttpServer.createClientUrl(boolean isSecure, String path) Creates the client URL to call theHttpServer.protected MockHttpResponsecreateMockHttpResponse(MockHttpServer.MockHttpRequest request, Throwable failure) Creates theMockHttpResponse.protected MockHttpResponsecreateMockHttpResponse(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, List<WritableHttpHeader> headers, List<WritableHttpCookie> cookies, InputStream entityInputStream) Creates theMockHttpResponse.direct(MockHttpRequestBuilder request, ExternalServiceInput<ServerHttpConnection, ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> externalServiceInput) Undertakes direct invocation of servicing theMockHttpRequestBuilder.voiddirect(MockHttpRequestBuilder request, ExternalServiceInput<ServerHttpConnection, ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> externalServiceInput, MockHttpRequestCallback callback) Triggers direct handling ofMockHttpRequestBuilder.Obtains the name of the host for the server within the cluster.intThe cluster may be behind a load balancer and the server may be running on a different port than expected by the client.intThe cluster may be behind a load balancer and the server may be running on a different port than expected by the client.Obtains the domain for the server.static ExternalServiceInput<ServerHttpConnection,ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> Convenience method to extractExternalServiceInputfromOfficeSectionInput.static ExternalServiceInput<ServerHttpConnection,ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> Convenience method to extractExternalServiceInputfromDeployedOfficeInput.intObtains the HTTP port.intObtains the HTTPS port.static MockServerHttpConnectionConvenience method to create theMockServerHttpConnectionfor GET / with no headers nor entity.static MockServerHttpConnectionmockConnection(MockHttpRequestBuilder request) Creates theMockServerHttpConnection.static MockHttpRequestBuildermockJsonRequest(Object jsonObject) CreateMockHttpRequestBuilderfor JSON payload.static MockHttpRequestBuildermockJsonRequest(HttpMethod method, String requestUri, Object jsonObject) CreateMockHttpRequestBuilderfor JSON payload.static MockHttpRequestBuilderCreates theMockHttpRequestBuilder.static MockHttpRequestBuildermockRequest(String requestUri) Convenience method to create aMockHttpRequestBuilder.static MockHttpResponseBuilderCreates theMockHttpRequestBuilder.static WritableHttpCookiemockResponseCookie(String name, String value) Creates a mockHttpResponseCookie.send(MockHttpRequestBuilder request) Sends theMockHttpRequestBuilderand blocks waiting for theMockHttpResponse.voidsend(MockHttpRequestBuilder request, MockHttpRequestCallback callback) Sends theMockHttpRequestBuilder.sendFollowRedirect(MockHttpRequestBuilder request) Sends theMockHttpRequestBuilderand blocks following the redirect.timeout(int timeout) Specifies the timeout for synchronous send.
-
Constructor Details
-
MockHttpServer
protected MockHttpServer()Instantiated via static methods or extending.
-
-
Method Details
-
configureMockHttpServer
Configures theMockHttpServerto be serviced by theDeployedOfficeInput.- Parameters:
input-DeployedOfficeInput.- Returns:
MockHttpServerto sendHttpRequestinstances.- Throws:
Exception- If fails to configureMockHttpServer.
-
configureMockHttpServer
public static MockHttpServer configureMockHttpServer(DeployedOfficeInput input, String typeQualifier) throws Exception Configures theMockHttpServerto be serviced by theDeployedOfficeInput.- Parameters:
input-DeployedOfficeInput.typeQualifier- Type qualifier for theMockHttpServer.- Returns:
MockHttpServerto sendHttpRequestinstances.- Throws:
Exception- If fails to configureMockHttpServer.
-
configureMockHttpServer
protected static void configureMockHttpServer(MockHttpServer httpServer, String typeQualifier, DeployedOfficeInput input) throws Exception Enables extending implementations to configure themselves as theMockHttpServer.- Parameters:
httpServer-MockHttpServer.typeQualifier- Type qualifier for theMockHttpServer.input-DeployedOfficeInput.- Throws:
Exception- If fails to configureMockHttpServer.
-
mockRequest
Creates theMockHttpRequestBuilder.- Returns:
MockHttpRequestBuilder.
-
mockRequest
Convenience method to create aMockHttpRequestBuilder.- Parameters:
requestUri- Request URI.- Returns:
MockHttpRequestBuilder.
-
mockResponse
Creates theMockHttpRequestBuilder.- Returns:
MockHttpRequestBuilder.
-
mockResponseCookie
Creates a mockHttpResponseCookie.- Parameters:
name- Name.value- value.- Returns:
HttpResponseCookie.
-
mockConnection
Convenience method to create theMockServerHttpConnectionfor GET / with no headers nor entity.- Returns:
MockServerHttpConnection.
-
mockConnection
Creates theMockServerHttpConnection.- Parameters:
request-MockHttpRequestBuilderfor theHttpRequestof theMockServerHttpConnection.- Returns:
MockServerHttpConnection.
-
getExternalServiceInput
public static ExternalServiceInput<ServerHttpConnection,ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> getExternalServiceInput(OfficeSectionInput input) Convenience method to extractExternalServiceInputfromOfficeSectionInput.- Parameters:
input-OfficeSectionInput.- Returns:
ExternalServiceInput.
-
getExternalServiceInput
public static ExternalServiceInput<ServerHttpConnection,ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> getExternalServiceInput(DeployedOfficeInput input) Convenience method to extractExternalServiceInputfromDeployedOfficeInput.- Parameters:
input-DeployedOfficeInput.- Returns:
ExternalServiceInput.
-
timeout
Specifies the timeout for synchronous send.- Parameters:
timeout- Timeout in milliseconds.- Returns:
this.
-
send
Sends theMockHttpRequestBuilder.- Parameters:
request-MockHttpRequestBuilder.callback-MockHttpRequestCallbackto receive theMockHttpResponse.
-
direct
public void direct(MockHttpRequestBuilder request, ExternalServiceInput<ServerHttpConnection, ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> externalServiceInput, MockHttpRequestCallback callback) Triggers direct handling ofMockHttpRequestBuilder.- Parameters:
request-MockHttpRequestBuilder.externalServiceInput-ExternalServiceInputfor direct invocation.callback-MockHttpRequestCallbackto receive theMockHttpResponse.
-
mockJsonRequest
CreateMockHttpRequestBuilderfor JSON payload.- Parameters:
jsonObject- JSON object.- Returns:
MockHttpRequestBuilder.
-
mockJsonRequest
public static MockHttpRequestBuilder mockJsonRequest(HttpMethod method, String requestUri, Object jsonObject) CreateMockHttpRequestBuilderfor JSON payload.- Parameters:
method-HttpMethod.requestUri- Request URI.jsonObject- JSON object.- Returns:
MockHttpRequestBuilder.
-
send
Sends theMockHttpRequestBuilderand blocks waiting for theMockHttpResponse.- Parameters:
request-MockHttpRequestBuilder.- Returns:
MockHttpResponse.
-
direct
public MockHttpResponse direct(MockHttpRequestBuilder request, ExternalServiceInput<ServerHttpConnection, ProcessAwareServerHttpConnectionManagedObject<ByteBuffer>> externalServiceInput) Undertakes direct invocation of servicing theMockHttpRequestBuilder.- Parameters:
request-MockHttpRequestBuilder.externalServiceInput-ExternalServiceInputfor direct invocation.- Returns:
MockHttpResponse.
-
sendFollowRedirect
Sends theMockHttpRequestBuilderand blocks following the redirect.- Parameters:
request-MockHttpRequestBuilder.- Returns:
- Redirect
MockHttpResponse.
-
createMockHttpResponse
protected MockHttpResponse createMockHttpResponse(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, List<WritableHttpHeader> headers, List<WritableHttpCookie> cookies, 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, Throwable failure) Creates theMockHttpResponse.- Parameters:
request-MockHttpServer.MockHttpRequest.failure- Failure in servicing.- Returns:
MockHttpResponse.
-
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
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
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
Description copied from interface:HttpServerImplementationConfigures theHttpServer.- Specified by:
configureHttpServerin interfaceHttpServerImplementation- Parameters:
context-HttpServerImplementationContext.
-