Package com.oorian.test
Class TestHttpResponse
java.lang.Object
com.oorian.test.TestHttpResponse
- All Implemented Interfaces:
OorianHttpResponse
In-memory implementation of
OorianHttpResponse for headless testing.
Captures all response output (headers, status, content) in memory for inspection
during testing. The rendered content can be retrieved via getContent().
Usage:
TestHttpResponse response = new TestHttpResponse();
page.write(request, response);
String html = response.getContent();
int status = response.getStatus();
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Field Summary
Fields inherited from interface com.oorian.OorianHttpResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CREATED, SC_FORBIDDEN, SC_FOUND, SC_GONE, SC_INTERNAL_SERVER_ERROR, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_NO_CONTENT, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_SERVICE_UNAVAILABLE, SC_TEMPORARY_REDIRECT, SC_TOO_MANY_REQUESTS, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(OorianCookie cookie) Adds a cookie to the response.voidAdds a response header without replacing existing values.booleancontainsHeader(String name) Returns whether the response contains the specified header.voidForces any content in the buffer to be written to the client.Returns the content written to this response viagetWriter().Returns all cookies added to this response.getHeaderValues(String name) Returns all values for a response header.byte[]Returns the content written to this response viagetOutputStream().Returns the output stream for writing binary response data.Returns the redirect URL ifsendRedirect(String)was called.intReturns the current HTTP status code of this response.Returns a PrintWriter for writing character response data.booleanReturns whether the response has been committed.voidSends an error response with the specified status code and message.voidsendRedirect(String url) Sends a temporary redirect response to the specified URL.voidsetCharacterEncoding(String charset) Sets the character encoding of the response.voidsetContentLength(int len) Sets the content length of the response body.voidsetContentType(String type) Sets the content type of the response.voidSets a response header, replacing any existing values.voidsetStatus(int sc) Sets the HTTP status code of the response.
-
Constructor Details
-
TestHttpResponse
public TestHttpResponse()Creates a new TestHttpResponse.
-
-
Method Details
-
getContent
Returns the content written to this response viagetWriter().- Returns:
- the response content as a string
-
getOutputContent
public byte[] getOutputContent()Returns the content written to this response viagetOutputStream().- Returns:
- the response content as a byte array
-
getRedirectUrl
Returns the redirect URL ifsendRedirect(String)was called.- Returns:
- the redirect URL, or
nullif no redirect was issued
-
getCookies
Returns all cookies added to this response.- Returns:
- the list of response cookies
-
getHeaderValues
Returns all values for a response header.- Parameters:
name- the header name- Returns:
- the list of header values, or an empty list if not set
-
setContentType
Description copied from interface:OorianHttpResponseSets the content type of the response.- Specified by:
setContentTypein interfaceOorianHttpResponse- Parameters:
type- the MIME content type
-
setCharacterEncoding
Description copied from interface:OorianHttpResponseSets the character encoding of the response.- Specified by:
setCharacterEncodingin interfaceOorianHttpResponse- Parameters:
charset- the character encoding name
-
setContentLength
public void setContentLength(int len) Description copied from interface:OorianHttpResponseSets the content length of the response body.- Specified by:
setContentLengthin interfaceOorianHttpResponse- Parameters:
len- the content length in bytes
-
getOutputStream
Description copied from interface:OorianHttpResponseReturns the output stream for writing binary response data.- Specified by:
getOutputStreamin interfaceOorianHttpResponse- Returns:
- the output stream
- Throws:
IOException- if an I/O error occurs
-
getWriter
Description copied from interface:OorianHttpResponseReturns a PrintWriter for writing character response data.- Specified by:
getWriterin interfaceOorianHttpResponse- Returns:
- the print writer
- Throws:
IOException- if an I/O error occurs
-
setHeader
Description copied from interface:OorianHttpResponseSets a response header, replacing any existing values.- Specified by:
setHeaderin interfaceOorianHttpResponse- Parameters:
name- the header namevalue- the header value
-
addHeader
Description copied from interface:OorianHttpResponseAdds a response header without replacing existing values.- Specified by:
addHeaderin interfaceOorianHttpResponse- Parameters:
name- the header namevalue- the header value
-
isCommitted
public boolean isCommitted()Description copied from interface:OorianHttpResponseReturns whether the response has been committed.- Specified by:
isCommittedin interfaceOorianHttpResponse- Returns:
- true if the response has been committed
-
sendError
Description copied from interface:OorianHttpResponseSends an error response with the specified status code and message.- Specified by:
sendErrorin interfaceOorianHttpResponse- Parameters:
sc- the HTTP status codemsg- the error message- Throws:
IOException- if an I/O error occurs
-
setStatus
public void setStatus(int sc) Description copied from interface:OorianHttpResponseSets the HTTP status code of the response.- Specified by:
setStatusin interfaceOorianHttpResponse- Parameters:
sc- the status code
-
sendRedirect
Description copied from interface:OorianHttpResponseSends a temporary redirect response to the specified URL.- Specified by:
sendRedirectin interfaceOorianHttpResponse- Parameters:
url- the redirect URL- Throws:
IOException- if an I/O error occurs
-
addCookie
Description copied from interface:OorianHttpResponseAdds a cookie to the response.- Specified by:
addCookiein interfaceOorianHttpResponse- Parameters:
cookie- the cookie to add
-
getStatus
public int getStatus()Description copied from interface:OorianHttpResponseReturns the current HTTP status code of this response.- Specified by:
getStatusin interfaceOorianHttpResponse- Returns:
- the status code
-
containsHeader
Description copied from interface:OorianHttpResponseReturns whether the response contains the specified header.- Specified by:
containsHeaderin interfaceOorianHttpResponse- Parameters:
name- the header name- Returns:
- true if the header has been set
-
flushBuffer
Description copied from interface:OorianHttpResponseForces any content in the buffer to be written to the client.- Specified by:
flushBufferin interfaceOorianHttpResponse- Throws:
IOException- if an I/O error occurs
-