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
MockHttpResponseimplementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<WritableHttpCookie>cookiesHttpResponseCookieinstances.protected java.io.InputStreamentityInputStreamHTTP entityInputStream.protected java.lang.ThrowablefailurePossible failure in writing the response.protected java.util.List<WritableHttpHeader>headersHttpHeaderinstances.protected MockHttpServer.MockHttpRequestrequestprotected HttpStatusstatusprotected HttpVersionversion
-
Constructor Summary
Constructors Modifier Constructor Description protectedMockHttpResponseImpl(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)Loads with response failure.protectedMockHttpResponseImpl(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 voidassertCookie(HttpResponseCookie cookie)Asserts contains theWritableHttpCookie.voidassertHeader(java.lang.String name, java.lang.String value)Asserts contains theHttpHeader.voidassertResponse(int statusCode, java.lang.String entity, java.lang.String... headerNameValuePairs)Asserts the contents of theHttpResponse.voidassertStatus(int statusCode)Assets the status of theHttpResponse.voidassertStatus(HttpStatus status)Assets theHttpStatusof theHttpResponse.WritableHttpCookiegetCookie(java.lang.String name)Obtains theWritableHttpCookieby the name.java.util.List<WritableHttpCookie>getCookies()Obtains the responseWritableHttpCookieinstances.java.io.InputStreamgetEntity()ObtainsInputStreamto the response HTTP entity.java.lang.StringgetEntity(java.nio.charset.Charset charset)Obtains the HTTP entity as text.WritableHttpHeadergetHeader(java.lang.String name)Obtains the firstWritableHttpHeaderby the name.java.util.List<WritableHttpHeader>getHeaders()Obtains the responseWritableHttpHeaderinstances.HttpStatusgetStatus()Obtains theHttpStatus.HttpVersiongetVersion()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
HttpHeaderinstances.
-
cookies
protected final java.util.List<WritableHttpCookie> cookies
HttpResponseCookieinstances.
-
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.MockHttpRequestfor thisMockHttpResponse.version-HttpVersion.status-HttpStatus.headers-ListofHttpHeaderinstances.cookies-ListofHttpResponseCookieinstances.entityInputStream- HTTP entityInputStream.
-
MockHttpResponseImpl
protected MockHttpResponseImpl(MockHttpServer.MockHttpRequest request, java.lang.Throwable failure)
Loads with response failure.- Parameters:
request-MockHttpServer.MockHttpRequestfor thisMockHttpResponse.failure-Throwable.
-
-
Method Detail
-
getVersion
public HttpVersion getVersion()
Description copied from interface:MockHttpResponseObtains theHttpVersion.- Specified by:
getVersionin interfaceMockHttpResponse- Returns:
HttpVersion.
-
getStatus
public HttpStatus getStatus()
Description copied from interface:MockHttpResponseObtains theHttpStatus.- Specified by:
getStatusin interfaceMockHttpResponse- Returns:
HttpStatus.
-
getHeader
public WritableHttpHeader getHeader(java.lang.String name)
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
public void assertHeader(java.lang.String name, java.lang.String value)Description copied from interface:MockHttpResponseAsserts contains theHttpHeader.- Specified by:
assertHeaderin interfaceMockHttpResponse- Parameters:
name- Expected name.value- Expected value.
-
getHeaders
public java.util.List<WritableHttpHeader> getHeaders()
Description copied from interface:MockHttpResponseObtains the responseWritableHttpHeaderinstances.- Specified by:
getHeadersin interfaceMockHttpResponse- Returns:
WritableHttpHeaderinstances.
-
getCookie
public WritableHttpCookie getCookie(java.lang.String name)
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
public java.util.List<WritableHttpCookie> getCookies()
Description copied from interface:MockHttpResponseObtains the responseWritableHttpCookieinstances.- Specified by:
getCookiesin interfaceMockHttpResponse- Returns:
WritableHttpCookieinstances.
-
assertCookie
public void assertCookie(HttpResponseCookie cookie)
Description copied from interface:MockHttpResponseAsserts contains theWritableHttpCookie.- Specified by:
assertCookiein interfaceMockHttpResponse- Parameters:
cookie- ExpectedWritableHttpCookie.- See Also:
MockHttpServer.mockResponseCookie(String, String)
-
getEntity
public java.io.InputStream getEntity()
Description copied from interface:MockHttpResponseObtainsInputStreamto the response HTTP entity.- Specified by:
getEntityin interfaceMockHttpResponse- Returns:
InputStreamto the response HTTP entity.
-
getEntity
public java.lang.String getEntity(java.nio.charset.Charset charset)
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
public void assertStatus(HttpStatus status)
Description copied from interface:MockHttpResponseAssets theHttpStatusof theHttpResponse.- Specified by:
assertStatusin interfaceMockHttpResponse- Parameters:
status-HttpStatus.
-
assertResponse
public void assertResponse(int statusCode, java.lang.String entity, java.lang.String... headerNameValuePairs)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.
-
-