Information Technology Reference
In-Depth Information
HTTP requests; however, this can be tedious work and doesn't offer
the desired precision for Struts architecture that heavily utilizes
Action classes and a configuration for mapping requests.
The StrutsTestCase project was created to address this issue. With
this framework you can easily isolate and test Struts' Action classes.
This project, however, requires a developer to extend a base class
which handles mocking of a servlet container. If a Struts application
requires the use of a database, you may be left in a quandary.
Via DbUnit's API, a combination framework can be created that
utilizes the seeding capabilities of DbUnit with the mocking capabili-
ties of the StrutsTestCase project (see Listing 6-23).
LISTING 6-23
Combination Struts and Hibernate Test Case
public abstract class DefaultDBUnitMockStrutsTestCase
extends MockStrutsTestCase {
public DefaultDBUnitMockStrutsTestCase(String testName) {
super(testName);
}
public void setUp() throws Exception {
super.setUp();
this.executeOperation(this.getSetUpOperation());
}
public void tearDown() throws Exception{
super.tearDown();
this.executeOperation(this.getTearDownOperation());
}
private void executeOperation(DatabaseOperation operation)
throws Exception{
if (operation != DatabaseOperation.NONE){
final IDatabaseConnection connection =
this.getConnection();
try{
operation.execute(connection, this.getDataSet());
}finally{
closeConnection(connection);
}
}
}
protected void closeConnection(IDatabaseConnection connection)
throws Exception{
connection.close();
}
Search WWH ::




Custom Search