Search in sources :

Example 31 with DoNothingWorkItemHandler

use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler 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 32 with DoNothingWorkItemHandler

use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler 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 33 with DoNothingWorkItemHandler

use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler 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)

Example 34 with DoNothingWorkItemHandler

use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testAdHocProcess.

@Test
public void testAdHocProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-AdHocProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("AdHocProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    logger.debug("Triggering node");
    ksession.signalEvent("Task1", null, processInstance.getId());
    assertProcessInstanceActive(processInstance);
    ksession.signalEvent("User1", null, processInstance.getId());
    assertProcessInstanceActive(processInstance);
    ksession.insert(new Person());
    ksession.signalEvent("Task3", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : 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) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Example 35 with DoNothingWorkItemHandler

use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testUserTaskWithDataStoreScenario.

@Test
public void testUserTaskWithDataStoreScenario() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithDataStore.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    ksession.startProcess("UserProcess");
// we can't test further as user tasks are asynchronous.
}
Also used : KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) Test(org.junit.Test)

Aggregations

DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)40 Test (org.junit.Test)39 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)36 KieBase (org.kie.api.KieBase)34 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)30 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)21 KieSession (org.kie.api.runtime.KieSession)12 HashMap (java.util.HashMap)6 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)6 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)4 Person (org.jbpm.bpmn2.objects.Person)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 ArrayList (java.util.ArrayList)3 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)3 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)3 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)3 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2