Search in sources :

Example 11 with RequirePersistence

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

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

the class ActivityTest method testNullVariableInScriptTaskProcess.

@RequirePersistence
@Test(timeout = 10000)
public void testNullVariableInScriptTaskProcess() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer", 1, true);
    KieBase kbase = createKnowledgeBase("BPMN2-NullVariableInScriptTaskProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    ProcessInstance processInstance = ksession.startProcess("nullVariableInScriptAfterTimer");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
    assertNotNull(pi);
    assertProcessInstanceActive(processInstance);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : 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) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 13 with RequirePersistence

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

the class ActivityTest method testRuleTaskSetVariable.

@Test
@RequirePersistence(true)
public void testRuleTaskSetVariable() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTask2.bpmn2", "BPMN2-RuleTaskSetVariable.drl");
    ksession = createKnowledgeSession(kbase);
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
    ut.commit();
    assertTrue(list.size() == 1);
    assertProcessVarValue(processInstance, "x", "AnotherString");
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : UserTransaction(javax.transaction.UserTransaction) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) 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 14 with RequirePersistence

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

the class ActivityTest method testCallActivityWithTimer.

@Test(timeout = 10000)
@RequirePersistence
public void testCallActivityWithTimer() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer", 1);
    KieBase kbase = createKnowledgeBase("BPMN2-ParentProcess.bpmn2", "BPMN2-SubProcessWithTimer.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>();
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    Map<String, Object> res = new HashMap<String, Object>();
    res.put("sleep", "2s");
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), res);
    long sessionId = ksession.getIdentifier();
    Environment env = ksession.getEnvironment();
    logger.info("dispose");
    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) 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 15 with RequirePersistence

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

the class ActivityTest method testRuleTaskWithFacts.

@Test
@RequirePersistence(false)
public void testRuleTaskWithFacts() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new AgendaEventListener() {

        public void matchCreated(MatchCreatedEvent event) {
        }

        public void matchCancelled(MatchCancelledEvent event) {
        }

        public void beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
        }

        public void beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
        }

        public void beforeMatchFired(BeforeMatchFiredEvent event) {
        }

        public void agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent event) {
        }

        public void agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent event) {
        }

        public void afterRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
        }

        public void afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
            ksession.fireAllRules();
        }

        public void afterMatchFired(AfterMatchFiredEvent event) {
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
    params = new HashMap<String, Object>();
    try {
        processInstance = ksession.startProcess("RuleTask", params);
        fail("Should fail");
    } catch (Exception e) {
        e.printStackTrace();
    }
    params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : HashMap(java.util.HashMap) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) KieBase(org.kie.api.KieBase) MatchCancelledEvent(org.kie.api.event.rule.MatchCancelledEvent) DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) BeforeMatchFiredEvent(org.kie.api.event.rule.BeforeMatchFiredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) MatchCreatedEvent(org.kie.api.event.rule.MatchCreatedEvent) 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