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
contentType_, gzipByteOutputStream_, gzipOutputStream_, lastElement_, outputStream_, responseOutputStream_, textBuffer_, textBufferEnabled_ -
Method Summary
Modifier and TypeMethodDescriptionvoidRetrieves the content of this response as parsed server-sent events (SSE).Retrieves the list of cookies that have been added in this response.Retrieves the content of this response as parsed HTML.Retrieves the template instance that was printed to the response.voidPrints the content of a template to the request text output.voidprintBlock(Template template, String blockId) Prints the content of one block of a template to the request text output.protected voidsseEventSent(Template template) Notifies that a server-sent event was written to this response.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.SiteResponse
_getOutputStream, _setContentType, addDateHeader, addHeader, addIntHeader, containsHeader, encodeURL, getBytes, getCharacterEncoding, getContentLength, getContentType, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpHeaders, getHttpServletResponse, getIntHeader, getLocale, getNewCookies, getReason, getSingleValueHttpHeaders, getStatus, getText, getWriter, isDetached, isFinished, isHandled, removeHeader, sendError, sendError, sendRedirect, setContentLength, setDateHeader, setHeader, setIntHeader, setLocale, setStatusMethods inherited from class rife.engine.AbstractResponse
clearBuffer, close, enableTextBuffer, flush, getLastElement, getOutputStream, getRequest, isContentTypeSet, isTextBufferEnabled, markOutputStarted, print, print, setContentType, setLastElement
-
Method Details
-
getTemplate
Retrieves the template instance that was printed to the response.This is also the template when only one of its blocks was printed, as
Context.printBlock(rife.template.Template, java.lang.String)andContext.printHtmxFragment(rife.template.Template, java.lang.String)do for an htmx request.- Returns:
- the template instance that was printed to the response; or
nullif 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:
-
getEvents
Retrieves the content of this response as parsed server-sent events (SSE).The text of the response will be interpreted according to the
text/event-streamwire format. Events are separated by blank lines, the multipledatafields of a single event are joined by line feeds, and the comment lines are captured as well, so that the events that only consist of comments, like keep-alive heartbeats, are represented too.- Returns:
- the list of events that were sent to this response
- Since:
- 1.10
- See Also:
-
sseEventSent
Description copied from class:AbstractResponseNotifies that a server-sent event was written to this response.This method does nothing by default and is intended for testing infrastructure that wants to capture the state of the events that were sent, like the out-of-container testing API does.
- Overrides:
sseEventSentin classAbstractResponse- Parameters:
template- the processed template that provided the event data; ornullwhen the event didn't use a template
-
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:ResponsePrints the content of a template to the request text output.- Specified by:
printin interfaceResponse- Overrides:
printin classAbstractResponse- Parameters:
template- the template that will be printed- Throws:
EngineException- if an error occurs during the output of the template content- See Also:
-
printBlock
Description copied from interface:ResponsePrints the content of one block of a template to the request text output.- Parameters:
template- the template whose block will be printedblockId- the id of the block that will be printed- Throws:
EngineException- if an error occurs during the output of the block content- See Also:
-
addCookie
Description copied from interface:Response- Specified by:
addCookiein interfaceResponse- Overrides:
addCookiein classSiteResponse
-
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
-