Information Technology Reference
In-Depth Information
protected abstract Properties getConnectionProperties();
protected abstract String getDBUnitDataSetFileForSetUp();
protected IDatabaseConnection getConnection() throws Exception {
final Properties dbPrps = this.getConnectionProperties();
DatabaseTestCase.
assertNotNull("database properties were null", dbPrps);
return DBUnitConfigurator.getDBUnitConnection(dbPrps);
}
protected DatabaseOperation getSetUpOperation() throws Exception {
return DatabaseOperation.CLEAN_INSERT;
}
protected DatabaseOperation getTearDownOperation() throws Exception {
return DatabaseOperation.NONE;
}
protected IDataSet getDataSet() throws Exception {
final String fileName = this.getDBUnitDataSetFileForSetUp();
DatabaseTestCase.assertNotNull("data set file was null", fileName);
return DBUnitConfigurator.getDataSet(fileName);
}
}
Once again, you may be left with the option of hard-coding con-
nection information or reusing existing files for this purpose. Testing a
Struts application that uses Hibernate? Not a problem—just combine
the new DefaultDBUnitMockStrutsTestCase with its handy utility
for reading Hibernate files.
For example, Listing 6-24 is a class that implements a Default-
MerlinMockStrutsTestCase class, which combines the DbUnit capa-
bility of DefaultDBUnitMockStrutsTestCase with the handy Hibernate
reader utility defined previously in Listing 6-20.
The Combo Framework in Action
LISTING 6-24
public class ProjectListActionTest
extends DefaultMerlinMockStrutsTestCase {
public void testProjectListAction() throws Exception{
this.setRequestPathInfo("/viewProjects");
this.actionPerform();
this.verifyForward("success");
IProject[] projects = (IProject[])this.getRequest().
getAttribute("projects");
assertNotNull("object was null", projects);
}
Search WWH ::




Custom Search