Search in sources :

Example 1 with IterableProcessEventListener

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

the class MultipleInstancesSubProcessTest method testMultipleInstances.

@BZ("802721")
@Test(timeout = 30000)
public void testMultipleInstances() {
    KieSession kieSession = createKSession(MULTIPLE_INSTANCES);
    IterableProcessEventListener eventListener = new IterableProcessEventListener();
    kieSession.addEventListener(eventListener);
    kieSession.addEventListener(new DebugProcessEventListener());
    List<String> items = new ArrayList<String>();
    items.add("breakfast");
    items.add("lunch");
    items.add("dinner");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("list", items);
    kieSession.execute((Command<?>) getCommands().newStartProcess(MULTIPLE_INSTANCES_ID, params));
    assertChangedVariable(eventListener, "list", null, items);
    assertProcessStarted(eventListener, MULTIPLE_INSTANCES_ID);
    assertNextNode(eventListener, "start");
    assertNextNode(eventListener, "script");
    assertTriggered(eventListener, "multipleInstances");
    // collection is passed to multiple-instances node
    for (String str : items) {
        assertChangedMultipleInstancesVariable(eventListener, "listItem", null, str);
    }
    // multiple-instances node is processed for every collection item
    for (String str : items) {
        assertNextNode(eventListener, "innerStart");
        assertTriggered(eventListener, "innerScript");
        assertChangedMultipleInstancesVariable(eventListener, "listItem", str, str + "-eaten");
        assertLeft(eventListener, "innerScript");
        assertNextNode(eventListener, "innerEnd");
    }
    assertLeft(eventListener, "multipleInstances");
    assertNextNode(eventListener, "end");
    assertProcessCompleted(eventListener, MULTIPLE_INSTANCES_ID);
}
Also used : DebugProcessEventListener(org.jbpm.test.listener.DebugProcessEventListener) HashMap(java.util.HashMap) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 2 with IterableProcessEventListener

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

the class ReusableSubProcessTest method testCallActivity.

@Test(timeout = 30000)
public void testCallActivity() {
    KieSession ksession = createKSession(CALL_ACTIVITY_CHILD, CALL_ACTIVITY_PARENT);
    IterableProcessEventListener eventListener = new IterableProcessEventListener();
    ksession.addEventListener(eventListener);
    ksession.execute((Command<?>) getCommands().newStartProcess(CALL_ACTIVITY_PARENT_ID));
    assertProcessStarted(eventListener, CALL_ACTIVITY_PARENT_ID);
    assertNextNode(eventListener, "start");
    assertTriggered(eventListener, "script");
    assertChangedVariable(eventListener, "var", null, 1);
    assertLeft(eventListener, "script");
    assertTriggered(eventListener, "reusable");
    assertChangedVariable(eventListener, "inSubVar", null, 1);
    assertProcessStarted(eventListener, CALL_ACTIVITY_CHILD_ID);
    assertNextNode(eventListener, "rs-start");
    assertTriggered(eventListener, "rs-script");
    assertChangedVariable(eventListener, "outSubVar", null, "one");
    assertLeft(eventListener, "rs-script");
    assertNextNode(eventListener, "rs-end");
    assertProcessCompleted(eventListener, CALL_ACTIVITY_CHILD_ID);
    assertChangedVariable(eventListener, "var", 1, "one");
    assertLeft(eventListener, "reusable");
    assertNextNode(eventListener, "end");
    assertProcessCompleted(eventListener, CALL_ACTIVITY_PARENT_ID);
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 3 with IterableProcessEventListener

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

the class SubprocessesTest method testDependentNoWaitForCompletionAbortParent.

@Test(timeout = 30000)
public void testDependentNoWaitForCompletionAbortParent() {
    TrackingProcessEventListener listener = new TrackingProcessEventListener();
    ksession.addEventListener(listener);
    IterableProcessEventListener process = new IterableProcessEventListener();
    ksession.addEventListener(process);
    ProcessInstance pi = ksession.startProcess(PROCESS_ID_2, createBranchDefiningMap("dependent-nowait"));
    assertChangedVariable(process, "node", null, "dependent-nowait");
    assertProcessStarted(process, PROCESS_ID_2);
    assertNextNode(process, P2_START);
    assertNextNode(process, P2_GATEWAY_START);
    assertTriggered(process, "dependent process that doesn't have to be completed");
    // subprocess
    assertProcessStarted(process, PROCESS_ID_3);
    long id = process.current().<CachedProcessStartedEvent>getEvent().getProcessInstanceId();
    assertNextNode(process, P3_START);
    assertTriggered(process, P3_SIGNAL);
    assertLeft(process, "dependent process that doesn't have to be completed");
    assertNextNode(process, P2_GATEWAY_END);
    assertTriggered(process, P2_SIGNAL_END);
    ksession.abortProcessInstance(pi.getId());
    assertProcessCompleted(process, PROCESS_ID_2);
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_3)).isFalse();
    // signal the subprocess to continue
    ksession.signalEvent("continue", null, id);
    assertLeft(process, P3_SIGNAL);
    assertTriggered(process, P3_SCRIPT);
    assertChangedVariable(process, "variable", null, "new value");
    assertLeft(process, P3_SCRIPT);
    assertNextNode(process, P3_END);
    assertProcessCompleted(process, PROCESS_ID_3);
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_3)).isTrue();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 4 with IterableProcessEventListener

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

the class SubprocessesTest method testIndependentNoWaitForCompletionAbortSubprocess.

@Test(timeout = 30000)
public void testIndependentNoWaitForCompletionAbortSubprocess() {
    TrackingProcessEventListener listener = new TrackingProcessEventListener();
    ksession.addEventListener(listener);
    IterableProcessEventListener process = new IterableProcessEventListener();
    ksession.addEventListener(process);
    ProcessInstance pi = ksession.startProcess(PROCESS_ID_2, createBranchDefiningMap("nowait"));
    assertChangedVariable(process, "node", null, "nowait");
    assertProcessStarted(process, PROCESS_ID_2);
    assertNextNode(process, P2_START);
    assertNextNode(process, P2_GATEWAY_START);
    assertTriggered(process, "don't wait for completion");
    // subprocess
    assertProcessStarted(process, PROCESS_ID_3);
    long id = process.current().<CachedProcessStartedEvent>getEvent().getProcessInstanceId();
    assertNextNode(process, P3_START);
    assertTriggered(process, P3_SIGNAL);
    assertLeft(process, "don't wait for completion");
    assertNextNode(process, P2_GATEWAY_END);
    assertTriggered(process, P2_SIGNAL_END);
    Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_3)).isTrue();
    ksession.abortProcessInstance(id);
    assertProcessCompleted(process, PROCESS_ID_3);
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_2)).isFalse();
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_3)).isTrue();
    ksession.signalEvent("finish", null, pi.getId());
    assertLeft(process, P2_SIGNAL_END);
    assertNextNode(process, P2_END);
    assertProcessCompleted(process, PROCESS_ID_2);
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_3)).isTrue();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 5 with IterableProcessEventListener

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

the class SubprocessesTest method testIndependentNoWaitForCompletionAbortParent.

@Test(timeout = 30000)
public void testIndependentNoWaitForCompletionAbortParent() {
    TrackingProcessEventListener listener = new TrackingProcessEventListener();
    ksession.addEventListener(listener);
    IterableProcessEventListener process = new IterableProcessEventListener();
    ksession.addEventListener(process);
    ProcessInstance pi = ksession.startProcess(PROCESS_ID_2, createBranchDefiningMap("nowait"));
    assertChangedVariable(process, "node", null, "nowait");
    assertProcessStarted(process, PROCESS_ID_2);
    assertNextNode(process, P2_START);
    assertNextNode(process, P2_GATEWAY_START);
    assertTriggered(process, "don't wait for completion");
    // subprocess
    assertProcessStarted(process, PROCESS_ID_3);
    long id = process.current().<CachedProcessStartedEvent>getEvent().getProcessInstanceId();
    assertNextNode(process, P3_START);
    assertTriggered(process, P3_SIGNAL);
    assertLeft(process, "don't wait for completion");
    assertNextNode(process, P2_GATEWAY_END);
    assertTriggered(process, P2_SIGNAL_END);
    Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_3)).isTrue();
    ksession.abortProcessInstance(pi.getId());
    assertProcessCompleted(process, PROCESS_ID_2);
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_3)).isFalse();
    // signal the subprocess to continue
    ksession.signalEvent("continue", null, id);
    assertLeft(process, P3_SIGNAL);
    assertTriggered(process, P3_SCRIPT);
    assertChangedVariable(process, "variable", null, "new value");
    assertLeft(process, P3_SCRIPT);
    assertNextNode(process, P3_END);
    assertProcessCompleted(process, PROCESS_ID_3);
    Assertions.assertThat(listener.wasProcessAborted(PROCESS_ID_2)).isTrue();
    Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_3)).isTrue();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

IterableProcessEventListener (org.jbpm.test.listener.IterableProcessEventListener)34 Test (org.junit.Test)32 KieSession (org.kie.api.runtime.KieSession)18 TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)15 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Command (org.kie.api.command.Command)4 BZ (qa.tools.ikeeper.annotation.BZ)3 Person (org.jbpm.test.domain.Person)2 Before (org.junit.Before)2 ResourceType (org.kie.api.io.ResourceType)2 RegisterWorkItemHandlerCommand (org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand)1 StartProcessCommand (org.drools.core.command.runtime.process.StartProcessCommand)1 JbpmJUnitBaseTestCase (org.jbpm.test.JbpmJUnitBaseTestCase)1 DebugProcessEventListener (org.jbpm.test.listener.DebugProcessEventListener)1 Ignore (org.junit.Ignore)1 WorkItem (org.kie.api.runtime.process.WorkItem)1