Search in sources :

Example 6 with RequirePersistence

use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.

the class ActivityTest method testCallActivityWithHistoryLog.

@Test
@RequirePersistence
public void testCallActivityWithHistoryLog() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-CallActivity.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals("new value", ((WorkflowProcessInstance) processInstance).getVariable("y"));
    AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment());
    List<ProcessInstanceLog> subprocesses = logService.findSubProcessInstances(processInstance.getId());
    assertNotNull(subprocesses);
    assertEquals(1, subprocesses.size());
    logService.dispose();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 7 with RequirePersistence

use of org.jbpm.bpmn2.test.RequirePersistence 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.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 8 with RequirePersistence

use of org.jbpm.bpmn2.test.RequirePersistence 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 9 with RequirePersistence

use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.

the class IntermediateEventTest method testTimerBoundaryEventCycleISO.

@Test(timeout = 10000)
@RequirePersistence(false)
public void testTimerBoundaryEventCycleISO() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventCycleISO.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    ksession.abortProcessInstance(processInstance.getId());
}
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) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 10 with RequirePersistence

use of org.jbpm.bpmn2.test.RequirePersistence 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)

Aggregations

RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)18 Test (org.junit.Test)18 KieBase (org.kie.api.KieBase)18 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)17 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)17 HashMap (java.util.HashMap)9 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)9 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)6 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)5 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 Environment (org.kie.api.runtime.Environment)4 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)3 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)3 ArrayList (java.util.ArrayList)2 RegistryContext (org.drools.core.command.impl.RegistryContext)2 ProcessPersistenceContext (org.jbpm.persistence.api.ProcessPersistenceContext)2 AuditLogService (org.jbpm.process.audit.AuditLogService)2 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)2 RuleAwareProcessEventLister (org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister)2 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)2