com.uwyn.rife.test
Class MockResponse

java.lang.Object
  extended by com.uwyn.rife.engine.AbstractResponse
      extended by com.uwyn.rife.test.MockResponse
All Implemented Interfaces:
Response

public class MockResponse
extends AbstractResponse

Provides a Response implementation that is suitable for testing a web application outside of a servlet container.

Since:
1.1
Version:
$Revision: 3669 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)

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

getLastElementInfo

public ElementInfo getLastElementInfo()
Retrieves the ElementInfo of the element that was last processed with this response.

Returns:
the ElementInfo of the last element
Since:
1.1
See Also:
AbstractResponse.getLastElement(), getLastElementId()

getLastElementId

public String getLastElementId()
Retrieves the identifier of the element that was last processed with this response.

Returns:
the identifier of the last element
Since:
1.1
See Also:
AbstractResponse.getLastElement(), getLastElementInfo()

getBytes

public byte[] getBytes()
Retrieves the an array of all the bytes that have been written to this reponse.

Returns:
an array of bytes with the response content
Since:
1.1
See Also:
getText(), getTemplate(), getParsedHtml()

getText

public String getText()
Retrieves the content of this reponse as text.

Returns:
the response content as text
Since:
1.1
See Also:
getBytes(), getTemplate(), getParsedHtml()

getTemplate

public Template 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.1
See Also:
getBytes(), getText(), getParsedHtml()

getParsedHtml

public ParsedHtml getParsedHtml()
                         throws IOException,
                                SAXException
Retrieves the content of this reponse as parsed HTML.

Returns:
the response content as parsed HTML
Throws:
IOException - when exception occured during the retrieval on the response content
SAXException - when exception occured during the parsing of the content as HTML
Since:
1.1
See Also:
getBytes(), getText(), getTemplate()

getContentType

public String getContentType()
Description copied from interface: Response
Retrieves the content type that was explicitly set for this response.

Specified by:
getContentType in interface Response
Overrides:
getContentType in class AbstractResponse
Returns:
the content type as a String; or

null if the content type wasn't set

See Also:
Response.setContentType(java.lang.String)

xpathNodeSet

public NodeList xpathNodeSet(String expression)
                      throws XPathExpressionException
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.1
See Also:
xpathNode(String), xpathString(String), xpathBoolean(String), xpathNumber(String)

xpathNode

public Node xpathNode(String expression)
               throws XPathExpressionException
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.1
See Also:
xpathNodeSet(String), xpathString(String), xpathBoolean(String), xpathNumber(String)

xpathString

public String xpathString(String expression)
                   throws XPathExpressionException
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.1
See Also:
xpathNodeSet(String), xpathNode(String), xpathBoolean(String), xpathNumber(String)

xpathBoolean

public Boolean xpathBoolean(String expression)
                     throws XPathExpressionException
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.1
See Also:
xpathNodeSet(String), xpathNode(String), xpathString(String), xpathNumber(String)

xpathNumber

public Double xpathNumber(String expression)
                   throws XPathExpressionException
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.1
See Also:
xpathNodeSet(String), xpathNode(String), xpathString(String), xpathBoolean(String)

xpathNodeSet

public NodeList xpathNodeSet(String expression,
                             Object context)
                      throws XPathExpressionException
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.2
See Also:
xpathNode(String, Object), xpathString(String, Object), xpathBoolean(String, Object), xpathNumber(String, Object)

xpathNode

public Node xpathNode(String expression,
                      Object context)
               throws XPathExpressionException
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.2
See Also:
xpathNodeSet(String, Object), xpathString(String, Object), xpathBoolean(String, Object), xpathNumber(String, Object)

xpathString

public String xpathString(String expression,
                          Object context)
                   throws XPathExpressionException
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.2
See Also:
xpathNodeSet(String, Object), xpathNode(String, Object), xpathBoolean(String, Object), xpathNumber(String, Object)

xpathBoolean

public Boolean xpathBoolean(String expression,
                            Object context)
                     throws XPathExpressionException
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.2
See Also:
xpathNodeSet(String, Object), xpathNode(String, Object), xpathString(String, Object), xpathNumber(String, Object)

xpathNumber

public Double xpathNumber(String expression,
                          Object context)
                   throws XPathExpressionException
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.2
See Also:
xpathNodeSet(String, Object), xpathNode(String, Object), xpathString(String, Object), xpathBoolean(String, Object)

validateAsXml

public void validateAsXml()
                   throws InvalidXmlException
Validates the response as an XML document.

Throws:
InvalidXmlException - when the XML document isn't valid
Since:
1.2

print

public void print(Template template)
           throws EngineException
Description copied from interface: Response
Prints the content of a template to the request text output.

Specified by:
print in interface Response
Overrides:
print in 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:
Response.print(Collection), Response.print(Object)

_setContentType

protected void _setContentType(String contentType)
Description copied from class: AbstractResponse
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.

Specified by:
_setContentType in class AbstractResponse
See Also:
Response.setContentType(String)

_getCharacterEncoding

protected String _getCharacterEncoding()
Description copied from class: AbstractResponse
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.

Specified by:
_getCharacterEncoding in class AbstractResponse
See Also:
Response.getCharacterEncoding()

_setContentLength

protected void _setContentLength(int length)
Description copied from class: AbstractResponse
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.

Specified by:
_setContentLength in class AbstractResponse
See Also:
Response.setContentLength(int)

_sendRedirect

protected void _sendRedirect(String location)
Description copied from class: AbstractResponse
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.

Specified by:
_sendRedirect in class AbstractResponse
See Also:
Response.sendRedirect(String)

_getOutputStream

protected OutputStream _getOutputStream()
                                 throws IOException
Description copied from class: AbstractResponse
This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE-specific additional behaviour. It behaves exactly like its counter-part in the Request interface.

Specified by:
_getOutputStream in class AbstractResponse
Throws:
IOException
See Also:
Response.getOutputStream()

createEmbeddedResponse

public Response createEmbeddedResponse(String valueId,
                                       String differentiator)
Description copied from interface: Response
Creates a new Response instance that will be used for embedded elements.

Parameters:
valueId - the template value in which the embedded element will be processed
differentiator - the embedded element differentiator
Returns:
the new Response instance for embedded use

addCookie

public void addCookie(Cookie cookie)
Description copied from interface: Response
See HttpServletResponse.addCookie(Cookie).


getEmbeddedResponses

public List<MockResponse> getEmbeddedResponses()
Retrieves the embedded responses that were processed.

Returns:
the collection of embedded responses; or

an empty collection if no embedded elements were processed

Since:
1.4

getEmbeddedResponse

public MockResponse getEmbeddedResponse(String valueId)
Retrieves the embedded response that corresponds to a specific value in the embedding template.

Parameters:
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
Returns:
the embedded responses that corresponds to the value; or

null if no such value could be found

Since:
1.4

getNewCookieNames

public List<String> getNewCookieNames()
Retrieves the list of cookies that have been added in this reponse.

Returns:
the list of added cookies; or

an empty list if no cookies have been added

Since:
1.1

getDateHeader

public long getDateHeader(String name)
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 an IllegalArgumentException.

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.1

getHeader

public String getHeader(String name)
Returns the value of the specified response header as a 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.

Parameters:
name - the name of the header
Returns:
a String containing the value of the response header; or

null if the response does not have a header of that name

Since:
1.1

getHeaderNames

public Collection getHeaderNames()
Returns the value of the specified response header as a 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.

Returns:
a Collection of all the header names sent with this response; or

if the response has no headers, an empty Collection

Since:
1.1

getHeaders

public Collection getHeaders(String name)
Returns all the values of the specified response header as an 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.

Parameters:
name - the name of the header
Returns:
a Collection containing the values of the response header; or

if the response does not have any headers of that name return an empty Collection

Since:
1.1

getIntHeader

public int getIntHeader(String name)
Returns the value of the specified response header as an 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.

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 an int
Since:
1.1

addHeader

public void addHeader(String name,
                      String value)
Description copied from interface: Response
See HttpServletResponse.addHeader(String, String).


addDateHeader

public void addDateHeader(String name,
                          long date)
Description copied from interface: Response
See HttpServletResponse.addDateHeader(String, long).


addIntHeader

public void addIntHeader(String name,
                         int integer)
Description copied from interface: Response
See HttpServletResponse.addIntHeader(String, int).


containsHeader

public boolean containsHeader(String name)
Description copied from interface: Response
See HttpServletResponse.containsHeader(String).


setDateHeader

public void setDateHeader(String name,
                          long date)
Description copied from interface: Response
See HttpServletResponse.setDateHeader(String, long).


setHeader

public void setHeader(String name,
                      String value)
Description copied from interface: Response
See HttpServletResponse.setHeader(String, String).


setIntHeader

public void setIntHeader(String name,
                         int value)
Description copied from interface: Response
See HttpServletResponse.setIntHeader(String, int).


removeHeader

public void removeHeader(String name)
Removes a response header with the given name.

Parameters:
name - the name of the header to remove
Since:
1.1

getStatus

public int getStatus()
Returns the status code of this response.

Returns:
an integer expressing the status code of this response
Since:
1.2

getReason

public String getReason()
Returns the error reason of this response.

Returns:
an String expressing the reason of this response error
Since:
1.2

setStatus

public void setStatus(int statusCode)
Description copied from interface: Response
See HttpServletResponse.setStatus(int).


sendError

public void sendError(int statusCode)
               throws EngineException
Description copied from interface: Response
See HttpServletResponse.sendError(int).

Throws:
EngineException

sendError

public void sendError(int statusCode,
                      String message)
               throws EngineException
Description copied from interface: Response
See HttpServletResponse.sendError(int, String).

Throws:
EngineException

encodeURL

public String encodeURL(String url)
Description copied from interface: Response
See HttpServletResponse.encodeURL(String).


setLocale

public void setLocale(Locale locale)
Description copied from interface: Response
See ServletResponse.setLocale(Locale).


getLocale

public Locale getLocale()
Description copied from interface: Response
See ServletResponse.getLocale().


getWriter

public PrintWriter getWriter()
                      throws IOException
Description copied from interface: Response
See ServletResponse.getWriter().

Throws:
IOException

getHttpServletResponse

public HttpServletResponse getHttpServletResponse()
Description copied from interface: Response
Retrieves the underlying HttpServletResponse.

Returns:
the underlying HttpServletResponse instance; or

null if this response isn't backed by HttpServletResponse



Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.