![]() | ![]() |
Apache > Jakarta > Cactus > Writing Tests | Docs for: v1.7.2 | v1.7 Last update: November 26 2008 |
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
Cactus proposes 2 ways of writing your
Method 2 is supported through the integration with
HttpUnit, meaning
you'll benefit from the full assertion power of HttpUnit in your
Depending on your need you can choose, on a per test case basis, the method you want to use. Usage
The signature of an public void endXXX(WebResponse theResponse) { [...] }
The
Method 1: Cactus provided WebResponse objectAn 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 objectAn 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.
|