use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerShortherDelayTest.
@Test(timeout = 30000)
public void updateTimerShortherDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 3s
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 3));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 3000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class TimerUpdateTest method updateBoundaryTimerTest.
@Test(timeout = 30000)
public void updateBoundaryTimerTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(BOUNDARY_TIMER_NAME, 1);
// timer is set for long duration (100s)
setProcessScenario(BOUNDARY_TIMER_FILE);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
kieSession.addEventListener(countDownListener);
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(BOUNDARY_PROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set timer delay to 3s
kieSession.execute(new UpdateTimerCommand(id, BOUNDARY_TIMER_ATTACHED_TO_NAME, 3));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 3000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(1000);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testSignalStartEventDataMapping.
@Test
@BZ("1154557")
public void testSignalStartEventDataMapping() throws Exception {
KieSession ksession = createKSession(SIGNAL_DATA_MAPPING);
final List<Long> list = new ArrayList<Long>();
final List<String> variableList = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
variableList.add((String) ((WorkflowProcessInstance) event.getProcessInstance()).getVariable("x"));
}
});
ksession.signalEvent("MyStartSignal", "NewValue");
Assertions.assertThat(list).hasSize(1);
Assertions.assertThat(variableList.get(0)).isEqualTo("NewValue");
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class HumanTaskSwimlaneTest method testSwimlaneWithMultipleActorsAssigned.
@Test
public void testSwimlaneWithMultipleActorsAssigned() {
createRuntimeManager(SWIMLANE_MULTIPLE_ACTORS);
String user = "john";
RuntimeEngine runtime = getRuntimeEngine();
KieSession kSession = runtime.getKieSession();
TaskService taskservice = runtime.getTaskService();
kSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("TASK")) {
Object swimlaneActorId = ((HumanTaskNodeInstance) event.getNodeInstance()).getWorkItem().getParameter("SwimlaneActorId");
assertNull(swimlaneActorId);
}
}
});
Map<String, Object> map = new HashMap<String, Object>();
ProcessInstance instance = kSession.startProcess(SWIMLANE_MULTIPLE_ACTORS_ID, map);
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.Reserved);
statuses.add(Status.InProgress);
List<TaskSummary> tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals(Status.Ready, task.getStatus());
taskservice.claim(task.getId(), user);
taskservice.start(task.getId(), user);
tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals(Status.InProgress, task.getStatus());
taskservice.complete(task.getId(), user, map);
assertProcessInstanceCompleted(instance.getId());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testMultipleProcessesInSingleCaseCompletedInSequence.
@Test
public void testMultipleProcessesInSingleCaseCompletedInSequence() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id > 0);
ProcessInstance pi1 = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_COMPLETED, pi1.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ProcessInstance pi2 = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_COMPLETED, pi2.getState());
// there should be only one ksession used
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
manager.close();
}
Aggregations