Search in sources :

Example 1 with TrackingProcessEventListener

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

the class AdHocSubProcessTest method testAdHocSubprocess.

@BZ("807187")
@Test(timeout = 30000)
public void testAdHocSubprocess() {
    KieSession kieSession = createKSession(ADHOC);
    TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
    kieSession.addEventListener(eventListener);
    ProcessInstance pi = (ProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_ID));
    assertProcessStarted(eventListener, ADHOC_ID);
    assertTriggeredAndLeft(eventListener, "start");
    assertTriggered(eventListener, "adhoc");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "script1", null));
    assertTriggeredAndLeft(eventListener, "script1");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "script2", null));
    assertTriggeredAndLeft(eventListener, "script2");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "script3", null));
    assertTriggeredAndLeft(eventListener, "script3");
    assertTriggered(eventListener, "innerEnd");
    assertLeft(eventListener, "adhoc");
    assertProcessCompleted(eventListener, ADHOC_ID);
}
Also used : CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Command(org.kie.api.command.Command) RegisterWorkItemHandlerCommand(org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 2 with TrackingProcessEventListener

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

the class AdHocSubProcessTest method testAdHocSubProcessAutoComplete2.

@BZ("808070")
@Test(timeout = 30000)
public void testAdHocSubProcessAutoComplete2() {
    KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE2);
    TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
    kieSession.addEventListener(eventListener);
    TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
    kieSession.execute(new RegisterWorkItemHandlerCommand("Human Task", handler));
    WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE2_ID));
    assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE2_ID);
    assertTriggeredAndLeft(eventListener, "start");
    assertTriggered(eventListener, "adhoc");
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(CommandFactory.newSignalEvent(pi.getId(), "task1", null));
    commands.add(CommandFactory.newSignalEvent(pi.getId(), "task2", null));
    kieSession.execute((Command<?>) CommandFactory.newBatchExecution(commands));
    assertTriggered(eventListener, "task1");
    assertTriggered(eventListener, "task2");
    WorkItem wi = handler.getWorkItems().get(0);
    kieSession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    assertLeft(eventListener, "adhoc");
    assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE2_ID);
}
Also used : RegisterWorkItemHandlerCommand(org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Command(org.kie.api.command.Command) RegisterWorkItemHandlerCommand(org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 3 with TrackingProcessEventListener

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

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

the class SubprocessesTest method testProcessStartFromScript.

@Test(timeout = 30000)
public void testProcessStartFromScript() {
    TrackingProcessEventListener process = runProcess(ksession, "script");
    Assertions.assertThat(process.wasProcessCompleted(PROCESS_ID_1)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(HELLO_WORLD_PROCESS_ID)).isTrue();
}
Also used : TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 5 with TrackingProcessEventListener

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

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