org.apache.cocoon.tools.it
Class HtmlUnitTestCase

java.lang.Object
  extended by org.apache.cocoon.tools.it.HtmlUnitTestCase

public abstract class HtmlUnitTestCase
extends Object

This class is useful as base class for JUnit TestCase classes to setup an environment which makes it possible to easily test web pages. First call one of the load methods and then assert on the response object, XML document (@see loadXmlPage), or HTML document (@see loadHtmlPage).

Version:
$Id: HtmlUnitTestCase.html 1422833 2012-12-17 10:27:16Z ilgrosso $

Field Summary
protected  Object document
          Low-level access to XML document (org.w3c.dom.Document) or HTML document (com.gargoylesoftware.htmlunit.html.HtmlPage).
protected  org.apache.commons.logging.Log log
           
protected  Map<String,String> namespaces
          Low-level access to namespace mappings for XPath expressions.
protected  com.gargoylesoftware.htmlunit.WebResponse response
          Low-level access to WebResponse object.
protected  com.gargoylesoftware.htmlunit.WebClient webClient
          Low-level access to WebClient object.
 
Constructor Summary
HtmlUnitTestCase()
           
 
Method Summary
protected  void addNamespace(String prefix, String uri)
          Add a namespace mapping for XPath expressions.
protected  void assertXPath(String xpathExpr, String expected)
          Assert that XPath expression result matches exactly expected value.
 void createClient()
           
protected  String evalXPath(String xpathExpr)
          Returns XPath expression as string.
protected  void loadDeleteResponse(String pageURL)
          Sends HTTP DELETE request and loads response object.
protected  void loadHtmlPage(String pageURL)
          Sends HTTP request and parses response as HTML document.
protected  void loadPostResponse(String pageURL, String content)
          Sends HTTP POST request and loads response object.
protected  void loadPutResponse(String pageURL, String content)
          Sends HTTP PUT request and loads response object.
protected  void loadResponse(String pageURL)
          Sends HTTP GET request and loads response object.
protected  void loadXmlPage(String pageURL)
          Sends HTTP request and parses response as XML document.
 void reset()
           
protected  URL setupBaseUrl()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

webClient

protected com.gargoylesoftware.htmlunit.WebClient webClient
Low-level access to WebClient object.


response

protected com.gargoylesoftware.htmlunit.WebResponse response
Low-level access to WebResponse object.


document

protected Object document
Low-level access to XML document (org.w3c.dom.Document) or HTML document (com.gargoylesoftware.htmlunit.html.HtmlPage).


namespaces

protected Map<String,String> namespaces
Low-level access to namespace mappings for XPath expressions.

Constructor Detail

HtmlUnitTestCase

public HtmlUnitTestCase()
Method Detail

createClient

public void createClient()
                  throws Exception
Throws:
Exception

reset

public void reset()
           throws Exception
Throws:
Exception

setupBaseUrl

protected URL setupBaseUrl()
                    throws Exception
Throws:
Exception

loadResponse

protected void loadResponse(String pageURL)
                     throws Exception
Sends HTTP GET request and loads response object.

Throws:
Exception

loadDeleteResponse

protected void loadDeleteResponse(String pageURL)
                           throws Exception
Sends HTTP DELETE request and loads response object.

Throws:
Exception

loadPutResponse

protected void loadPutResponse(String pageURL,
                               String content)
                        throws Exception
Sends HTTP PUT request and loads response object.

Throws:
Exception

loadPostResponse

protected void loadPostResponse(String pageURL,
                                String content)
                         throws Exception
Sends HTTP POST request and loads response object.

Throws:
Exception

loadHtmlPage

protected void loadHtmlPage(String pageURL)
                     throws Exception
Sends HTTP request and parses response as HTML document.

Throws:
Exception

loadXmlPage

protected void loadXmlPage(String pageURL)
                    throws Exception
Sends HTTP request and parses response as XML document.

Throws:
Exception

evalXPath

protected String evalXPath(String xpathExpr)
                    throws Exception
Returns XPath expression as string.

Parameters:
xpathExpr - XPath expression
Returns:
Value of XPath expression in current document. Empty string if XPath not matched.
Throws:
Exception

addNamespace

protected void addNamespace(String prefix,
                            String uri)
                     throws Exception
Add a namespace mapping for XPath expressions.

Throws:
Exception

assertXPath

protected void assertXPath(String xpathExpr,
                           String expected)
                    throws Exception
Assert that XPath expression result matches exactly expected value.

Throws:
Exception


Copyright © 1999-2012 The Apache Software Foundation. All Rights Reserved.