}
public void testCancelEndState() {
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
MockRequestContext context = new MockRequestContext();
MockFlowSession flowSession = new MockFlowSession();
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
jpaListener.sessionStarting(context, flowSession, null);
context.setActiveSession(flowSession);
assertSessionBound();
TestBean bean = new TestBean(1, "Keith Donald");
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
em.persist(bean);
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
endState.getAttributes().put("commit", false);
flowSession.setState(endState);
jpaListener.sessionEnding(context, flowSession, "cancel", null);
jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionNotBound();
}