webapplicationtestcase
Class HttpResponse

java.lang.Object
  extended by webapplicationtestcase.HttpResponse

public class HttpResponse
extends java.lang.Object

This class represents an http response from the web application.

Version:
1.0
Author:
Jason Edwards

Constructor Summary
HttpResponse()
           
 
Method Summary
 boolean containsTag(java.lang.String tagName, java.util.Map attributes, java.lang.String text)
          Determines if a tag is contained in the content of the response.
 java.lang.String getContent()
          Accessor for the content of the response.
 java.lang.String getContentType()
          Accessor for the content type of the response.
 java.util.Map getHeaderFields()
          A map of the response headers.
 java.util.List getNodes()
          The parsed nodes of the response.
 int getStatus()
          Accessor for the http response status code.
 Tag[] getTagsByName(java.lang.String tagName)
          Finds tags contained in the response (html only) by name.
static boolean isStatusRedirect(int status)
          Determines if the http status code is a redirect.
 void setContent(java.lang.String contentType, java.lang.String content)
          Setter for the content of the response.
 void setHeaderFields(java.util.Map headerFields)
          Sets the header fields for this response.
 void setStatus(int status)
          Setter for the http response status code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResponse

public HttpResponse()
Method Detail

isStatusRedirect

public static boolean isStatusRedirect(int status)
Determines if the http status code is a redirect. Http status codes of 3xx are considered to be redirects.

Parameters:
status - the status to evaluate.
Returns:
true if status is a redirect, false otherwise.

getContentType

public java.lang.String getContentType()
Accessor for the content type of the response.

Returns:
the content type of the response

getHeaderFields

public java.util.Map getHeaderFields()
A map of the response headers. Usually, this map is taken directly from the HttpURLConnection.getHeaderFields(), so the keys are java.lang.Strings and the value is an unmodifiable java.util.List of java.lang.Strings.

Returns:
A map of the header fields of the response.
See Also:
URLConnection.getHeaderFields()

setHeaderFields

public void setHeaderFields(java.util.Map headerFields)
Sets the header fields for this response. The map should use java.lang.Strings for the keys, and a java.util.List of java.lang.Strings for the values.

Parameters:
headerFields - a map of header fields to set for this response

getStatus

public int getStatus()
Accessor for the http response status code.

Returns:
the http response status code for this response.

setStatus

public void setStatus(int status)
Setter for the http response status code.

Parameters:
status - the http response code for this response.

getContent

public java.lang.String getContent()
Accessor for the content of the response.

Returns:
a String containing the content.

setContent

public void setContent(java.lang.String contentType,
                       java.lang.String content)
Setter for the content of the response. If the content type is "text/html", the content will be parsed.

Parameters:
contentType - the content type of the response, e.g. "text/html" or "text/xml"
content - a String containing the content of the response

containsTag

public boolean containsTag(java.lang.String tagName,
                           java.util.Map attributes,
                           java.lang.String text)
Determines if a tag is contained in the content of the response.

Note: this only works if the content type is 'text/html'. XML and other types of content are not parsed.

Parameters:
tagName - the name of the tag to find, e.g. "span", "div", "img", "a", "p"
attributes - a map of the attributes
text - a String containing the text to find
Returns:
true if a tag, or text, is found, false otherwise

getTagsByName

public Tag[] getTagsByName(java.lang.String tagName)
Finds tags contained in the response (html only) by name. For example if you wanted all the anchor tags in the response, you would call getTagsByName("a");.

Parameters:
tagName - the name of tags to find, e.g. "span", "div", "a"
Returns:
an Array of Tags with the name specified, the array will be empty if none are found.

getNodes

public java.util.List getNodes()
The parsed nodes of the response. All elements will be either Strings or Tags. String represent text nodes.

Returns:
a List of the nodes of the response.