Java Reference
In-Depth Information
DynaBean request1 = dynaClass.newInstance();
request1.set("id", "12345");
request1.set("responsetime", new Long(500));
results.add(request1);
C
DynaBean request2 = dynaClass.newInstance();
request2.set("id", "56789");
request2.set("responsetime", new Long(430));
results.add(request2);
return results;
}
D
public void testCallView() throws Exception {
AdminServlet servlet = new AdminServlet();
request.setAttribute("results", createCommandResult());
servlet.callView(request, response);
}
public void endCallView(com.meterware.httpunit.WebResponse response)
throws Exception {
assertTrue(response.isHTML());
[...]
assertEquals("12345",
response.getTables()[0].getCellAsText(1, 0));
assertEquals("500",
response.getTables()[0].getCellAsText(1, 1));
assertEquals("56789",
response.getTables()[0].getCellAsText(2, 0));
assertEquals("430",
response.getTables()[0].getCellAsText(2, 1));
}
}
We start by defining the createCommand method B , which puts several DynaBeans
in the request C . Then in the testCallView D method (remember that it's exe-
cuted on the server side) we instantiate the servlet to test E , set the DynaBeans in
the request E , and call the JSP F to display the result. The endCallView G ,
which is executed on the client side, has a com.meterware.httpunit.WebResponse
parameter, holding the response from the server. In H we assert different state-
ments against the response of the server, in order to verify that the JSP displays the
results properly.
We use the Cactus HttpUnit integration in the endCallView method to assert the
returned HTML page. When Cactus needs to execute the end XXX method, first it
looks for an end XXX (org.apache.cactus.WebResponse) signature. If this signature
is found, Cactus calls it; if it isn't, Cactus looks for an end XXX (com.meterware.
httpunit.WebResponse) signature, and if it's available, calls it. Using the org.apache.
cactus.WebResponse object, we can perform asserts on the content of the HTTP
response, such as verifying the returned cookies, the returned HTTP headers, or the
content. The Cactus org.apache.cactus.WebResponse object supports a simple API .
The HttpUnit web response API ( com.meterware.httpunit.WebResponse ) is much
more comprehensive. With HttpUnit, we can view the returned XML or HTML pages
E
F
G
H
 
 
Search WWH ::




Custom Search