|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.engine.AbstractResponse
com.uwyn.rife.test.MockResponse
public class MockResponse
Provides a Response implementation that is suitable for testing a
web application outside of a servlet container.
| Method Summary | |
|---|---|
protected String |
_getCharacterEncoding()
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the
RIFE-specific additional behaviour. |
protected OutputStream |
_getOutputStream()
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the
RIFE-specific additional behaviour. |
protected void |
_sendRedirect(String location)
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the
RIFE-specific additional behaviour. |
protected void |
_setContentLength(int length)
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the
RIFE-specific additional behaviour. |
protected void |
_setContentType(String contentType)
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the
RIFE-specific additional behaviour. |
void |
addCookie(Cookie cookie)
See HttpServletResponse.addCookie(Cookie). |
void |
addDateHeader(String name,
long date)
See HttpServletResponse.addDateHeader(String, long). |
void |
addHeader(String name,
String value)
See HttpServletResponse.addHeader(String, String). |
void |
addIntHeader(String name,
int integer)
See HttpServletResponse.addIntHeader(String, int). |
boolean |
containsHeader(String name)
See HttpServletResponse.containsHeader(String). |
Response |
createEmbeddedResponse(String valueId,
String differentiator)
Creates a new Response instance that will be used for
embedded elements. |
String |
encodeURL(String url)
See HttpServletResponse.encodeURL(String). |
byte[] |
getBytes()
Retrieves the an array of all the bytes that have been written to this reponse. |
String |
getContentType()
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. |
MockResponse |
getEmbeddedResponse(String valueId)
Retrieves the embedded response that corresponds to a specific value in the embedding template. |
List<MockResponse> |
getEmbeddedResponses()
Retrieves the embedded responses that were processed. |
String |
getHeader(String name)
Returns the value of the specified response header as a String. |
Collection |
getHeaderNames()
Returns the value of the specified response header as a String. |
Collection |
getHeaders(String name)
Returns all the values of the specified response header as an Collection of String objects. |
HttpServletResponse |
getHttpServletResponse()
Retrieves the underlying HttpServletResponse. |
int |
getIntHeader(String name)
Returns the value of the specified response header as an int. |
String |
getLastElementId()
Retrieves the identifier of the element that was last processed with this response. |
ElementInfo |
getLastElementInfo()
Retrieves the ElementInfo of the element that was last
processed with this response. |
Locale |
getLocale()
See ServletResponse.getLocale(). |
List<String> |
getNewCookieNames()
Retrieves the list of cookies that have been added in this reponse. |
ParsedHtml |
getParsedHtml()
Retrieves the content of this reponse as parsed HTML. |
String |
getReason()
Returns the error reason of this response. |
int |
getStatus()
Returns the status code of this response. |
Template |
getTemplate()
Retrieves the template instance that was printed to the response. |
String |
getText()
Retrieves the content of this reponse as text. |
PrintWriter |
getWriter()
See ServletResponse.getWriter(). |
void |
print(Template template)
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)
See HttpServletResponse.sendError(int). |
void |
sendError(int statusCode,
String message)
See HttpServletResponse.sendError(int, String). |
void |
setDateHeader(String name,
long date)
See HttpServletResponse.setDateHeader(String, long). |
void |
setHeader(String name,
String value)
See HttpServletResponse.setHeader(String, String). |
void |
setIntHeader(String name,
int value)
See HttpServletResponse.setIntHeader(String, int). |
void |
setLocale(Locale locale)
See ServletResponse.setLocale(Locale). |
void |
setStatus(int statusCode)
See HttpServletResponse.setStatus(int). |
void |
validateAsXml()
Validates the response as an XML document. |
Boolean |
xpathBoolean(String expression)
Evaluate an XPath expression in the context of the response text and return the result as a boolean. |
Boolean |
xpathBoolean(String expression,
Object context)
Evaluate an XPath expression in the provided context object and return the result as a boolean. |
Node |
xpathNode(String expression)
Evaluate an XPath expression in the context of the response text and return the result as a DOM node. |
Node |
xpathNode(String expression,
Object context)
Evaluate an XPath expression in the provided context object and return the result as a DOM node. |
NodeList |
xpathNodeSet(String expression)
Evaluate an XPath expression in the context of the response text and return the result as a list of DOM nodes. |
NodeList |
xpathNodeSet(String expression,
Object context)
Evaluate an XPath expression in the provided context object and return the result as a list of DOM nodes. |
Double |
xpathNumber(String expression)
Evaluate an XPath expression in the context of the response text and return the result as a number. |
Double |
xpathNumber(String expression,
Object context)
Evaluate an XPath expression in the provided context object and return the result as a number. |
String |
xpathString(String expression)
Evaluate an XPath expression in the context of the response text and return the result as a string. |
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 com.uwyn.rife.engine.AbstractResponse |
|---|
clearBuffer, close, enableTextBuffer, flush, getCharacterEncoding, getEmbeddedContent, getLastElement, getOutputStream, getRequest, isContentTypeSet, isEmbedded, isTextBufferEnabled, print, print, sendRedirect, setContentLength, setContentType, setLastElement |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public ElementInfo getLastElementInfo()
ElementInfo of the element that was last
processed with this response.
ElementInfo of the last elementAbstractResponse.getLastElement(),
getLastElementId()public String getLastElementId()
AbstractResponse.getLastElement(),
getLastElementInfo()public byte[] getBytes()
getText(),
getTemplate(),
getParsedHtml()public String getText()
getBytes(),
getTemplate(),
getParsedHtml()public Template getTemplate()
null of no template was printed to the response
getBytes(),
getText(),
getParsedHtml()
public ParsedHtml getParsedHtml()
throws IOException,
SAXException
IOException - when exception occured during the retrieval on
the response content
SAXException - when exception occured during the parsing of
the content as HTMLgetBytes(),
getText(),
getTemplate()public String getContentType()
Response
getContentType in interface ResponsegetContentType in class AbstractResponsenull if the content type wasn't set
Response.setContentType(java.lang.String)
public NodeList xpathNodeSet(String expression)
throws XPathExpressionException
More information about XPath can be found in the original specification or in this tutorial.
NodeList
XPathExpressionException - if expression cannot be evaluated.xpathNode(String),
xpathString(String),
xpathBoolean(String),
xpathNumber(String)
public Node xpathNode(String expression)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String),
xpathString(String),
xpathBoolean(String),
xpathNumber(String)
public String xpathString(String expression)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String),
xpathNode(String),
xpathBoolean(String),
xpathNumber(String)
public Boolean xpathBoolean(String expression)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String),
xpathNode(String),
xpathString(String),
xpathNumber(String)
public Double xpathNumber(String expression)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String),
xpathNode(String),
xpathString(String),
xpathBoolean(String)
public NodeList xpathNodeSet(String expression,
Object context)
throws XPathExpressionException
More information about XPath can be found in the original specification or in this tutorial.
NodeList
XPathExpressionException - if expression cannot be evaluated.xpathNode(String, Object),
xpathString(String, Object),
xpathBoolean(String, Object),
xpathNumber(String, Object)
public Node xpathNode(String expression,
Object context)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String, Object),
xpathString(String, Object),
xpathBoolean(String, Object),
xpathNumber(String, Object)
public String xpathString(String expression,
Object context)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String, Object),
xpathNode(String, Object),
xpathBoolean(String, Object),
xpathNumber(String, Object)
public Boolean xpathBoolean(String expression,
Object context)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String, Object),
xpathNode(String, Object),
xpathString(String, Object),
xpathNumber(String, Object)
public Double xpathNumber(String expression,
Object context)
throws XPathExpressionException
Node
XPathExpressionException - if expression cannot be evaluated.xpathNodeSet(String, Object),
xpathNode(String, Object),
xpathString(String, Object),
xpathBoolean(String, Object)
public void validateAsXml()
throws InvalidXmlException
InvalidXmlException - when the XML document isn't valid
public void print(Template template)
throws EngineException
Response
print in interface Responseprint in class AbstractResponsetemplate - the template that will be printed
EngineException - if an error
occurs during the output of the template contentResponse.print(Collection),
Response.print(Object)protected void _setContentType(String contentType)
AbstractResponseAbstractResponse during the
RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.
_setContentType in class AbstractResponseResponse.setContentType(String)protected String _getCharacterEncoding()
AbstractResponseAbstractResponse during the
RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.
_getCharacterEncoding in class AbstractResponseResponse.getCharacterEncoding()protected void _setContentLength(int length)
AbstractResponseAbstractResponse during the
RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.
_setContentLength in class AbstractResponseResponse.setContentLength(int)protected void _sendRedirect(String location)
AbstractResponseAbstractResponse during the
RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.
_sendRedirect in class AbstractResponseResponse.sendRedirect(String)
protected OutputStream _getOutputStream()
throws IOException
AbstractResponseAbstractResponse during the
RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Request interface.
_getOutputStream in class AbstractResponseIOExceptionResponse.getOutputStream()
public Response createEmbeddedResponse(String valueId,
String differentiator)
ResponseResponse instance that will be used for
embedded elements.
valueId - the template value in which the embedded element will
be processeddifferentiator - the embedded element differentiator
Response instance for embedded usepublic void addCookie(Cookie cookie)
ResponseHttpServletResponse.addCookie(Cookie).
public List<MockResponse> getEmbeddedResponses()
an empty collection if no embedded elements were processed
public MockResponse getEmbeddedResponse(String valueId)
valueId - the template value in which the embedded element has
been processed, the "ELEMENT:" prefix is optional and will be
automatically added if you leave it off
null if no such value could be found
public List<String> getNewCookieNames()
an empty list if no cookies have been added
public long getDateHeader(String name)
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 an IllegalArgumentException.
name - the name of the header
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
IllegalArgumentException - if the header value can't
be converted to a datepublic String getHeader(String name)
String. If the reponse did not include a header of the
specified name, this method returns null. The header name
is case insensitive. You can use this method with any response header.
name - the name of the header
String containing the value of the response
header; or
null if the response does not have a header of that
name
public Collection getHeaderNames()
String. If the reponse did not include a header of the
specified name, this method returns null. The header name
is case insensitive. You can use this method with any response header.
Collection of all the header names sent with
this response; or
if the response has no headers, an empty Collection
public Collection getHeaders(String name)
Collection of String 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.
name - the name of the header
Collection containing the values of the response
header; or
if the response does not have any headers of that name return an
empty Collection
public int getIntHeader(String name)
int. If the response does not have a header of the
specified name, this method returns -1. If the header
cannot be converted to an integer, this method throws a
NumberFormatException.
The header name is case insensitive.
name - the name of the header
integer expressing the value of the response
header; or
-1 if the response doesn't have a header of this name
NumberFormatException - if the header value can't be
converted to an int
public void addHeader(String name,
String value)
ResponseHttpServletResponse.addHeader(String, String).
public void addDateHeader(String name,
long date)
ResponseHttpServletResponse.addDateHeader(String, long).
public void addIntHeader(String name,
int integer)
ResponseHttpServletResponse.addIntHeader(String, int).
public boolean containsHeader(String name)
ResponseHttpServletResponse.containsHeader(String).
public void setDateHeader(String name,
long date)
ResponseHttpServletResponse.setDateHeader(String, long).
public void setHeader(String name,
String value)
ResponseHttpServletResponse.setHeader(String, String).
public void setIntHeader(String name,
int value)
ResponseHttpServletResponse.setIntHeader(String, int).
public void removeHeader(String name)
name - the name of the header to removepublic int getStatus()
integer expressing the status code of this
responsepublic String getReason()
String expressing the reason of this response errorpublic void setStatus(int statusCode)
ResponseHttpServletResponse.setStatus(int).
public void sendError(int statusCode)
throws EngineException
ResponseHttpServletResponse.sendError(int).
EngineException
public void sendError(int statusCode,
String message)
throws EngineException
ResponseHttpServletResponse.sendError(int, String).
EngineExceptionpublic String encodeURL(String url)
ResponseHttpServletResponse.encodeURL(String).
public void setLocale(Locale locale)
ResponseServletResponse.setLocale(Locale).
public Locale getLocale()
ResponseServletResponse.getLocale().
public PrintWriter getWriter()
throws IOException
ResponseServletResponse.getWriter().
IOExceptionpublic HttpServletResponse getHttpServletResponse()
ResponseHttpServletResponse.
HttpServletResponse instance; or
null if this response isn't backed by
HttpServletResponse
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||