Class MockResponse
- All Implemented Interfaces:
Response
Response
implementation that is suitable for testing a
web application outside a servlet container.- Since:
- 1.0
-
Field Summary
Fields inherited from class rife.engine.AbstractResponse
gzipByteOutputStream_, gzipOutputStream_, lastElement_, outputStream_, responseOutputStream_, textBuffer_, textBufferEnabled_
-
Method Summary
Modifier and TypeMethodDescriptionprotected OutputStream
This method needs to be implemented by the extending back-end class and will be called byAbstractResponse
during the RIFE2-specific additional behaviour.protected void
_setContentType
(String contentType) This method needs to be implemented by the extending back-end class and will be called byAbstractResponse
during the RIFE2-specific additional behaviour.void
void
addDateHeader
(String name, long date) void
void
addIntHeader
(String name, int integer) boolean
containsHeader
(String name) byte[]
getBytes()
Retrieves an array of all the bytes that have been written to this response.int
Retrieves the content type that was explicitly set for this response.long
getDateHeader
(String name) Returns the value of the specified response header as a long value that represents a Date object.Returns the value of the specified response header as aString
.Returns the value of the specified response header as aString
.getHeaders
(String name) Returns all the values of the specified response header as anCollection
ofString
objects.Retrieves the underlyingHttpServletResponse
.int
getIntHeader
(String name) Returns the value of the specified response header as anint
.Retrieves the list of cookies that have been added in this response.Retrieves the content of this response as parsed HTML.Returns the error reason of this response.int
Returns the status code of this response.Retrieves the template instance that was printed to the response.getText()
Retrieves the content of this response as text.void
Prints the content of a template to the request text output.void
removeHeader
(String name) Removes a response header with the given name.void
sendError
(int statusCode) void
void
sendRedirect
(String location) void
setContentLength
(int length) void
setDateHeader
(String name, long date) void
void
setIntHeader
(String name, int value) void
void
setStatus
(int statusCode) xpathBoolean
(String expression) Evaluate an XPath expression in the context of the response text and return the result as a boolean.xpathBoolean
(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a boolean.Evaluate an XPath expression in the context of the response text and return the result as a DOM node.Evaluate an XPath expression in the provided context object and return the result as a DOM node.xpathNodeSet
(String expression) Evaluate an XPath expression in the context of the response text and return the result as a list of DOM nodes.xpathNodeSet
(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a list of DOM nodes.xpathNumber
(String expression) Evaluate an XPath expression in the context of the response text and return the result as a number.xpathNumber
(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a number.xpathString
(String expression) Evaluate an XPath expression in the context of the response text and return the result as a string.xpathString
(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a string.Methods inherited from class rife.engine.AbstractResponse
clearBuffer, close, enableTextBuffer, flush, getLastElement, getOutputStream, getRequest, isContentTypeSet, isTextBufferEnabled, print, print, setContentType, setLastElement
-
Method Details
-
getBytes
public byte[] getBytes()Retrieves an array of all the bytes that have been written to this response.- Returns:
- an array of bytes with the response content
- Since:
- 1.0
- See Also:
-
getText
Retrieves the content of this response as text.- Returns:
- the response content as text
- Since:
- 1.0
- See Also:
-
getTemplate
Retrieves the template instance that was printed to the response.- Returns:
- the template instance that was printed to the response; or
null
of no template was printed to the response - Since:
- 1.0
- See Also:
-
getParsedHtml
Retrieves the content of this response as parsed HTML.- Returns:
- the response content as parsed HTML
- Since:
- 1.0
- See Also:
-
getContentType
Description copied from interface:Response
Retrieves the content type that was explicitly set for this response.- Specified by:
getContentType
in interfaceResponse
- Overrides:
getContentType
in classAbstractResponse
- Returns:
- the content type as a String; or
null
if the content type wasn't set - See Also:
-
xpathNodeSet
Evaluate an XPath expression in the context of the response text and return the result as a list of DOM nodes.More information about XPath can be found in the original specification or in this tutorial.
- Returns:
- the result as a
NodeList
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNode
Evaluate an XPath expression in the context of the response text and return the result as a DOM node.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathString
Evaluate an XPath expression in the context of the response text and return the result as a string.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathBoolean
Evaluate an XPath expression in the context of the response text and return the result as a boolean.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNumber
Evaluate an XPath expression in the context of the response text and return the result as a number.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNodeSet
Evaluate an XPath expression in the provided context object and return the result as a list of DOM nodes.More information about XPath can be found in the original specification or in this tutorial.
- Returns:
- the result as a
NodeList
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNode
Evaluate an XPath expression in the provided context object and return the result as a DOM node.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathString
Evaluate an XPath expression in the provided context object and return the result as a string.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathBoolean
Evaluate an XPath expression in the provided context object and return the result as a boolean.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNumber
Evaluate an XPath expression in the provided context object and return the result as a number.- Returns:
- the result as a
Node
- Throws:
XPathExpressionException
- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
print
Description copied from interface:Response
Prints the content of a template to the request text output.- Specified by:
print
in interfaceResponse
- Overrides:
print
in classAbstractResponse
- Parameters:
template
- the template that will be printed- Throws:
EngineException
- if an error occurs during the output of the template content- See Also:
-
_setContentType
Description copied from class:AbstractResponse
This method needs to be implemented by the extending back-end class and will be called byAbstractResponse
during the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Response interface
.- Specified by:
_setContentType
in classAbstractResponse
- See Also:
-
getCharacterEncoding
Description copied from interface:Response
-
setContentLength
public void setContentLength(int length) Description copied from interface:Response
-
getContentLength
public int getContentLength() -
sendRedirect
Description copied from interface:Response
-
_getOutputStream
Description copied from class:AbstractResponse
This method needs to be implemented by the extending back-end class and will be called byAbstractResponse
during the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Request interface
.- Specified by:
_getOutputStream
in classAbstractResponse
- See Also:
-
addCookie
Description copied from interface:Response
-
getNewCookieNames
Retrieves the list of cookies that have been added in this response.- Returns:
- the list of added cookies; or
an empty list if no cookies have been added
- Since:
- 1.0
-
getDateHeader
Returns the value of the specified response header as a long value that represents a Date object. Use this method with headers that contain dates.The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case-insensitive.
If the response did not have a header of the specified name, this method returns
-1
. If the header can't be converted to a date, the method throws anIllegalArgumentException
.- Parameters:
name
- the name of the header- Returns:
- a
long
value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT; or-1
if the named header was not included with the response - Throws:
IllegalArgumentException
- if the header value can't be converted to a date- Since:
- 1.0
-
getHeader
Returns the value of the specified response header as aString
. If the response did not include a header of the specified name, this method returnsnull
. The header name is case-insensitive. You can use this method with any response header.- Parameters:
name
- the name of the header- Returns:
- a
String
containing the value of the response header; ornull
if the response does not have a header of that name - Since:
- 1.0
-
getHeaderNames
Returns the value of the specified response header as aString
. If the response did not include a header of the specified name, this method returnsnull
. The header name is case-insensitive. You can use this method with any response header.- Returns:
- a
Collection
of all the header names sent with this response; orif the response has no headers, an empty
Collection
- Since:
- 1.0
-
getHeaders
Returns all the values of the specified response header as anCollection
ofString
objects.If the response did not include any headers of the specified name, this method returns an empty
Collection
. The header name is case-insensitive. You can use this method with any response header.- Parameters:
name
- the name of the header- Returns:
- a
Collection
containing the values of the response header; orif the response does not have any headers of that name return an empty
Collection
- Since:
- 1.0
-
getIntHeader
Returns the value of the specified response header as anint
. If the response does not have a header of the specified name, this method returns-1
. If the header cannot be converted to aninteger
, this method throws aNumberFormatException
.The header name is case-insensitive.
- Parameters:
name
- the name of the header- Returns:
- an
integer
expressing the value of the response header; or-1
if the response doesn't have a header of this name - Throws:
NumberFormatException
- if the header value can't be converted to anint
- Since:
- 1.0
-
addHeader
Description copied from interface:Response
-
addDateHeader
Description copied from interface:Response
-
addIntHeader
Description copied from interface:Response
-
containsHeader
Description copied from interface:Response
-
setDateHeader
Description copied from interface:Response
-
setHeader
Description copied from interface:Response
-
setIntHeader
Description copied from interface:Response
-
removeHeader
Removes a response header with the given name.- Parameters:
name
- the name of the header to remove- Since:
- 1.0
-
getStatus
public int getStatus()Returns the status code of this response.- Returns:
- an
integer
expressing the status code of this response - Since:
- 1.0
-
getReason
Returns the error reason of this response.- Returns:
- an
String
expressing the reason of this response error - Since:
- 1.0
-
setStatus
public void setStatus(int statusCode) Description copied from interface:Response
-
sendError
Description copied from interface:Response
- Throws:
EngineException
-
sendError
Description copied from interface:Response
- Throws:
EngineException
-
encodeURL
Description copied from interface:Response
-
setLocale
Description copied from interface:Response
-
getLocale
Description copied from interface:Response
-
getWriter
Description copied from interface:Response
- Throws:
IOException
-
getHttpServletResponse
Description copied from interface:Response
Retrieves the underlyingHttpServletResponse
.- Returns:
- the underlying
HttpServletResponse
instance; ornull
if this response isn't backed byHttpServletResponse
-