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 java.lang.Object implements MockHttpResponse
MockHttpResponse
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<WritableHttpCookie>
cookies
HttpResponseCookie
instances.protected java.io.InputStream
entityInputStream
HTTP entityInputStream
.protected java.lang.Throwable
failure
Possible failure in writing the response.protected java.util.List<WritableHttpHeader>
headers
HttpHeader
instances.protected MockHttpServer.MockHttpRequest
request
protected HttpStatus
status
protected HttpVersion
version
-
Constructor Summary
Constructors Modifier Constructor Description protected
MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Loads with response failure.protected
MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, java.util.List<WritableHttpHeader> headers, java.util.List<WritableHttpCookie> cookies, java.io.InputStream entityInputStream)
Loads the response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertCookie(HttpResponseCookie cookie)
Asserts contains theWritableHttpCookie
.void
assertHeader(java.lang.String name, java.lang.String value)
Asserts contains theHttpHeader
.void
assertResponse(int statusCode, java.lang.String entity, java.lang.String... headerNameValuePairs)
Asserts the contents of theHttpResponse
.void
assertStatus(int statusCode)
Assets the status of theHttpResponse
.void
assertStatus(HttpStatus status)
Assets theHttpStatus
of theHttpResponse
.WritableHttpCookie
getCookie(java.lang.String name)
Obtains theWritableHttpCookie
by the name.java.util.List<WritableHttpCookie>
getCookies()
Obtains the responseWritableHttpCookie
instances.java.io.InputStream
getEntity()
ObtainsInputStream
to the response HTTP entity.java.lang.String
getEntity(java.nio.charset.Charset charset)
Obtains the HTTP entity as text.WritableHttpHeader
getHeader(java.lang.String name)
Obtains the firstWritableHttpHeader
by the name.java.util.List<WritableHttpHeader>
getHeaders()
Obtains the responseWritableHttpHeader
instances.HttpStatus
getStatus()
Obtains theHttpStatus
.HttpVersion
getVersion()
Obtains theHttpVersion
.
-
-
-
Field Detail
-
request
protected final MockHttpServer.MockHttpRequest request
-
version
protected final HttpVersion version
-
status
protected final HttpStatus status
-
headers
protected final java.util.List<WritableHttpHeader> headers
HttpHeader
instances.
-
cookies
protected final java.util.List<WritableHttpCookie> cookies
HttpResponseCookie
instances.
-
entityInputStream
protected final java.io.InputStream entityInputStream
HTTP entityInputStream
.
-
failure
protected final java.lang.Throwable failure
Possible failure in writing the response.
-
-
Constructor Detail
-
MockHttpResponseImpl
protected MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, HttpVersion version, HttpStatus status, java.util.List<WritableHttpHeader> headers, java.util.List<WritableHttpCookie> cookies, java.io.InputStream entityInputStream)
Loads the response.- Parameters:
request
-MockHttpServer.MockHttpRequest
for thisMockHttpResponse
.version
-HttpVersion
.status
-HttpStatus
.headers
-List
ofHttpHeader
instances.cookies
-List
ofHttpResponseCookie
instances.entityInputStream
- HTTP entityInputStream
.
-
MockHttpResponseImpl
protected MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Loads with response failure.- Parameters:
request
-MockHttpServer.MockHttpRequest
for thisMockHttpResponse
.failure
-Throwable
.
-
-
Method Detail
-
getVersion
public HttpVersion getVersion()
Description copied from interface:MockHttpResponse
Obtains theHttpVersion
.- Specified by:
getVersion
in interfaceMockHttpResponse
- Returns:
HttpVersion
.
-
getStatus
public HttpStatus getStatus()
Description copied from interface:MockHttpResponse
Obtains theHttpStatus
.- Specified by:
getStatus
in interfaceMockHttpResponse
- Returns:
HttpStatus
.
-
getHeader
public WritableHttpHeader getHeader(java.lang.String name)
Description copied from interface:MockHttpResponse
Obtains the firstWritableHttpHeader
by the name.- Specified by:
getHeader
in interfaceMockHttpResponse
- Parameters:
name
- Name of theWritableHttpHeader
.- Returns:
- First
WritableHttpHeader
by the name, ornull
if noWritableHttpHeader
by the name.
-
assertHeader
public void assertHeader(java.lang.String name, java.lang.String value)
Description copied from interface:MockHttpResponse
Asserts contains theHttpHeader
.- Specified by:
assertHeader
in interfaceMockHttpResponse
- Parameters:
name
- Expected name.value
- Expected value.
-
getHeaders
public java.util.List<WritableHttpHeader> getHeaders()
Description copied from interface:MockHttpResponse
Obtains the responseWritableHttpHeader
instances.- Specified by:
getHeaders
in interfaceMockHttpResponse
- Returns:
WritableHttpHeader
instances.
-
getCookie
public WritableHttpCookie getCookie(java.lang.String name)
Description copied from interface:MockHttpResponse
Obtains theWritableHttpCookie
by the name.- Specified by:
getCookie
in interfaceMockHttpResponse
- Parameters:
name
- Name of theWritableHttpCookie
.- Returns:
WritableHttpCookie
by the name, ornull
if noWritableHttpCookie
by the name.
-
getCookies
public java.util.List<WritableHttpCookie> getCookies()
Description copied from interface:MockHttpResponse
Obtains the responseWritableHttpCookie
instances.- Specified by:
getCookies
in interfaceMockHttpResponse
- Returns:
WritableHttpCookie
instances.
-
assertCookie
public void assertCookie(HttpResponseCookie cookie)
Description copied from interface:MockHttpResponse
Asserts contains theWritableHttpCookie
.- Specified by:
assertCookie
in interfaceMockHttpResponse
- Parameters:
cookie
- ExpectedWritableHttpCookie
.- See Also:
MockHttpServer.mockResponseCookie(String, String)
-
getEntity
public java.io.InputStream getEntity()
Description copied from interface:MockHttpResponse
ObtainsInputStream
to the response HTTP entity.- Specified by:
getEntity
in interfaceMockHttpResponse
- Returns:
InputStream
to the response HTTP entity.
-
getEntity
public java.lang.String getEntity(java.nio.charset.Charset charset)
Description copied from interface:MockHttpResponse
Obtains the HTTP entity as text.- Specified by:
getEntity
in interfaceMockHttpResponse
- Parameters:
charset
-Charset
for HTTP entity. May benull
to use defaultCharset
.- Returns:
- Text of the HTTP entity.
-
assertStatus
public void assertStatus(int statusCode)
Description copied from interface:MockHttpResponse
Assets the status of theHttpResponse
.- Specified by:
assertStatus
in interfaceMockHttpResponse
- Parameters:
statusCode
- Status code.
-
assertStatus
public void assertStatus(HttpStatus status)
Description copied from interface:MockHttpResponse
Assets theHttpStatus
of theHttpResponse
.- Specified by:
assertStatus
in interfaceMockHttpResponse
- Parameters:
status
-HttpStatus
.
-
assertResponse
public void assertResponse(int statusCode, java.lang.String entity, java.lang.String... headerNameValuePairs)
Description copied from interface:MockHttpResponse
Asserts the contents of theHttpResponse
.- Specified by:
assertResponse
in interfaceMockHttpResponse
- Parameters:
statusCode
- Expected status code.entity
- Expected entity.headerNameValuePairs
- ExpectedHttpHeader
name/value pairs. This only confirms they exist on theHttpResponse
. It is not inclusive to check if these are the onlyHttpHeader
instances.
-
-