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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations