Search in sources :

Example 36 with ProcessStartedEvent

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);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) Date(java.util.Date) Test(org.junit.Test)

Example 37 with ProcessStartedEvent

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");
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 38 with ProcessStartedEvent

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");
    }
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItem(org.kie.api.runtime.process.WorkItem) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 39 with ProcessStartedEvent

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);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) Test(org.junit.Test)

Example 40 with ProcessStartedEvent

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}");
}
Also used : NotAvailableGoodsReport(org.jbpm.bpmn2.objects.NotAvailableGoodsReport) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)57 Test (org.junit.Test)55 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)48 ArrayList (java.util.ArrayList)45 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)29 KieBase (org.kie.api.KieBase)29 KieSession (org.kie.api.runtime.KieSession)23 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)15 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 HashMap (java.util.HashMap)10 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)9 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)8 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)8 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)7 ProcessEvent (org.kie.api.event.process.ProcessEvent)6 WorkItem (org.kie.api.runtime.process.WorkItem)6