use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.
the class EJBTransactionsTest method startProcess.
private void startProcess(ProcessEJB ejb) {
TrackingProcessEventListener listener = new TrackingProcessEventListener();
final TestWorkItemHandler wih = new TestWorkItemHandler();
Assertions.assertThat(kbase).isNotNull();
ProcessScenario scenario = new ProcessScenario(kbase, EJBTransactions.PROCESS_DOUBLE_HUMAN_TASKS, null, listener) {
@Override
protected void runScenario(String procId, Map<String, Object> params, KieSession ksession) {
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", wih);
ksession.startProcess(procId, params);
// first task
ksession.getWorkItemManager().completeWorkItem(wih.getWorkItem().getId(), null);
// second task
ksession.getWorkItemManager().completeWorkItem(wih.getWorkItem().getId(), null);
}
};
ejb.startProcess(scenario);
if (scenario.hasErrors()) {
throw new RuntimeException(scenario.getErrors().get(0));
}
TrackingListenerAssert.assertProcessStarted(listener, EJBTransactions.PROCESS_DOUBLE_HUMAN_TASKS);
TrackingListenerAssert.assertTriggeredAndLeft(listener, "Upload Form");
TrackingListenerAssert.assertTriggeredAndLeft(listener, "Approve It");
TrackingListenerAssert.assertProcessCompleted(listener, EJBTransactions.PROCESS_DOUBLE_HUMAN_TASKS);
}
use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.
the class TransactionsTest method testTimer.
@Test
public void testTimer() throws Exception {
TrackingProcessEventListener process = new TrackingProcessEventListener();
KieSession ksession = createJPASession(getKnowledgeBase());
ksession.addEventListener(process);
long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
UserTransaction ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "timer", processId);
Assertions.assertThat(process.wasNodeLeft("timer")).isTrue();
ut.rollback();
Thread.sleep(600);
process.clear();
ksession = reloadSession(ksession);
ksession.addEventListener(process);
ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "timer", processId);
ut.commit();
Thread.sleep(1000);
Assertions.assertThat(process.wasNodeLeft("timer")).isTrue();
ksession.signalEvent("finish", null, processId);
Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isTrue();
}
use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.
the class TransactionsTest method testScript.
@Test
public void testScript() throws Exception {
TrackingProcessEventListener process = new TrackingProcessEventListener();
KieSession ksession = createJPASession(getKnowledgeBase());
ksession.addEventListener(process);
long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
UserTransaction ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "script", processId);
Assertions.assertThat(process.wasNodeLeft("script")).isTrue();
ut.rollback();
process.clear();
ksession = reloadSession(ksession);
ksession.addEventListener(process);
ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "script", processId);
Thread.sleep(1000);
Assertions.assertThat((long) ut.getStatus()).isEqualTo((long) Status.STATUS_ACTIVE);
ut.commit();
Assertions.assertThat(process.wasNodeLeft("script")).isTrue();
ksession.signalEvent("finish", null, processId);
Thread.sleep(1000);
Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isTrue();
}
use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.
the class TransactionsTest method testUsertask.
@Test
public void testUsertask() throws Exception {
TrackingProcessEventListener process = new TrackingProcessEventListener();
KieSession ksession = createJPASession(getKnowledgeBase());
ksession.addEventListener(process);
ListWorkItemHandler handler = new ListWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
UserTransaction ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "usertask", processId);
Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 1);
ut.rollback();
// human tasks are not aborted (as that would not cause the task to be
// cancelled
process.clear();
ksession = reloadSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(process);
ut = getUserTransaction();
ut.begin();
ksession.signalEvent("start", "usertask", processId);
ut.commit();
Thread.sleep(1000);
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 2);
Assertions.assertThat((long) handler.getWorkItems().size()).isEqualTo((long) 2);
Assertions.assertThat(process.wasNodeLeft("usertask")).isTrue();
Assertions.assertThat(process.wasNodeTriggered("User Task")).isTrue();
Assertions.assertThat(process.wasNodeLeft("User Task")).isFalse();
Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isFalse();
}
use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.
the class TransactionsTest method testAbortProcessCommit.
@Test
public void testAbortProcessCommit() throws Exception {
KieSession ksession = createJPASession(getKnowledgeBase());
long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
TrackingProcessEventListener listener = new TrackingProcessEventListener();
ksession.addEventListener(listener);
Assertions.assertThat((long) ksession.getProcessInstance(processId).getState()).isEqualTo((long) ProcessInstance.STATE_ACTIVE);
UserTransaction ut = getUserTransaction();
ut.begin();
ksession.abortProcessInstance(processId);
ut.commit();
ksession = reloadSession(ksession);
Assertions.assertThat(ksession.getProcessInstance(processId)).isNull();
Assertions.assertThat(listener.wasProcessAborted(LocalTransactions.PROCESS_TRANSACTIONS)).isTrue();
}
Aggregations