use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testTimerStartCycleLegacy.
@Test(timeout = 10000)
public void testTimerStartCycleLegacy() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 2);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStartCycleLegacy.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
logger.debug("About to start ###### " + new Date());
assertThat(list.size()).isEqualTo(0);
// then wait 5 times 5oo ms as that is period configured on the process
countDownListener.waitTillCompleted();
ksession.dispose();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(2);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testSignalStartWithTransformation.
@Test(timeout = 10000)
public void testSignalStartWithTransformation() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-SignalStartWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<ProcessInstance> list = new ArrayList<ProcessInstance>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance());
}
});
ksession.signalEvent("MySignal", "NewValue");
countDownListener.waitTillCompleted();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
assertThat(list).isNotNull();
assertThat(list.size()).isEqualTo(1);
String var = getProcessVarValue(list.get(0), "x");
assertThat(var).isEqualTo("NEWVALUE");
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testMultipleEventBasedStartEventsTimerDifferentPaths.
@Test(timeout = 10000)
public void testMultipleEventBasedStartEventsTimerDifferentPaths() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartTimer", 2);
KieBase kbase = createKnowledgeBase("BPMN2-MultipleStartEventProcessDifferentPaths.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertThat(list.size()).isEqualTo(0);
// Timer in the process takes 1000ms, so after 2 seconds, there should be 2 process IDs in the list.
countDownListener.waitTillCompleted();
assertThat(list.size()).isEqualTo(2);
List<WorkItem> workItems = workItemHandler.getWorkItems();
for (WorkItem workItem : workItems) {
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstanceId, "StartTimer", "Script 2", "User task", "End");
}
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testTimerStart.
@Test(timeout = 10000)
public void testTimerStart() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStart.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertThat(list.size()).isEqualTo(0);
countDownListener.waitTillCompleted();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(5);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testSignalStartWithCustomEvent.
@Test
public void testSignalStartWithCustomEvent() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SingalStartWithCustomEvent.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<ProcessInstance> list = new ArrayList<ProcessInstance>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance());
}
});
NotAvailableGoodsReport report = new NotAvailableGoodsReport("test");
ksession.signalEvent("SignalNotAvailableGoods", report);
assertThat(getNumberOfProcessInstances("org.jbpm.example.SignalObjectProcess")).isEqualTo(1);
assertThat(list.size()).isEqualTo(1);
assertProcessVarValue(list.get(0), "report", "NotAvailableGoodsReport{type:test}");
}
Aggregations