Search in sources :

Example 81 with NodeLeftCountDownProcessEventListener

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

the class StandaloneBPMNProcessTest method testTimerBoundaryEventInterrupting.

@Test(timeout = 10000)
public void testTimerBoundaryEventInterrupting() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventInterrupting.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    countDownListener.waitTillCompleted();
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 82 with NodeLeftCountDownProcessEventListener

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

the class IntermediateEventTest method testIntermediateTimerEventMI.

@Test(timeout = 10000)
public void testIntermediateTimerEventMI() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("After timer", 3);
    KieBase kbase = createKnowledgeBase("timer/BPMN2-IntermediateTimerEventMI.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("defaultprocessid");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance.getId(), ksession);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceAborted(processInstance.getId(), ksession);
}
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) Test(org.junit.Test)

Example 83 with NodeLeftCountDownProcessEventListener

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

the class IntermediateEventTest method testIntermediateCatchEventTimerCycleWithErrorWithPersistence.

@Test(timeout = 10000)
@RequirePersistence
public void testIntermediateCatchEventTimerCycleWithErrorWithPersistence() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    ksession.addEventListener(countDownListener);
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertProcessInstanceActive(processInstance);
    final long piId = processInstance.getId();
    ksession.execute(new ExecutableCommand<Void>() {

        public Void execute(Context context) {
            StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
            WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
            processInstance.setVariable("x", 0);
            return null;
        }
    });
    // now wait for 1 second for timer to trigger
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    Integer xValue = ksession.execute(new ExecutableCommand<Integer>() {

        public Integer execute(Context context) {
            StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
            WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
            return (Integer) processInstance.getVariable("x");
        }
    });
    assertThat(xValue).isEqualTo(2);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) Context(org.kie.api.runtime.Context) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) RegistryContext(org.drools.core.command.impl.RegistryContext) 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) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 84 with NodeLeftCountDownProcessEventListener

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

the class IntermediateEventTest method testIntermediateCatchEventTimerCycleWithError.

@Test(timeout = 10000)
@RequirePersistence(false)
public void testIntermediateCatchEventTimerCycleWithError() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    ksession.addEventListener(countDownListener);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 0);
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
    assertProcessInstanceActive(processInstance);
    // now wait for 1 second for timer to trigger
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    Integer xValue = (Integer) ((WorkflowProcessInstance) processInstance).getVariable("x");
    assertThat(xValue).isEqualTo(3);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) 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) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 85 with NodeLeftCountDownProcessEventListener

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

the class IntermediateEventTest method testTimerBoundaryEventDurationISO.

@Test(timeout = 10000)
public void testTimerBoundaryEventDurationISO() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventDurationISO.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