Search in sources :

Example 1 with ListWorkItemHandler

use of org.jbpm.test.wih.ListWorkItemHandler in project jbpm by kiegroup.

the class TransactionsTest method testUsertask.

@Test(timeout = 60000)
public void testUsertask() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(process);
    ListWorkItemHandler handler = new ListWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    long processId = startProcess(ksession);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "usertask", processId);
        Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
        Assertions.assertThat(handler.getWorkItems()).hasSize(1);
    } finally {
        ut.rollback();
    }
    // human tasks are not aborted (as that would not cause the task to be cancelled
    process.clear();
    ksession = restoreKSession(resources);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "usertask", processId);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    String lastUserTaskNodeName = "User Task";
    assertTrue("Node '" + lastUserTaskNodeName + "' was not left on time!", process.waitForNodeTobeTriggered(lastUserTaskNodeName, 1000));
    Assertions.assertThat(handler.getWorkItems()).hasSize(2);
    Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
    Assertions.assertThat(process.wasNodeTriggered(lastUserTaskNodeName)).isTrue();
    Assertions.assertThat(process.wasNodeLeft(lastUserTaskNodeName)).isFalse();
    Assertions.assertThat(process.wasProcessCompleted("transactions")).isFalse();
}
Also used : ListWorkItemHandler(org.jbpm.test.wih.ListWorkItemHandler) UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Aggregations

UserTransaction (javax.transaction.UserTransaction)1 TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)1 ListWorkItemHandler (org.jbpm.test.wih.ListWorkItemHandler)1 Test (org.junit.Test)1