Search in sources :

Example 16 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class LaneTest method testLane.

@Test(timeout = 30000)
public void testLane() {
    KieSession ksession = createKSession(PROCESS);
    TrackingProcessEventListener tpel = new TrackingProcessEventListener();
    ksession.addEventListener(tpel);
    ksession.execute((Command<?>) getCommands().newStartProcess(PROCESS_ID));
    assertProcessStarted(tpel, PROCESS_ID);
    assertTriggeredAndLeft(tpel, "start");
    assertTriggered(tpel, "fork");
    assertLeft(tpel, "fork", 2);
    assertTriggeredAndLeft(tpel, "scriptTask1");
    assertTriggeredAndLeft(tpel, "scriptTask2");
    assertTriggered(tpel, "end1");
    assertTriggered(tpel, "end2");
    assertProcessCompleted(tpel, PROCESS_ID);
}
Also used : TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 17 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener 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)

Example 18 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testForLoop.

@Test(timeout = 60000)
public void testForLoop() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener(false);
    ksession.addEventListener(process);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", Arrays.asList("hello world", "25", "false", "1234567891011121314151617181920", ""));
    long processId = ksession.startProcess(TRANSACTIONS_ID, params).getId();
    String forLoopNodeName = "forloop";
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", forLoopNodeName, processId);
        assertTrue("Node '" + forLoopNodeName + "' was not left on time!", process.waitForNodeToBeLeft(forLoopNodeName, 1000));
        Assertions.assertThat(process.wasNodeLeft(forLoopNodeName)).isTrue();
    } finally {
        ut.rollback();
    }
    process.clear();
    ksession = restoreKSession(resources);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "forloop", processId);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    String multipleInstancesNode = "Multiple Instances";
    assertTrue("Process did not complete on time!", process.waitForNodeToBeLeft(multipleInstancesNode, 1000));
    Assertions.assertThat(process.wasNodeLeft(forLoopNodeName)).isTrue();
    Assertions.assertThat(process.wasNodeLeft(multipleInstancesNode)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted("transactions")).isFalse();
}
Also used : UserTransaction(javax.transaction.UserTransaction) HashMap(java.util.HashMap) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 19 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testScript.

@Test(timeout = 60000)
public void testScript() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener(false);
    ksession.addEventListener(process);
    long processId = startProcess(ksession);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "script", processId);
        Assertions.assertThat(process.wasNodeLeft("script")).isTrue();
    } finally {
        ut.rollback();
    }
    process.clear();
    ksession = restoreKSession(resources);
    ksession.addEventListener(process);
    String scriptNodeName = "script";
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "script", processId);
        assertTrue("Node '" + scriptNodeName + "' was not left on time!", process.waitForNodeToBeLeft(scriptNodeName, 1000));
        Assertions.assertThat(ut.getStatus()).isEqualTo(Status.STATUS_ACTIVE);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    Assertions.assertThat(process.wasNodeLeft(scriptNodeName)).isTrue();
    ksession.signalEvent("finish", null, processId);
    assertTrue("Process was not completed on time!", process.waitForProcessToComplete(1000));
    assertProcessInstanceCompleted(processId);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 20 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class StartEventTest method testDelayingTimerStartEvent.

@Test(timeout = 30000)
public void testDelayingTimerStartEvent() throws Exception {
    KieSession ksession = createKSession(TIMER_DURATION);
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(process);
    ksession.fireAllRules();
    assertTrue("The process did not start on time!", process.waitForProcessToStart(1000));
    assertTrue("The process did not complete on time!", process.waitForProcessToComplete(1000));
    ksession.fireAllRules();
    Assertions.assertThat(process.wasProcessStarted(TIMER_DURATION_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(TIMER_DURATION_ID)).isTrue();
    process.clear();
}
Also used : TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)51 Test (org.junit.Test)49 KieSession (org.kie.api.runtime.KieSession)25 IterableProcessEventListener (org.jbpm.test.listener.IterableProcessEventListener)17 Command (org.kie.api.command.Command)16 ArrayList (java.util.ArrayList)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)13 BZ (qa.tools.ikeeper.annotation.BZ)9 UserTransaction (javax.transaction.UserTransaction)7 RegisterWorkItemHandlerCommand (org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand)6 CompleteWorkItemCommand (org.drools.core.command.runtime.process.CompleteWorkItemCommand)5 HashMap (java.util.HashMap)3 TrackingAgendaEventListener (org.jbpm.test.listener.TrackingAgendaEventListener)2 WorkItem (org.kie.api.runtime.process.WorkItem)2 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)1 JbpmJUnitBaseTestCase (org.jbpm.test.JbpmJUnitBaseTestCase)1 TrackingRuleRuntimeEventListener (org.jbpm.test.listener.TrackingRuleRuntimeEventListener)1 ListWorkItemHandler (org.jbpm.test.wih.ListWorkItemHandler)1 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)1 Before (org.junit.Before)1