Search in sources :

Example 71 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testEventSubprocessTimerCycle.

@Test(timeout = 10000)
@RequirePersistence
public void testEventSubprocessTimerCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Script Task 1", 4);
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessTimerCycle.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessTimer");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "start-sub", "Script Task 1", "end-sub");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 72 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testTimerBoundaryEventCronCycleVariable.

@Test(timeout = 10000)
public void testTimerBoundaryEventCronCycleVariable() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Send Update Timer", 3);
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryTimerCycleCronVariable.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("cronStr", "0/1 * * * * ?");
    ProcessInstance processInstance = ksession.startProcess("boundaryTimerCycleCron", parameters);
    assertProcessInstanceActive(processInstance);
    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(1);
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(3);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 73 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testEventSubprocessMessageWithLocalVars.

@Test(timeout = 10000)
public void testEventSubprocessMessageWithLocalVars() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
    KieBase kbase = createKnowledgeBase("subprocess/BPMN2-EventSubProcessWithLocalVariables.bpmn2");
    final Set<String> variablevalues = new HashSet<String>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            @SuppressWarnings("unchecked") Map<String, String> variable = (Map<String, String>) event.getNodeInstance().getVariable("richiesta");
            if (variable != null) {
                variablevalues.addAll(variable.keySet());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    ksession.addEventListener(countDownListener);
    ProcessInstance processInstance = ksession.startProcess("EventSPWithVars");
    assertProcessInstanceActive(processInstance);
    Map<String, String> data = new HashMap<String, String>();
    ksession.signalEvent("Message-MAIL", data, processInstance.getId());
    countDownListener.waitTillCompleted();
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertThat(processInstance).isNull();
    assertThat(variablevalues.size()).isEqualTo(2);
    assertThat(variablevalues.contains("SCRIPT1")).isTrue();
    assertThat(variablevalues.contains("SCRIPT2")).isTrue();
}
Also used : HashMap(java.util.HashMap) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testMultipleTimerBoundaryEventCronCycleVariable.

@Test(timeout = 10000)
public void testMultipleTimerBoundaryEventCronCycleVariable() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Send Update Timer", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleBoundaryTimerCycleCronVariable.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("cronStr", "0/1 * * * * ?");
    ProcessInstance processInstance = ksession.startProcess("boundaryTimerCycleCron", parameters);
    assertProcessInstanceActive(processInstance);
    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(1);
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(2);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 75 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testTimerBoundaryEventCycle1.

@Test(timeout = 10000)
public void testTimerBoundaryEventCycle1() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventCycle1.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
    ksession.addEventListener(countDownListener);
    ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    ksession = restoreSession(ksession, true);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)132 Test (org.junit.Test)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)101 KieSession (org.kie.api.runtime.KieSession)66 KieBase (org.kie.api.KieBase)61 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)58 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)46 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)42 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)42 HashMap (java.util.HashMap)40 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)39 ArrayList (java.util.ArrayList)35 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)30 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)28 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)26 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)23 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)20 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)19 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)18