Package net.officefloor.woof.mock
Class MockWoofServer
- java.lang.Object
-
- net.officefloor.server.http.mock.MockHttpServer
-
- net.officefloor.woof.mock.MockWoofServer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,HttpServerImplementation
,HttpServerLocation
- Direct Known Subclasses:
MockWoofServerExtension
,MockWoofServerRule
public class MockWoofServer extends MockHttpServer implements java.lang.AutoCloseable
MockHttpServer
loading the WoOF application.This provides convenient means to test WoOF applications.
- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MockWoofServer.MockWoofInput
Annotates service methods for theClassSectionSource
.protected class
MockWoofServer.MockWoofResponseImpl
MockWoofResponse
implementation.static interface
MockWoofServer.MockWoofServerConfigurer
Enables configuring theMockWoofServer
.-
Nested classes/interfaces inherited from class net.officefloor.server.http.mock.MockHttpServer
MockHttpServer.MockHttpRequest, MockHttpServer.MockHttpResponseImpl, MockHttpServer.MockServerHttpConnectionImpl
-
-
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 Constructor Description MockWoofServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected MockHttpResponse
createMockHttpResponse(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Creates theMockHttpResponse
.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
.static MockWoofServer.MockWoofServerConfigurer
createSectionServicer(java.lang.Class<?> sectionClass)
OfficeFloor
getOfficeFloor()
Obtains theOfficeFloor
.static MockHttpRequestBuilder
mockJsonRequest(HttpMethod method, java.lang.Object jsonObject)
CreateMockHttpRequestBuilder
for JSON payload.static MockHttpRequestBuilder
mockJsonRequest(HttpMethod method, java.lang.String requestUri, java.lang.Object jsonObject)
CreateMockHttpRequestBuilder
for JSON payload.static OfficeFloor
open(int httpPort, int httpsPort, java.lang.Class<?> sectionClass)
static OfficeFloor
open(int httpPort, int httpsPort, MockWoofServer.MockWoofServerConfigurer... configurers)
Opens theWoOF
on particular ports.static OfficeFloor
open(int httpPort, java.lang.Class<?> sectionClass)
static MockWoofServer
open(MockWoofServer.MockWoofServerConfigurer... configurers)
Opens theMockWoofServer
.protected static MockWoofServer
open(MockWoofServer server, MockWoofServer.MockWoofServerConfigurer... configurers)
Opens theMockWoofServer
.MockWoofResponse
send(MockHttpRequestBuilder request)
Sends theMockHttpRequestBuilder
and blocks waiting for theMockHttpResponse
.MockWoofResponse
sendFollowRedirect(MockHttpRequestBuilder request)
Sends theMockHttpRequestBuilder
and blocks following the redirect.-
Methods inherited from class net.officefloor.server.http.mock.MockHttpServer
configureHttpServer, configureMockHttpServer, configureMockHttpServer, createClientUrl, getClusterHostName, getClusterHttpPort, getClusterHttpsPort, getDomain, getHttpPort, getHttpsPort, mockConnection, mockConnection, mockRequest, mockRequest, mockResponse, mockResponseCookie, send, timeout
-
-
-
-
Method Detail
-
open
public static MockWoofServer open(MockWoofServer.MockWoofServerConfigurer... configurers) throws java.lang.Exception
Opens theMockWoofServer
.- Parameters:
configurers
-MockWoofServer.MockWoofServerConfigurer
instances.- Returns:
MockWoofServer
.- Throws:
java.lang.Exception
- If fails to start theMockWoofServer
.
-
open
public static OfficeFloor open(int httpPort, java.lang.Class<?> sectionClass) throws java.lang.Exception
Opens the
WoOF
on a particular port with theClassSectionSource
to serviceServerHttpConnection
.This is a convenience method to typically setup a mock server to respond to application requests.
- Parameters:
httpPort
- HTTP port.sectionClass
-Class
forClassSectionSource
.- Returns:
MockWoofServer
.- Throws:
java.lang.Exception
- If fails to start theMockWoofServer
.
-
open
public static OfficeFloor open(int httpPort, int httpsPort, java.lang.Class<?> sectionClass) throws java.lang.Exception
Opens the
WoOF
on a particular port with theClassSectionSource
to serviceServerHttpConnection
.This is a convenience method to typically setup a mock server to respond to application requests.
- Parameters:
httpPort
- HTTP port.httpsPort
- HTTPS port.sectionClass
-Class
forClassSectionSource
.- Returns:
MockWoofServer
.- Throws:
java.lang.Exception
- If fails to start theMockWoofServer
.
-
createSectionServicer
public static MockWoofServer.MockWoofServerConfigurer createSectionServicer(java.lang.Class<?> sectionClass)
- Parameters:
sectionClass
-ClassSectionSource
Class
.- Returns:
MockWoofServer.MockWoofServerConfigurer
.
-
open
public static OfficeFloor open(int httpPort, int httpsPort, MockWoofServer.MockWoofServerConfigurer... configurers) throws java.lang.Exception
Opens theWoOF
on particular ports.- Parameters:
httpPort
- HTTP port.httpsPort
- HTTPS port.configurers
-MockWoofServer.MockWoofServerConfigurer
instances.- Returns:
MockWoofServer
.- Throws:
java.lang.Exception
- If fails to start theMockWoofServer
.
-
open
protected static MockWoofServer open(MockWoofServer server, MockWoofServer.MockWoofServerConfigurer... configurers) throws java.lang.Exception
Opens theMockWoofServer
.- Parameters:
server
-MockWoofServer
.configurers
-MockWoofServer.MockWoofServerConfigurer
instances.- Returns:
- Input
MockWoofServer
. - Throws:
java.lang.Exception
- If fails to open theMockWoofServer
.
-
mockJsonRequest
public static MockHttpRequestBuilder mockJsonRequest(HttpMethod method, java.lang.Object jsonObject)
CreateMockHttpRequestBuilder
for JSON payload.- Parameters:
method
-HttpMethod
.jsonObject
- JSON object.- Returns:
MockHttpRequestBuilder
.
-
mockJsonRequest
public static MockHttpRequestBuilder mockJsonRequest(HttpMethod method, java.lang.String requestUri, java.lang.Object jsonObject)
CreateMockHttpRequestBuilder
for JSON payload.- Parameters:
method
-HttpMethod
.requestUri
- Request URI.jsonObject
- JSON object.- Returns:
MockHttpRequestBuilder
.
-
getOfficeFloor
public OfficeFloor getOfficeFloor()
Obtains theOfficeFloor
.- Returns:
OfficeFloor
.
-
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)
Description copied from class:MockHttpServer
Creates theMockHttpResponse
.- Overrides:
createMockHttpResponse
in classMockHttpServer
- Parameters:
request
-MockHttpServer.MockHttpRequest
.version
-HttpVersion
.status
-HttpStatus
.headers
-WritableHttpHeader
instances.cookies
-WritableHttpCookie
instances.entityInputStream
- Entity.- Returns:
MockHttpResponse
.
-
createMockHttpResponse
protected MockHttpResponse createMockHttpResponse(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Description copied from class:MockHttpServer
Creates theMockHttpResponse
.- Overrides:
createMockHttpResponse
in classMockHttpServer
- Parameters:
request
-MockHttpServer.MockHttpRequest
.failure
- Failure in servicing.- Returns:
MockHttpResponse
.
-
send
public MockWoofResponse send(MockHttpRequestBuilder request)
Description copied from class:MockHttpServer
Sends theMockHttpRequestBuilder
and blocks waiting for theMockHttpResponse
.- Overrides:
send
in classMockHttpServer
- Parameters:
request
-MockHttpRequestBuilder
.- Returns:
MockHttpResponse
.
-
sendFollowRedirect
public MockWoofResponse sendFollowRedirect(MockHttpRequestBuilder request)
Description copied from class:MockHttpServer
Sends theMockHttpRequestBuilder
and blocks following the redirect.- Overrides:
sendFollowRedirect
in classMockHttpServer
- Parameters:
request
-MockHttpRequestBuilder
.- Returns:
- Redirect
MockHttpResponse
.
-
close
public void close() throws java.lang.Exception
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
-