You need the above-named fix, if you want do some integration testing of your JSF managed beans and don't want to use DBUnit to prepare your fixtures in the database. In this case the functionality of the Spring Testing Framework could be used. Here a short example to demonstrate such a situation:
public class CustomerFormTest extends BasePageTestCase {
private Customer customer;
private CustomerForm customerForm;
// In this case JSF managed beans are configured in a Spring application context
public void setCustomerForm(CustomerForm customerForm)
{
this.customerForm = customerForm;
}
@Override
protected void onSetUp() throws Exception
{
customer = new Customer();
customer.setId(new Long(4711));
customer.setName("John Q. Public");
super.onSetUp();
}
@Override
protected void onSetUpInTransaction() throws Exception
{
jdbcTemplate.execute("INSERT INTO CUSTOMER(ID,NAME) " +
" VALUES(" + customer.getId().toString() + "," +
"'" + customer.getName() + "')");
super.onSetUpInTransaction();
}
public void testShouldLoadACustomerByAnIdRequestParameter()
{
request.addParameter("id", customer.getId().toString());
assertEquals("edit", customerForm.edit());
assertEquals(customer, customerForm.getCustomer());
}
}
The fixture is prepared in the onSetUpInTransaction-method. When the test ends the onTeardown-method in the AbstractTransactionalSpringContextTests is called, which rollbacks the database transaction. Without the aboved-named fix the onSetUpInTransaction-method in the superclass AbstractTransactionalSpringContextTests will never be called. Furthermore the onTearDown-method of the superclass should be called to rollback the started database transaction.
Best regards,
Max
Please describe steps to reproduce the error this causes and how your suggested fix solves the problem.
Thanks,
Matt