Search in sources :

Example 26 with TrackingProcessEventListener

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

the class EndEventTest method testCompensateEndEvent.

@BZ("1021631")
@Test(timeout = 30000)
public void testCompensateEndEvent() {
    KieSession ksession = createKSession(COMPENSATE);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<ProcessInstance> cmd = getCommands().newStartProcess(COMPENSATE_ID);
    ProcessInstance pi = ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(COMPENSATE_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(COMPENSATE_ID)).isTrue();
    assertProcessStarted(events, COMPENSATE_ID);
    assertNextNode(events, "start");
    assertTriggered(events, "subprocess");
    assertNextNode(events, "sub-start");
    assertTriggered(events, "script");
    assertChangedVariable(events, "x", null, 0);
    assertLeft(events, "script");
    assertNextNode(events, "sub-end");
    assertLeft(events, "subprocess");
    assertTriggered(events, "end");
    assertLeft(events, "compensate-catch");
    assertTriggered(events, "compensate");
    assertChangedVariable(events, "x", 0, null);
    assertLeft(events, "compensate");
    Assertions.assertThat(pi.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) 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 27 with TrackingProcessEventListener

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

the class RuleTest method testNoOnEntryEvent.

@Test
@BZ("852095")
public void testNoOnEntryEvent() {
    Map<String, ResourceType> res = new HashMap<String, ResourceType>();
    res.put(ON_ENTRY_EVENT, ResourceType.BPMN2);
    res.put(ON_ENTRY_EVENT_DRL, ResourceType.DRL);
    KieSession ksession = createKSession(res);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    TrackingAgendaEventListener agendaEvents = new TrackingAgendaEventListener();
    TrackingProcessEventListener processEvents = new TrackingProcessEventListener();
    TrackingRuleRuntimeEventListener ruleEvents = new TrackingRuleRuntimeEventListener();
    ksession.addEventListener(agendaEvents);
    ksession.addEventListener(processEvents);
    ksession.addEventListener(ruleEvents);
    commands.add(getCommands().newStartProcess(ON_ENTRY_EVENT_ID));
    commands.add(getCommands().newFireAllRules());
    ksession.execute(getCommands().newBatchExecution(commands, null));
    Assertions.assertThat(processEvents.wasProcessStarted(ON_ENTRY_EVENT_ID)).isTrue();
    Assertions.assertThat(processEvents.wasNodeTriggered("Rule")).isTrue();
    Assertions.assertThat(ruleEvents.wasInserted("OnEntry")).isTrue();
    Assertions.assertThat(agendaEvents.isRuleFired("dummyRule")).isTrue();
    Assertions.assertThat(ruleEvents.wasInserted("OnExit")).isTrue();
    Assertions.assertThat(processEvents.wasNodeLeft("Rule")).isTrue();
    Assertions.assertThat(processEvents.wasProcessCompleted(ON_ENTRY_EVENT_ID)).isTrue();
}
Also used : HashMap(java.util.HashMap) Command(org.kie.api.command.Command) TrackingAgendaEventListener(org.jbpm.test.listener.TrackingAgendaEventListener) ArrayList(java.util.ArrayList) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) TrackingRuleRuntimeEventListener(org.jbpm.test.listener.TrackingRuleRuntimeEventListener) ResourceType(org.kie.api.io.ResourceType) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 28 with TrackingProcessEventListener

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

the class MultipleInstancesSubprocessTest method testTimerEvent.

@Test
@BZ("958390")
public void testTimerEvent() throws Exception {
    KieSession ksession = createKSession(TIMER_EVENT_PARENT, TIMER_EVENT_SUBPROCESS1, TIMER_EVENT_SUBPROCESS2);
    TrackingProcessEventListener processEvents = new TrackingProcessEventListener();
    ksession.addEventListener(processEvents);
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> clients = new ArrayList<String>();
    clients.add("A");
    clients.add("B");
    params.put("clients", clients);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(getCommands().newStartProcess(TIMER_EVENT_PARENT_ID, params));
    ksession.execute(getCommands().newBatchExecution(commands, null));
    String lastNodeName = "main-end";
    assertTrue("Node '" + lastNodeName + "' was not triggered on time!", processEvents.waitForNodeTobeTriggered(lastNodeName, 4000));
    Assertions.assertThat(processEvents.wasNodeTriggered("main-script1")).isTrue();
    Assertions.assertThat(processEvents.wasNodeTriggered("main-multiinstance1")).isTrue();
    Assertions.assertThat(processEvents.wasNodeTriggered("main-script2")).isTrue();
    Assertions.assertThat(processEvents.wasNodeTriggered("main-multiinstance2")).isTrue();
    Assertions.assertThat(processEvents.wasNodeTriggered(lastNodeName)).isTrue();
}
Also used : HashMap(java.util.HashMap) Command(org.kie.api.command.Command) 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 29 with TrackingProcessEventListener

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

the class AdHocSubProcessTest method testAdHocSubprocessAutocomplete3.

/**
 * Same as {@link #testAdHocSubprocessAutocomplete()} but BPMN contains the
 * old autocomplete constant:
 * getActivityInstanceAttribute("numberOfActiveInstances") == 0
 */
@Test(timeout = 30000)
public void testAdHocSubprocessAutocomplete3() {
    KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE3);
    TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
    kieSession.addEventListener(eventListener);
    TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(new RegisterWorkItemHandlerCommand("Human Task", handler));
    kieSession.execute(CommandFactory.newBatchExecution(commands));
    WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE3_ID));
    assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE3_ID);
    assertTriggeredAndLeft(eventListener, "start");
    assertTriggered(eventListener, "adhoc");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task1", null));
    assertTriggered(eventListener, "task1");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task2", null));
    assertTriggered(eventListener, "task2");
    WorkItem wi1 = handler.getWorkItems().get(0);
    WorkItem wi2 = handler.getWorkItems().get(1);
    kieSession.getWorkItemManager().completeWorkItem(wi1.getId(), null);
    assertFalse(eventListener.wasNodeLeft("adhoc"));
    kieSession.getWorkItemManager().completeWorkItem(wi2.getId(), null);
    assertLeft(eventListener, "adhoc");
    assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE3_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) 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)

Example 30 with TrackingProcessEventListener

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

the class AdHocSubProcessTest method testAdHocSubprocessAutocomplete.

/**
 * Tests if adhoc subprocess autocompletes when "autocomplete" is set as
 * completion condition. Signals 2 tasks inside subprocess;
 * the first completes, the second stays active, then completes
 * the second one => "autocomplete" => subprocess is also completed.
 */
@Test(timeout = 30000)
public void testAdHocSubprocessAutocomplete() {
    KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE);
    TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
    kieSession.addEventListener(eventListener);
    TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(new RegisterWorkItemHandlerCommand("Human Task", handler));
    kieSession.execute(CommandFactory.newBatchExecution(commands));
    WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE_ID));
    assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE_ID);
    assertTriggeredAndLeft(eventListener, "start");
    assertTriggered(eventListener, "adhoc");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task1", null));
    assertTriggered(eventListener, "task1");
    kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task2", null));
    assertTriggered(eventListener, "task2");
    WorkItem wi1 = handler.getWorkItems().get(0);
    WorkItem wi2 = handler.getWorkItems().get(1);
    kieSession.getWorkItemManager().completeWorkItem(wi1.getId(), null);
    assertFalse(eventListener.wasNodeLeft("adhoc"));
    kieSession.getWorkItemManager().completeWorkItem(wi2.getId(), null);
    assertLeft(eventListener, "adhoc");
    assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE_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) 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)

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