Search in sources :

Example 36 with TrackingProcessEventListener

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

the class HumanTaskTest method testBoundaryTimer.

@Test
@BZ("958397")
public void testBoundaryTimer() throws Exception {
    createRuntimeManager(BOUNDARY_TIMER);
    KieSession ksession = getRuntimeEngine().getKieSession();
    TaskService taskService = getRuntimeEngine().getTaskService();
    TrackingProcessEventListener tpel = new TrackingProcessEventListener();
    ksession.addEventListener(tpel);
    ProcessInstance pi = ksession.startProcess(BOUNDARY_TIMER_ID);
    // wait for timer
    String endNodeName = "End1";
    assertTrue("Node '" + endNodeName + "' was not triggered on time!", tpel.waitForNodeTobeTriggered(endNodeName, 2000));
    assertTriggeredAndLeft(tpel, "Script1");
    assertTriggered(tpel, endNodeName);
    long taskId = taskService.getTasksByProcessInstanceId(pi.getId()).get(0);
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    assertTriggeredAndLeft(tpel, "Script2");
    assertTriggered(tpel, "End2");
    assertProcessInstanceCompleted(pi.getId());
}
Also used : TaskService(org.kie.api.task.TaskService) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 37 with TrackingProcessEventListener

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

the class EventListenersTest method testClearExecution.

@Test(timeout = 60000L)
public void testClearExecution() {
    TrackingProcessEventListener listener = new TrackingProcessEventListener();
    ksession.addEventListener(listener);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(getCommands().newStartProcess(PROCESS_ID));
    commands.add(getCommands().newSignalEvent("other-branch", "hello world!"));
    ksession.execute(getCommands().newBatchExecution(commands, null));
    assertTrue(listener.wasNodeTriggered("introduction"));
    assertFalse(listener.wasNodeTriggered("script-warning"));
    assertTrue(listener.wasNodeLeft("introduction"));
    assertFalse(listener.wasNodeLeft("script-warning"));
    assertTrue(listener.wasVariableChanged("signalData"));
    assertFalse(listener.wasVariableChanged("stringVariable"));
    assertTrue(listener.wasProcessStarted(PROCESS_ID));
    assertTrue(listener.wasProcessCompleted(PROCESS_ID));
}
Also used : Command(org.kie.api.command.Command) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with TrackingProcessEventListener

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

the class TransactionsTest method testAbortProcessCommit.

@Test(timeout = 60000)
public void testAbortProcessCommit() throws Exception {
    long processId = startProcess(ksession);
    TrackingProcessEventListener listener = new TrackingProcessEventListener();
    ksession.addEventListener(listener);
    assertProcessInstanceActive(processId);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.abortProcessInstance(processId);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    ksession = restoreKSession(resources);
    assertProcessInstanceAborted(processId);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 39 with TrackingProcessEventListener

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

the class TransactionsTest method testTimer.

@Test
public void testTimer() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(process);
    long processId = startProcess(ksession);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "timer", processId);
        Assertions.assertThat(process.wasNodeLeft("timer")).isTrue();
    } finally {
        ut.rollback();
    }
    Thread.sleep(600);
    process.clear();
    ksession = restoreKSession(resources);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "timer", processId);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    String timerNodeName = "timer";
    assertTrue("Node '" + timerNodeName + "' was not left on time!", process.waitForNodeToBeLeft(timerNodeName, 1500));
    Assertions.assertThat(process.wasNodeLeft(timerNodeName)).isTrue();
    String finishScriptNodeName = "Finish-Script";
    assertTrue("Node '" + finishScriptNodeName + "' was not triggered on time!", process.waitForNodeTobeTriggered(finishScriptNodeName, 1500));
    ksession.signalEvent("finish", null, processId);
    assertTrue("Process did not complete on time!", process.waitForProcessToComplete(1500));
    assertProcessInstanceCompleted(processId);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 40 with TrackingProcessEventListener

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

the class TransactionsTest method testEmbedded.

@Test(timeout = 60000)
public void testEmbedded() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener(false);
    ksession.addEventListener(process);
    long processId = startProcess(ksession);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "embedded", processId);
        assertTrue("Node 'embedded' was not left on time!", process.waitForNodeToBeLeft("embedded", 1000));
        Assertions.assertThat(process.wasNodeLeft("embedded")).isTrue();
    } finally {
        ut.rollback();
    }
    process.clear();
    ksession = restoreKSession(resources);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "embedded", processId);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    assertTrue("Node 'embedded' was not left on time!", process.waitForNodeToBeLeft("embedded", 1000));
    Assertions.assertThat(process.wasNodeLeft("embedded")).isTrue();
    Assertions.assertThat(process.wasProcessCompleted("transactions")).isFalse();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) 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