Search in sources :

Example 1 with ListWorkItemHandler

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();
}
Also used : ListWorkItemHandler(org.jbpm.test.container.handlers.ListWorkItemHandler) UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.container.listeners.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Aggregations

UserTransaction (javax.transaction.UserTransaction)1 JbpmContainerTest (org.jbpm.test.container.JbpmContainerTest)1 ListWorkItemHandler (org.jbpm.test.container.handlers.ListWorkItemHandler)1 TrackingProcessEventListener (org.jbpm.test.container.listeners.TrackingProcessEventListener)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1