use of org.jbpm.test.container.handlers.ListWorkItemHandler in project jbpm by kiegroup.
the class TransactionsTest method testUsertask.
@Test
public void testUsertask() throws Exception {
TrackingProcessEventListener process = new TrackingProcessEventListener();
KieSession ksession = createJPASession(getKnowledgeBase());
ksession.addEventListener(process);
ListWorkItemHandler handler = new ListWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
UserTransaction ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "usertask", processId);
Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 1);
ut.rollback();
// human tasks are not aborted (as that would not cause the task to be
// cancelled
process.clear();
ksession = reloadSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(process);
ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "usertask", processId);
ut.commit();
Thread.sleep(1000);
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 2);
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 2);
Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
Assertions.assertThat(process.wasNodeTriggered("User Task")).isTrue();
Assertions.assertThat(process.wasNodeLeft("User Task")).isFalse();
Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isFalse();
}
Aggregations