rvdlv
08-07-2006, 07:33 PM
First let me start of to compliment on the great work that is done on the Spring.NET. Keep up the good work!
Coming from a Java background working with Spring, I really like to be able to leverage the "AbstractTransactionalDataSourceSpringContextTests" class provided by the Spring framework. This lets us write transactional database tests like below (merely an example):
/**
* Testclass for testing class {@link HibernatePetDao}.
*
* @author Rob
*/
public class HibernatePetDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
private HibernatePetDao petDao;
private SessionFactory sessionFactory;
private DatabaseHelper databaseHelper;
protected String[] getConfigLocations() {
return new String[]{"testDatasource.xml"};
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected void onSetUpInTransaction() throws Exception {
petDao = new HibernatePetDao();
petDao.setSessionFactory(sessionFactory);
databaseHelper = new DatabaseHelper(jdbcTemplate);
// Insert testdata
jdbcTemplate.execute("INSERT INTO `pet` (`id`, `version`, `name`) VALUES (100, 0, 'Snoopy')");
}
public void testGetPetById() throws Exception {
Pet pet = petDao.getPetById(100L);
assertNotNull(pet);
assertEquals("Snoopy", pet.getName());
}
}
Is there any chance you guys are considering a "AbstractTransactionalSpringContextTests" in the near future?
Rgds,
Rob
Coming from a Java background working with Spring, I really like to be able to leverage the "AbstractTransactionalDataSourceSpringContextTests" class provided by the Spring framework. This lets us write transactional database tests like below (merely an example):
/**
* Testclass for testing class {@link HibernatePetDao}.
*
* @author Rob
*/
public class HibernatePetDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
private HibernatePetDao petDao;
private SessionFactory sessionFactory;
private DatabaseHelper databaseHelper;
protected String[] getConfigLocations() {
return new String[]{"testDatasource.xml"};
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected void onSetUpInTransaction() throws Exception {
petDao = new HibernatePetDao();
petDao.setSessionFactory(sessionFactory);
databaseHelper = new DatabaseHelper(jdbcTemplate);
// Insert testdata
jdbcTemplate.execute("INSERT INTO `pet` (`id`, `version`, `name`) VALUES (100, 0, 'Snoopy')");
}
public void testGetPetById() throws Exception {
Pet pet = petDao.getPetById(100L);
assertNotNull(pet);
assertEquals("Snoopy", pet.getName());
}
}
Is there any chance you guys are considering a "AbstractTransactionalSpringContextTests" in the near future?
Rgds,
Rob