use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.
the class AdHocSubProcessTest method testAdHocSubprocessDynamicWorkItem.
/**
* Tests dynamic insertion of new work item node into the adhoc subprocess.
* Uses DynamicUtils.
*/
@Test(timeout = 30000)
public void testAdHocSubprocessDynamicWorkItem() {
KieSession kieSession = createKSession(ADHOC);
TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
kieSession.addEventListener(eventListener);
WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_ID));
assertProcessStarted(eventListener, ADHOC_ID);
assertTriggeredAndLeft(eventListener, "start");
assertTriggered(eventListener, "adhoc");
// dynamic node insert
JbpmJUnitBaseTestCase.TestWorkItemHandler handler = getTestWorkItemHandler();
RegisterWorkItemHandlerCommand registerCommand = new RegisterWorkItemHandlerCommand("addedWorkItem", handler);
kieSession.execute(registerCommand);
DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) pi.getNodeInstances().iterator().next();
DynamicUtils.addDynamicWorkItem(dynamicNodeInstance, kieSession, "addedWorkItem", new java.util.HashMap<String, Object>());
WorkItem wi = handler.getWorkItem();
CompleteWorkItemCommand completeCommand = new CompleteWorkItemCommand(wi.getId(), null);
kieSession.execute(completeCommand);
// end of the dynamic stuff
assertEquals("addedWorkItem", wi.getName());
}
use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.
the class SubprocessesTest method testDependentNoWaitForCompletion.
@Test(timeout = 30000)
public void testDependentNoWaitForCompletion() {
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);
Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_2)).isTrue();
Assertions.assertThat(listener.wasProcessStarted(PROCESS_ID_3)).isTrue();
// signal the parent process to finish
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.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.wasProcessCompleted(PROCESS_ID_2)).isTrue();
Assertions.assertThat(listener.wasProcessCompleted(PROCESS_ID_3)).isTrue();
}
use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.
the class SubprocessesTest method runProcess.
private TrackingProcessEventListener runProcess(KieSession session, String processId, String nodeType, Command<?>... additionalCommands) {
TrackingProcessEventListener process = new TrackingProcessEventListener();
session.addEventListener(process);
ProcessInstance pi = session.startProcess(processId);
session.signalEvent("nodeType", nodeType, pi.getId());
for (Command<?> additionalCommand : additionalCommands) {
session.execute(additionalCommand);
}
try {
assertTrue("Process was not started on time!", process.waitForProcessToStart(1000));
} catch (Exception ex) {
logger.warn("Interrupted", ex);
}
return process;
}
use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.
the class AsyncWIHOnOracleTest method testAsyncWIHExecutedMoreThanOnceOnOracle.
@Test
@BZ("1234592")
public void testAsyncWIHExecutedMoreThanOnceOnOracle() throws Exception {
KieSession ksession = createKSession(PROCESS);
TrackingProcessEventListener tpel = new TrackingProcessEventListener();
ksession.addEventListener(tpel);
WorkItemHandler wih = new AsyncWorkItemHandler(getExecutorService(), CounterCommand.class.getName());
ksession.getWorkItemManager().registerWorkItemHandler("async", wih);
ksession.startProcess(PROCESS_ID);
boolean completed = tpel.waitForProcessToComplete(10000);
Assertions.assertThat(completed).as("The process should have finished in 10s").isTrue();
Assertions.assertThat(CounterCommand.getCounter()).as("The job has not been executed").isNotEqualTo(0);
Assertions.assertThat(CounterCommand.getCounter()).as("The job has been executed multiple times").isEqualTo(1);
}
use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.
the class EmbeddedSubprocessTest method testTerminatingEndEvent.
@Test
@BZ("851286")
public void testTerminatingEndEvent() {
KieSession ksession = createKSession(TERMINATING_END_EVENT);
TrackingProcessEventListener processEvents = new TrackingProcessEventListener();
ksession.addEventListener(processEvents);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(getCommands().newStartProcess(TERMINATING_END_EVENT_ID));
ksession.execute(getCommands().newBatchExecution(commands, null));
Assertions.assertThat(processEvents.wasNodeTriggered("main-script")).isTrue();
Assertions.assertThat(processEvents.wasNodeTriggered("main-end")).isTrue();
}
Aggregations