Package net.officefloor.server.http.mock
Class MockHttpServer.MockHttpResponseImpl
java.lang.Object
net.officefloor.server.http.mock.MockHttpServer.MockHttpResponseImpl
- All Implemented Interfaces:
MockHttpResponse
- Direct Known Subclasses:
MockWoofServer.MockWoofResponseImpl
- Enclosing class:
- MockHttpServer
protected static class MockHttpServer.MockHttpResponseImpl
extends Object
implements MockHttpResponse
MockHttpResponse implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<WritableHttpCookie>HttpResponseCookieinstances.protected final InputStreamHTTP entityInputStream.protected final ThrowablePossible failure in writing the response.protected final List<WritableHttpHeader>HttpHeaderinstances.protected final MockHttpServer.MockHttpRequestprotected final HttpStatusprotected final HttpVersion -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMockHttpResponseImpl(MockHttpServer.MockHttpRequest request, Throwable failure) Loads with response failure.protectedMockHttpResponseImpl(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, List<WritableHttpHeader> headers, List<WritableHttpCookie> cookies, InputStream entityInputStream) Loads the response. -
Method Summary
Modifier and TypeMethodDescriptionvoidassertCookie(HttpResponseCookie cookie) Asserts contains theWritableHttpCookie.voidassertHeader(String name, String value) Asserts contains theHttpHeader.voidassertJson(int statusCode, Object entity, com.fasterxml.jackson.databind.ObjectMapper mapper, String... headerNameValuePairs) Asserts the JSON response providing customObjectMapper.voidassertJson(int statusCode, Object entity, String... headerNameValuePairs) Asserts the JSON response.voidassertResponse(int statusCode, String entity, String... headerNameValuePairs) Asserts the contents of theHttpResponse.voidassertStatus(int statusCode) Assets the status of theHttpResponse.voidassertStatus(HttpStatus status) Assets theHttpStatusof theHttpResponse.Obtains theWritableHttpCookieby the name.Obtains the responseWritableHttpCookieinstances.ObtainsInputStreamto the response HTTP entity.Obtains the HTTP entity as text.Obtains the firstWritableHttpHeaderby the name.Obtains the responseWritableHttpHeaderinstances.<T> TObtains the JSON object from HTTP payload.<T> TObtains the JSON object from HTTP payload using customObjectMapper.Obtains theHttpStatus.Obtains theHttpVersion.
-
Field Details
-
request
-
version
-
status
-
headers
HttpHeaderinstances. -
cookies
HttpResponseCookieinstances. -
entityInputStream
HTTP entityInputStream. -
failure
Possible failure in writing the response.
-
-
Constructor Details
-
MockHttpResponseImpl
protected MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, List<WritableHttpHeader> headers, List<WritableHttpCookie> cookies, InputStream entityInputStream) Loads the response.- Parameters:
request-MockHttpServer.MockHttpRequestfor thisMockHttpResponse.version-HttpVersion.status-HttpStatus.headers-ListofHttpHeaderinstances.cookies-ListofHttpResponseCookieinstances.entityInputStream- HTTP entityInputStream.
-
MockHttpResponseImpl
Loads with response failure.- Parameters:
request-MockHttpServer.MockHttpRequestfor thisMockHttpResponse.failure-Throwable.
-
-
Method Details
-
getVersion
Description copied from interface:MockHttpResponseObtains theHttpVersion.- Specified by:
getVersionin interfaceMockHttpResponse- Returns:
HttpVersion.
-
getStatus
Description copied from interface:MockHttpResponseObtains theHttpStatus.- Specified by:
getStatusin interfaceMockHttpResponse- Returns:
HttpStatus.
-
getHeader
Description copied from interface:MockHttpResponseObtains the firstWritableHttpHeaderby the name.- Specified by:
getHeaderin interfaceMockHttpResponse- Parameters:
name- Name of theWritableHttpHeader.- Returns:
- First
WritableHttpHeaderby the name, ornullif noWritableHttpHeaderby the name.
-
assertHeader
Description copied from interface:MockHttpResponseAsserts contains theHttpHeader.- Specified by:
assertHeaderin interfaceMockHttpResponse- Parameters:
name- Expected name.value- Expected value.
-
getHeaders
Description copied from interface:MockHttpResponseObtains the responseWritableHttpHeaderinstances.- Specified by:
getHeadersin interfaceMockHttpResponse- Returns:
WritableHttpHeaderinstances.
-
getCookie
Description copied from interface:MockHttpResponseObtains theWritableHttpCookieby the name.- Specified by:
getCookiein interfaceMockHttpResponse- Parameters:
name- Name of theWritableHttpCookie.- Returns:
WritableHttpCookieby the name, ornullif noWritableHttpCookieby the name.
-
getCookies
Description copied from interface:MockHttpResponseObtains the responseWritableHttpCookieinstances.- Specified by:
getCookiesin interfaceMockHttpResponse- Returns:
WritableHttpCookieinstances.
-
assertCookie
Description copied from interface:MockHttpResponseAsserts contains theWritableHttpCookie.- Specified by:
assertCookiein interfaceMockHttpResponse- Parameters:
cookie- ExpectedWritableHttpCookie.- See Also:
-
getEntity
Description copied from interface:MockHttpResponseObtainsInputStreamto the response HTTP entity.- Specified by:
getEntityin interfaceMockHttpResponse- Returns:
InputStreamto the response HTTP entity.
-
getEntity
Description copied from interface:MockHttpResponseObtains the HTTP entity as text.- Specified by:
getEntityin interfaceMockHttpResponse- Parameters:
charset-Charsetfor HTTP entity. May benullto use defaultCharset.- Returns:
- Text of the HTTP entity.
-
assertStatus
public void assertStatus(int statusCode) Description copied from interface:MockHttpResponseAssets the status of theHttpResponse.- Specified by:
assertStatusin interfaceMockHttpResponse- Parameters:
statusCode- Status code.
-
assertStatus
Description copied from interface:MockHttpResponseAssets theHttpStatusof theHttpResponse.- Specified by:
assertStatusin interfaceMockHttpResponse- Parameters:
status-HttpStatus.
-
assertResponse
Description copied from interface:MockHttpResponseAsserts the contents of theHttpResponse.- Specified by:
assertResponsein interfaceMockHttpResponse- Parameters:
statusCode- Expected status code.entity- Expected entity.headerNameValuePairs- ExpectedHttpHeadername/value pairs. This only confirms they exist on theHttpResponse. It is not inclusive to check if these are the onlyHttpHeaderinstances.
-
getJson
Description copied from interface:MockHttpResponseObtains the JSON object from HTTP payload.- Specified by:
getJsonin interfaceMockHttpResponse- Type Parameters:
T- Type of object.- Parameters:
statusCode-HttpStatus.clazz-Classfor the JSON object.- Returns:
- JSON object.
-
getJson
public <T> T getJson(int statusCode, Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) Description copied from interface:MockHttpResponseObtains the JSON object from HTTP payload using customObjectMapper.- Specified by:
getJsonin interfaceMockHttpResponse- Type Parameters:
T- Type of object.- Parameters:
statusCode-HttpStatus.clazz-Classfor the JSON object.mapper- CustomObjectMapper.- Returns:
- JSON object.
-
assertJson
Description copied from interface:MockHttpResponseAsserts the JSON response.- Specified by:
assertJsonin interfaceMockHttpResponse- Parameters:
statusCode-HttpStatus.entity-Objectto be written as JSON.headerNameValuePairs- ExpectedHttpHeadername/value pairs.
-
assertJson
public void assertJson(int statusCode, Object entity, com.fasterxml.jackson.databind.ObjectMapper mapper, String... headerNameValuePairs) Description copied from interface:MockHttpResponseAsserts the JSON response providing customObjectMapper.- Specified by:
assertJsonin interfaceMockHttpResponse- Parameters:
statusCode-HttpStatus.entity-Objectto be written as JSON.mapper- CustomObjectMapper.headerNameValuePairs- ExpectedHttpHeadername/value pairs.
-