}
public void testFlowCommitsAfterMultipleRequests() {
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 bean1 = new TestBean(1, "Keith Donald");
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
em.persist(bean1);
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
jpaListener.paused(context);
assertSessionNotBound();
jpaListener.resuming(context);
TestBean bean2 = new TestBean(2, "Keith Donald");
em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
em.persist(bean2);
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionBound();
EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
endState.getAttributes().put("commit", true);
flowSession.setState(endState);
jpaListener.sessionEnding(context, flowSession, "success", null);
jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));