Class MockResponse
- All Implemented Interfaces:
- Response
Response implementation that is suitable for testing a
 web application outside a servlet container.- Since:
- 1.0
- 
Field SummaryFields inherited from class rife.engine.AbstractResponsegzipByteOutputStream_, gzipOutputStream_, lastElement_, outputStream_, responseOutputStream_, textBuffer_, textBufferEnabled_
- 
Method SummaryModifier and TypeMethodDescriptionprotected OutputStreamThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring 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 byAbstractResponseduring the RIFE2-specific additional behaviour.voidvoidaddDateHeader(String name, long date) voidvoidaddIntHeader(String name, int integer) booleancontainsHeader(String name) byte[]getBytes()Retrieves an array of all the bytes that have been written to this response.intRetrieves the content type that was explicitly set for this response.longgetDateHeader(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 anCollectionofStringobjects.Retrieves the underlyingHttpServletResponse.intgetIntHeader(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.intReturns 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.voidPrints the content of a template to the request text output.voidremoveHeader(String name) Removes a response header with the given name.voidsendError(int statusCode) voidvoidsendRedirect(String location) voidsetContentLength(int length) voidsetDateHeader(String name, long date) voidvoidsetIntHeader(String name, int value) voidvoidsetStatus(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.AbstractResponseclearBuffer, close, enableTextBuffer, flush, getLastElement, getOutputStream, getRequest, isContentTypeSet, isTextBufferEnabled, print, print, setContentType, setLastElement
- 
Method Details- 
getBytespublic 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:
 
- 
getTextRetrieves the content of this response as text.- Returns:
- the response content as text
- Since:
- 1.0
- See Also:
 
- 
getTemplateRetrieves the template instance that was printed to the response.- Returns:
- the template instance that was printed to the response; or
 nullof no template was printed to the response
- Since:
- 1.0
- See Also:
 
- 
getParsedHtmlRetrieves the content of this response as parsed HTML.- Returns:
- the response content as parsed HTML
- Since:
- 1.0
- See Also:
 
- 
getContentTypeDescription copied from interface:ResponseRetrieves the content type that was explicitly set for this response.- Specified by:
- getContentTypein interface- Response
- Overrides:
- getContentTypein class- AbstractResponse
- Returns:
- the content type as a String; or
 nullif the content type wasn't set
- See Also:
 
- 
xpathNodeSetEvaluate 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:
 
- 
xpathNodeEvaluate 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:
 
- 
xpathStringEvaluate 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:
 
- 
xpathBooleanEvaluate 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:
 
- 
xpathNumberEvaluate 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:
 
- 
xpathNodeSetEvaluate 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:
 
- 
xpathNodeEvaluate 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:
 
- 
xpathStringEvaluate 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:
 
- 
xpathBooleanEvaluate 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:
 
- 
xpathNumberEvaluate 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:
 
- 
printDescription copied from interface:ResponsePrints the content of a template to the request text output.- Specified by:
- printin interface- Response
- Overrides:
- printin class- AbstractResponse
- Parameters:
- template- the template that will be printed
- Throws:
- EngineException- if an error occurs during the output of the template content
- See Also:
 
- 
_setContentTypeDescription copied from class:AbstractResponseThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Response interface.- Specified by:
- _setContentTypein class- AbstractResponse
- See Also:
 
- 
getCharacterEncodingDescription copied from interface:Response
- 
setContentLengthpublic void setContentLength(int length) Description copied from interface:Response
- 
getContentLengthpublic int getContentLength()
- 
sendRedirectDescription copied from interface:Response
- 
_getOutputStreamDescription copied from class:AbstractResponseThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Request interface.- Specified by:
- _getOutputStreamin class- AbstractResponse
- See Also:
 
- 
addCookieDescription copied from interface:Response
- 
getNewCookieNamesRetrieves 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
 
- 
getDateHeaderReturns 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 longvalue representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT; or-1if 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
 
- 
getHeaderReturns 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 Stringcontaining the value of the response header; ornullif the response does not have a header of that name
- Since:
- 1.0
 
- 
getHeaderNamesReturns 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 Collectionof all the header names sent with this response; orif the response has no headers, an empty Collection
- Since:
- 1.0
 
- 
getHeadersReturns all the values of the specified response header as anCollectionofStringobjects.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 Collectioncontaining the values of the response header; orif the response does not have any headers of that name return an empty Collection
- Since:
- 1.0
 
- 
getIntHeaderReturns 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 integerexpressing the value of the response header; or-1if the response doesn't have a header of this name
- Throws:
- NumberFormatException- if the header value can't be converted to an- int
- Since:
- 1.0
 
- 
addHeaderDescription copied from interface:Response
- 
addDateHeaderDescription copied from interface:Response
- 
addIntHeaderDescription copied from interface:Response
- 
containsHeaderDescription copied from interface:Response
- 
setDateHeaderDescription copied from interface:Response
- 
setHeaderDescription copied from interface:Response
- 
setIntHeaderDescription copied from interface:Response
- 
removeHeaderRemoves a response header with the given name.- Parameters:
- name- the name of the header to remove
- Since:
- 1.0
 
- 
getStatuspublic int getStatus()Returns the status code of this response.- Returns:
- an integerexpressing the status code of this response
- Since:
- 1.0
 
- 
getReasonReturns the error reason of this response.- Returns:
- an Stringexpressing the reason of this response error
- Since:
- 1.0
 
- 
setStatuspublic void setStatus(int statusCode) Description copied from interface:Response
- 
sendErrorDescription copied from interface:Response- Throws:
- EngineException
 
- 
sendErrorDescription copied from interface:Response- Throws:
- EngineException
 
- 
encodeURLDescription copied from interface:Response
- 
setLocaleDescription copied from interface:Response
- 
getLocaleDescription copied from interface:Response
- 
getWriterDescription copied from interface:Response- Throws:
- IOException
 
- 
getHttpServletResponseDescription copied from interface:ResponseRetrieves the underlyingHttpServletResponse.- Returns:
- the underlying HttpServletResponseinstance; ornullif this response isn't backed byHttpServletResponse
 
 
-