Information Technology Reference
In-Depth Information
}catch (ResourceNotFoundException e2) {
throw new DBUnitHibernateConfigurationException(
"ResourceNotFoundException in getDBUnitConnection", e2);
}
}
}
Note how the class in Listing 6-20 puts the Hibernate connection
information in a Properties object, which is then converted into
DbUnit's IDatabaseConnection type in a DBUnitConfigurator class.
The DbUnit connection type is then returned via the getDBUnit-
Connection method. DbUnit's IDataSet type, which represents those
XML files containing all the data, is returned via the getDataSet
method. This method frees developers from having to provide a path to
a file—something especially tricky in different environments.
In Listing 6-21, a custom abstract test case class can be created
which requests that implementers feed the desired data set information
for a particular test case.
LISTING 6-21
Convenient Test Case
public abstract class DefaultDBUnitHibernateTestCase extends
DatabaseTestCase {
public DefaultDBUnitHibernateTestCase(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
DefaultHibernateSessionFactory.
closeSessionAndEvictCache();
DefaultHibernateSessionFactory.
getInstance().getHibernateSession();
}
protected void tearDown() throws Exception {
DefaultHibernateSessionFactory.
closeSessionAndEvictCache();
super.tearDown();
}
protected IDatabaseConnection getConnection() throws Exception {
return DBUnitHibernateConfigurator.
getDBUnitConnection();
}
protected IDataSet getDataSet() throws Exception {
final String fileName = this.getDBUnitDataSetFileForSetUp();
Search WWH ::




Custom Search