|
Last update : August 31 2002
Doc for : v1.4.1
About
What is Cactus ?
News
Changes
Features/Status
Goals
Roadmap/Todo
Contributors
Contributing
Cactus Users
Tested on ...
License
Downloads
Downloads
Documentation
How it works ?
Getting Started
Mock vs Container
Javadocs
FAQ
Howto Guides
Classpath Howto
Config Howto
Migration Howto
TestCase Howto
Jsp Howto
Runner Howto
Security Howto
Ant Howto
HttpUnit Howto
Sample Howto
EJB Howto
IDE Howto
Tomcat Howto
JUnitEE Howto
Support
Bug database
Mailing list
Misc.
Why the name ?
Logo Challenge
Resources
Test Coverage
Stats
Developers
CVS
Coding Conventions
Build results
Release Checklist
|
HttpUnit integration |
 |
The HttpUnit integration is only available for Cactus v1.2 and
later. It won't work with version 1.1 and earlier.
|
Cactus test cases allow to assert the results of the returned server
output stream in an endXXX() method (where XXX
is the name of your test case).
Cactus proposes 2 ways of writing your endXXX() methods,
-
Method 1 : it allows you to do simple check on the
returned stream like checking for returned cookies, HTTP headers and
to do assertions on the returned content as a String,
-
Method 2 : it allows you to do complex and
powerful assertions on the returned content. For example, you can
get an HTML DOM view of your returned HTML page and check that a given
named table has the correct number of columns, ....
Method 2 is supported through the integration with
HttpUnit, meaning
you'll benefit from the full assertion power of HttpUnit in your
endXXX() method. Method 1 is a class provided by Cactus.
Depending on your need you can choose, on a per test case basis, the
method you want to use.
|
Usage |
The signature of an endXXX() method is always :
public void endXXX(WebResponse theResponse)
{
[...]
}
|
The WebResponse object is passed by the Cactus framework
to your endXXX() method. What changes between the 2
methods described above is the class of the WebResponse
object that is passed :
-
org.apache.cactus.WebResponse for Method 1,
-
com.meterware.httpunit.WebResponse for Method 2
(HttpUnit)
Method 1 : Cactus provided WebResponse object |
An example :
public void endXXX(org.apache.cactus.WebResponse theResponse)
{
// Get the returned cookies
Hashtable cookies = theResponse.getCookies();
// Get the returned content as a string
String content = theResponse.getText();
// Do some asserts
assertEquals(content, "<html><body><h1>Hello world!</h1></body></html>");
[...]
}
|
 |
For the complete list of all methods available on the
WebResponse object, see the associated Javadoc.
|
|
Method 2 : HttpUnit provided WebResponse object |
An example :
public void endXXX(com.meterware.httpunit.WebResponse theResponse)
{
WebTable table = theResponse.getTables()[0];
assertEquals("rows", 4, table.getRowCount());
assertEquals("columns", 3, table.getColumnCount());
assertEquals("links", 1, table.getTableCell(0, 2).getLinks().length);
[...]
}
|
 |
For the complete list of all methods available on the
HttpUnit WebResponse object, see the HttpUnit
documentation.
|
|
|
|
|