Search in sources :

Example 1 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class RequestUI method createKieSession.

private KieSession createKieSession() {
    try {
        final KieSession ksession = getKieSession();
        KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
        UIWorkItemHandler handler = new UIWorkItemHandler();
        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
        handler.setVisible(true);
        ksession.getWorkItemManager().registerWorkItemHandler("Email", new WorkItemHandler() {

            public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                System.out.println("Sending email ...");
                manager.completeWorkItem(workItem.getId(), null);
            }

            public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            }
        });
        Person person = new Person("john", "John Doe");
        person.setAge(40);
        ksession.insert(person);
        person = new Person("krisv", "Kris Verlaenen");
        person.setAge(30);
        ksession.insert(person);
        person = new Person("baby", "Baby");
        person.setAge(1);
        ksession.insert(person);
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                ksession.insert(event);
            }
        });
        return ksession;
    } catch (Throwable t) {
        throw new RuntimeException("Could not initialize session!", t);
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Example 2 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testTimerStart.

@Test(timeout = 10000)
public void testTimerStart() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
    KieBase kbase = createKnowledgeBase("BPMN2-TimerStart.bpmn2");
    KieSession 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(list.size()).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) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 3 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class FlowTest method testMultipleInOutgoingSequenceFlows.

@Test
public void testMultipleInOutgoingSequenceFlows() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
    System.setProperty("jbpm.enable.multi.con", "true");
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleInOutgoingSequenceFlows.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());
        }
    });
    assertEquals(0, list.size());
    countDownListener.waitTillCompleted();
    assertEquals(1, list.size());
    System.clearProperty("jbpm.enable.multi.con");
}
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 4 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class ActivityTest method testCallActivityWithTransformation.

@Test
public void testCallActivityWithTransformation() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityWithTransformation.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            instances.add(event.getProcessInstance());
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, instances.size());
    // assert variables of parent process, first in start (input transformation, then on end output transformation)
    assertEquals("oldValue", ((WorkflowProcessInstance) instances.get(0)).getVariable("x"));
    assertEquals("NEW VALUE", ((WorkflowProcessInstance) instances.get(0)).getVariable("y"));
    // assert variables of subprocess, first in start (input transformation, then on end output transformation)
    assertEquals("OLDVALUE", ((WorkflowProcessInstance) instances.get(1)).getVariable("subX"));
    assertEquals("new value", ((WorkflowProcessInstance) instances.get(1)).getVariable("subY"));
}
Also used : HashMap(java.util.HashMap) 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) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 5 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class ActivityTest method testCallActivityMI.

@Test
public void testCallActivityMI() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityMI.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<Long> subprocessStarted = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            if (event.getProcessInstance().getProcessId().equals("SubProcess")) {
                subprocessStarted.add(event.getProcessInstance().getId());
            }
        }
    });
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    params.put("list", list);
    params.put("listOut", listOut);
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, subprocessStarted.size());
    listOut = (List) ((WorkflowProcessInstance) processInstance).getVariable("listOut");
    assertNotNull(listOut);
    assertEquals(2, listOut.size());
    assertEquals("new value", listOut.get(0));
    assertEquals("new value", listOut.get(1));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)59 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