@Override protected void assertCommitState(boolean insertRow, boolean isCommited) { if (insertRow) { EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory); em.persist(new TestBean(rowCount++, "Keith Donald")); } if (!isCommited) { assertEquals("Nothing should be committed yet", 1, getCount()); } else { assertEquals("All rows should be committed", rowCount, getCount()); } }
public void testLazyInitializedCollection() { MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); TestBean bean = hibernate.templateGet(TestBean.class, 0L); assertFalse("addresses should not be initialized", Hibernate.isInitialized(bean.getAddresses())); hibernateListener.paused(context); assertFalse("addresses should not be initialized", Hibernate.isInitialized(bean.getAddresses())); Hibernate.initialize(bean.getAddresses()); assertTrue("addresses should be initialized", Hibernate.isInitialized(bean.getAddresses())); }
@SuppressWarnings("unused") public void execute(RequestContext context, int expected) { assertSessionBound(); Session session = (Session) context.getFlowScope().get("persistenceContext"); TestBean bean = session.get(TestBean.class, 0L); assertEquals(expected, bean.getCount()); } };
public Event execute(RequestContext context) { assertSessionBound(); Session session = (Session) context.getFlowScope().get("persistenceContext"); TestBean bean = session.get(TestBean.class, 0L); bean.incrementCount(); return new Event(this, "success"); } };
public Event execute(RequestContext context) { assertSessionBound(); EntityManager em = (EntityManager) context.getFlowScope().get("persistenceContext"); TestBean bean = em.getReference(TestBean.class, 0L); bean.incrementCount(); assertNotNull(bean); return new Event(this, "success"); } };
@Override protected void assertCommitState(boolean insertRow, boolean isCommited) { if (insertRow) { hibernate.templateSave(new TestBean(rowCount++, "Keith Donald")); } if (!isCommited) { assertEquals("Nothing should be committed yet", 1, getCount()); } else { assertEquals("All rows should be committed", rowCount, getCount()); } }
@SuppressWarnings("unused") public void execute(RequestContext context, int expected) { assertSessionBound(); EntityManager em = (EntityManager) context.getFlowScope().get("persistenceContext"); TestBean bean = em.getReference(TestBean.class, 0L); assertEquals(expected, bean.getCount()); } };
public void testFlowCommitsAfterMultipleRequests() { assertEquals("Table should only have one row", 1, getCount()); 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, getCount()); 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, getCount()); 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, getCount()); assertSessionNotBound(); }
public void testExceptionThrown() { assertEquals("Table should only have one row", 1, getCount()); 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, getCount()); jpaListener.exceptionThrown(context, new FlowExecutionException("bla", "bla", "bla")); assertEquals("Table should still only have one row", 1, getCount()); assertSessionNotBound(); }
public void testFlowCommitsInSingleRequest() { assertEquals("Table should only have one row", 1, getCount()); 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, getCount()); 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 two rows", 2, getCount()); assertSessionNotBound(); }
public void testCancelEndState() { assertEquals("Table should only have one row", 1, getCount()); 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, getCount()); 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, getCount()); assertSessionNotBound(); }
public void testExceptionThrown() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); TestBean bean1 = new TestBean("Keith Donald"); hibernate.templateSave(bean1); assertEquals("Table should still only have one row", 1, getCount()); hibernateListener.exceptionThrown(context, new FlowExecutionException("bla", "bla", "bla")); assertEquals("Table should still only have one row", 1, getCount()); assertSessionNotBound(); }
public void testFlowCommitsAfterMultipleRequests() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); TestBean bean1 = new TestBean("Keith Donald"); hibernate.templateSave(bean1); assertEquals("Table should still only have one row", 1, getCount()); hibernateListener.paused(context); assertSessionNotBound(); hibernateListener.resuming(context); TestBean bean2 = new TestBean("Keith Donald"); hibernate.templateSave(bean2); assertEquals("Table should still only have one row", 1, getCount()); assertSessionBound(); EndState endState = new EndState(flowSession.getDefinitionInternal(), "success"); endState.getAttributes().put("commit", true); flowSession.setState(endState); hibernateListener.sessionEnding(context, flowSession, "success", null); hibernateListener.sessionEnded(context, flowSession, "success", null); assertEquals("Table should only have three rows", 3, getCount()); assertSessionNotBound(); }
public void testFlowCommitsInSingleRequest() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); TestBean bean = new TestBean("Keith Donald"); hibernate.templateSave(bean); assertEquals("Table should still only have one row", 1, getCount()); EndState endState = new EndState(flowSession.getDefinitionInternal(), "success"); endState.getAttributes().put("commit", true); flowSession.setState(endState); hibernateListener.sessionEnding(context, flowSession, "success", null); hibernateListener.sessionEnded(context, flowSession, "success", null); assertEquals("Table should only have two rows", 2, getCount()); assertSessionNotBound(); }
public void testCancelEndState() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); TestBean bean = new TestBean("Keith Donald"); hibernate.templateSave(bean); assertEquals("Table should still only have one row", 1, getCount()); EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel"); endState.getAttributes().put("commit", false); flowSession.setState(endState); hibernateListener.sessionEnding(context, flowSession, "success", null); hibernateListener.sessionEnded(context, flowSession, "cancel", null); assertEquals("Table should only have two rows", 1, getCount()); assertSessionNotBound(); }