com.netriser.xmltestsuite
Class HttpResource

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--com.netriser.xmltestsuite.TestResource
              |
              +--com.netriser.xmltestsuite.HttpResource
All Implemented Interfaces:
TestResourceInterface

public class HttpResource
extends TestResource

Provides http and file resources to test objects. Test objects can make http requests and analyse responses.

This class provides a facade to test objects which uses the httpunit and jaxen packages for much of its functionality

This class is instantiated as a singleton using a factory To obtain a instance use

 	HttpResource ResourceFactory.getHttpResource();
 

Author:
david

Constructor Summary
HttpResource()
          This class is instantiated as a singleton using a factory.
 
Method Summary
 void generatePageTemplate()
          Generates prototype XML fragment baed on the current response and the specified form.
 java.lang.String getBaseURL()
          Return the url prefix defined by the configuration file.
 com.meterware.httpunit.WebConversation getConversation()
          Returns the current WebConversation object, WebConversation implements the http requests.
 org.w3c.dom.Document getDOM()
          Returns an XML Document for the last response.
 org.w3c.dom.Document getDOM(com.meterware.httpunit.WebResponse specificResponse)
          Returns an XML Document for the specified response.
 com.meterware.httpunit.WebRequest getLastRequest()
          Return the most recent http request as a WebRequest object.
 com.meterware.httpunit.WebResponse getLastResponse()
          Return the most recent http response as a WebResponse object.
 com.meterware.httpunit.WebResponse getLastResponse(java.lang.String windowName, java.lang.String frameName)
          Return the response in the named window or frame, or, if not defined, the most recent http response, as a WebResponse object.
 com.meterware.httpunit.WebResponse getResponse(org.w3c.dom.Element testElement, java.lang.String querystring)
          Gets the response object specified by the url in the TestObject suffixed with a searchParameter.
 com.meterware.httpunit.WebResponse getResponse(java.lang.String URL, java.lang.String querystring)
          Gets the response object specified by the url suffixed with a searchParameter.
 void saveHTML(com.meterware.httpunit.WebResponse response)
           
 void setHtmlWarnings(boolean b)
           
 void setUp()
          Configures the internal, httpunit and jaxen resources.
 void submitform(org.w3c.dom.Element formElement)
          Submit a HTML form using values defined in the specified form Element in the xml configuration file.
 void tearDown()
          Tidy up the resource after the tests are run
 void validatecookies(org.w3c.dom.Element cookies)
          Validate the cookies against the test spec.
 void validatecookies(org.w3c.dom.Element cookies, com.meterware.httpunit.WebResponse response2Validate)
          Validate the cookies against the test spec.
 void validateElement(org.w3c.dom.Element element)
          Validate an element in the response against the test spec.
 void validateElement(org.w3c.dom.Element element, com.meterware.httpunit.WebResponse response2Validate)
          Validate an element in the response against the test spec.
 void validateform(org.w3c.dom.Element formElement, java.lang.String validatingAttributeName)
          Validate the form against the test spec.
 void validateframeset(org.w3c.dom.Element framesetElement)
          Validate the details of a response using the named frameset Element
 void validateframeset(org.w3c.dom.Element framesetElement, com.meterware.httpunit.WebResponse response2Validate)
          Validate the details of a response using the named frameset Element
 void validateheaders(org.w3c.dom.Element page)
          Validate the http headers and response code against the test spec.
 void validateheaders(org.w3c.dom.Element page, com.meterware.httpunit.WebResponse response2Validate)
          Validate the http headers and response code against the test spec.
 void validatelinks(org.w3c.dom.Element page)
          Recursively alidate all links on the most.recent response
 void validatelinks(org.w3c.dom.Element page, com.meterware.httpunit.WebResponse response2Validate)
          Validate all links on the specified response
 
Methods inherited from class com.netriser.xmltestsuite.TestResource
debug, getDebugMode, getVerboseMode, setDebug, setVerbose, useTestResult, verbose
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResource

public HttpResource()
This class is instantiated as a singleton using a factory. To obtain a instance use
 	HttpResource ResourceFactory.getHttpResource();
 

Method Detail

getConversation

public com.meterware.httpunit.WebConversation getConversation()
Returns the current WebConversation object, WebConversation implements the http requests. Use if you need to call any of its its methods directly.

Returns:
WebConversation

getLastRequest

public com.meterware.httpunit.WebRequest getLastRequest()
Return the most recent http request as a WebRequest object.

Returns:
WebRequest

getLastResponse

public com.meterware.httpunit.WebResponse getLastResponse()
Return the most recent http response as a WebResponse object.

Returns:
WebResponse

getLastResponse

public com.meterware.httpunit.WebResponse getLastResponse(java.lang.String windowName,
                                                          java.lang.String frameName)
Return the response in the named window or frame, or, if not defined, the most recent http response, as a WebResponse object.

Returns:
WebResponse

getBaseURL

public java.lang.String getBaseURL()
Return the url prefix defined by the configuration file. Set in the xml configuration file using:
 	<testSpec baseURL="">
 

Returns:
String

setUp

public void setUp()
Configures the internal, httpunit and jaxen resources.

Specified by:
setUp in interface TestResourceInterface
Specified by:
setUp in class TestResource
See Also:
TestResource.setUp()

tearDown

public void tearDown()
Description copied from class: TestResource
Tidy up the resource after the tests are run

Specified by:
tearDown in interface TestResourceInterface
Specified by:
tearDown in class TestResource
See Also:
TestResource.tearDown()

submitform

public void submitform(org.w3c.dom.Element formElement)
                throws NoResponseToProcess,
                       java.net.MalformedURLException,
                       java.io.IOException,
                       org.xml.sax.SAXException,
                       java.lang.Exception
Submit a HTML form using values defined in the specified form Element in the xml configuration file.

Parameters:
formElement - form Element
Returns:
Response Object
Throws:
java.net.MalformedURLException - URL Error
java.io.IOException - HTTP Error
org.xml.sax.SAXException - Error parsing HTML
java.lang.Exception - Description of Exception
NoResponseToProcess
Since:

getResponse

public com.meterware.httpunit.WebResponse getResponse(org.w3c.dom.Element testElement,
                                                      java.lang.String querystring)
Gets the response object specified by the url in the TestObject suffixed with a searchParameter. A ? is inserted in front of the search string or & if if already exists in the url,

The response is cached using the element name and can be refered to in test scripts even after subsequent requests.

Returns:
response object
Since:

getDOM

public org.w3c.dom.Document getDOM()
                            throws NoResponseToProcess,
                                   org.xml.sax.SAXException
Returns an XML Document for the last response. The Document is cached for each response to avoid regenerating unnecessarily. This method should only be used for responses with a content type of text/html or application/xml An expception will be raised of the doucment connot be parsed into an XML Document.

Returns:
Document
NoResponseToProcess
org.xml.sax.SAXException

getDOM

public org.w3c.dom.Document getDOM(com.meterware.httpunit.WebResponse specificResponse)
                            throws NoResponseToProcess,
                                   org.xml.sax.SAXException
Returns an XML Document for the specified response. The Document is cached for each response to avoid regenerating unnecessarily. This method should only be used for responses with a content type of text/html or application/xml An expception will be raised of the doucment connot be parsed into an XML Document.

Returns:
Document
NoResponseToProcess
org.xml.sax.SAXException

getResponse

public com.meterware.httpunit.WebResponse getResponse(java.lang.String URL,
                                                      java.lang.String querystring)
Gets the response object specified by the url suffixed with a searchParameter. A ? is inserted in front of the search string or & if if already exists in the url,

Parameters:
URL -
querystring -
Returns:
WebResponse

validateform

public void validateform(org.w3c.dom.Element formElement,
                         java.lang.String validatingAttributeName)
                  throws NoResponseToProcess,
                         java.net.MalformedURLException,
                         java.io.IOException,
                         org.xml.sax.SAXException
Validate the form against the test spec. Validates using validatingAttributeName so that it can validate against expected values ("value") or values used by submit form ("set")

Parameters:
formElement - form element
validatingAttributeName - "set" or "value"
Throws:
java.net.MalformedURLException - URL Error
java.io.IOException - HTTP Error
org.xml.sax.SAXException - Error parsing HTML
NoResponseToProcess
Since:

validatecookies

public void validatecookies(org.w3c.dom.Element cookies)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate the cookies against the test spec.

Throws:
java.net.MalformedURLException - URL Error
java.io.IOException - HTTP Error
org.xml.sax.SAXException - Error parsing HTML
NoResponseToProcess
Since:

validatecookies

public void validatecookies(org.w3c.dom.Element cookies,
                            com.meterware.httpunit.WebResponse response2Validate)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate the cookies against the test spec.

Parameters:
cookies -
response2Validate -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validateheaders

public void validateheaders(org.w3c.dom.Element page)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate the http headers and response code against the test spec.

Parameters:
page -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validateheaders

public void validateheaders(org.w3c.dom.Element page,
                            com.meterware.httpunit.WebResponse response2Validate)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate the http headers and response code against the test spec.

Parameters:
page -
response2Validate -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validatelinks

public void validatelinks(org.w3c.dom.Element page)
                   throws NoResponseToProcess,
                          java.net.MalformedURLException,
                          java.io.IOException,
                          org.xml.sax.SAXException
Recursively alidate all links on the most.recent response

Parameters:
page -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validatelinks

public void validatelinks(org.w3c.dom.Element page,
                          com.meterware.httpunit.WebResponse response2Validate)
                   throws NoResponseToProcess,
                          java.net.MalformedURLException,
                          java.io.IOException,
                          org.xml.sax.SAXException
Validate all links on the specified response

Parameters:
page -
response2Validate -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validateframeset

public void validateframeset(org.w3c.dom.Element framesetElement)
                      throws NoResponseToProcess,
                             java.net.MalformedURLException,
                             java.io.IOException,
                             org.xml.sax.SAXException
Validate the details of a response using the named frameset Element

Throws:
java.net.MalformedURLException - URL Error
java.io.IOException - HTTP Error
org.xml.sax.SAXException - Error parsing HTML
NoResponseToProcess
Since:

validateframeset

public void validateframeset(org.w3c.dom.Element framesetElement,
                             com.meterware.httpunit.WebResponse response2Validate)
                      throws NoResponseToProcess,
                             java.net.MalformedURLException,
                             java.io.IOException,
                             org.xml.sax.SAXException
Validate the details of a response using the named frameset Element

Parameters:
framesetElement -
response2Validate -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validateElement

public void validateElement(org.w3c.dom.Element element)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate an element in the response against the test spec. An xpath can be used to refer to any part in the response. If a value is specified, the value is matched against the content specified by the xpath Otherwise the xpath is evaluated as an expression.

Parameters:
element -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess

validateElement

public void validateElement(org.w3c.dom.Element element,
                            com.meterware.httpunit.WebResponse response2Validate)
                     throws NoResponseToProcess,
                            java.net.MalformedURLException,
                            java.io.IOException,
                            org.xml.sax.SAXException
Validate an element in the response against the test spec.

Parameters:
element -
response2Validate -
Throws:
java.net.MalformedURLException
java.io.IOException
org.xml.sax.SAXException
NoResponseToProcess
See Also:
validateElement(Element)

generatePageTemplate

public void generatePageTemplate()
                          throws NoResponseToProcess
Generates prototype XML fragment baed on the current response and the specified form. Use to generate XML for a form to avoid having to type it in by hand Hint: if possible, try to specify a form with existing data rather than a blank form.

NoResponseToProcess
Since:

setHtmlWarnings

public void setHtmlWarnings(boolean b)

saveHTML

public void saveHTML(com.meterware.httpunit.WebResponse response)