Search in sources :

Example 1 with NodeLeftCountDownProcessEventListener

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

the class ActivityTest method testProcesWithHumanTaskWithTimer.

@Test(timeout = 10000)
@RequirePersistence
public void testProcesWithHumanTaskWithTimer() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-SubProcessWithTimer.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("subproc", params);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    long sessionId = ksession.getIdentifier();
    Environment env = ksession.getEnvironment();
    ksession.dispose();
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
    ksession.addEventListener(countDownListener);
    countDownListener.waitTillCompleted();
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Environment(org.kie.api.runtime.Environment) 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 2 with NodeLeftCountDownProcessEventListener

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

the class ActivityTest method testCallActivityWithBoundaryEvent.

@Test
public void testCallActivityWithBoundaryEvent() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Boundary event", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-CallActivityWithBoundaryEvent.bpmn2", "BPMN2-CallActivitySubProcessWithBoundaryEvent.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    countDownListener.waitTillCompleted();
    assertProcessInstanceFinished(processInstance, ksession);
    // assertEquals("new timer value",
    // ((WorkflowProcessInstance) processInstance).getVariable("y"));
    // first check the parent process executed nodes
    assertNodeTriggered(processInstance.getId(), "StartProcess", "CallActivity", "Boundary event", "Script Task", "end");
    // then check child process executed nodes - is there better way to get child process id than simply increment?
    assertNodeTriggered(processInstance.getId() + 1, "StartProcess2", "User Task");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with NodeLeftCountDownProcessEventListener

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

the class ProcessFactoryTest method testBoundaryTimerTimeDuration.

@Test(timeout = 10000)
public void testBoundaryTimerTimeDuration() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeDuration("1s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
    RuleFlowProcess process = factory.validate().getProcess();
    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    // source path or target path must be set to be added into kbase
    res.setSourcePath("/tmp/processFactory.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(countDownListener);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertProcessInstanceActive(pi);
    // wait for boundary timer firing
    countDownListener.waitTillCompleted();
    assertNodeTriggered(pi.getId(), "End2");
    // still active because CancelActivity = false
    assertProcessInstanceActive(pi);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(pi);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 4 with NodeLeftCountDownProcessEventListener

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

the class ProcessFactoryTest method testBoundaryTimerTimeCycle.

@Test(timeout = 10000)
public void testBoundaryTimerTimeCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeCycle("1s###5s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
    RuleFlowProcess process = factory.validate().getProcess();
    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    // source path or target path must be set to be added into kbase
    res.setSourcePath("/tmp/processFactory.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(countDownListener);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertProcessInstanceActive(pi);
    // wait for boundary timer firing
    countDownListener.waitTillCompleted();
    assertNodeTriggered(pi.getId(), "End2");
    // still active because CancelActivity = false
    assertProcessInstanceActive(pi);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(pi);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 5 with NodeLeftCountDownProcessEventListener

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

the class StartEventTest method testTimerCycle.

@Test(timeout = 10000)
public void testTimerCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 5);
    KieBase kbase = createKnowledgeBase("timer/BPMN2-StartTimerCycle.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    StartCountingListener listener = new StartCountingListener();
    ksession.addEventListener(listener);
    countDownListener.waitTillCompleted();
    assertThat(listener.getCount("start.cycle")).isEqualTo(5);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) Test(org.junit.Test)

Aggregations

NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener)147 Test (org.junit.Test)142 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)109 KieSession (org.kie.api.runtime.KieSession)75 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)67 KieBase (org.kie.api.KieBase)62 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)61 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)52 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)46 HashMap (java.util.HashMap)44 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)43 ArrayList (java.util.ArrayList)37 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)34 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)32 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)30 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)25 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)21 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)21 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)20 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.process.NodeTriggeredCountDownProcessEventListener)20