Search in sources :

Example 81 with StatefulKnowledgeSession

use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.

the class EndEventTest method testOnEntryExitMixedNamespacedScript.

@Test
public void testOnEntryExitMixedNamespacedScript() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-OnEntryExitMixedNamespacedScriptProcess.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new SystemOutWorkItemHandler());
    List<String> myList = new ArrayList<String>();
    ksession.setGlobal("list", myList);
    ProcessInstance processInstance = ksession.startProcess("OnEntryExitScriptProcess");
    assertProcessInstanceCompleted(processInstance);
    assertEquals(4, myList.size());
}
Also used : KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 82 with StatefulKnowledgeSession

use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.

the class EndEventTest method testTerminateWithinSubprocessEnd.

@Test
public void testTerminateWithinSubprocessEnd() throws Exception {
    KieBase kbase = createKnowledgeBase("subprocess/BPMN2-SubprocessWithParallelSpitTerminate.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-SubprocessWithParallelSpitTerminate");
    ksession.signalEvent("signal1", null, processInstance.getId());
    assertProcessInstanceCompleted(processInstance);
}
Also used : KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 83 with StatefulKnowledgeSession

use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.

the class EndEventTest method testTerminateEnd.

@Test
public void testTerminateEnd() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ParallelSpitTerminate.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ParallelSpitTerminate");
    ksession.signalEvent("Signal 1", null, processInstance.getId());
    assertProcessInstanceCompleted(processInstance);
}
Also used : KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 84 with StatefulKnowledgeSession

use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.

the class EndEventTest method testMessageEndVerifyDeploymentId.

@Test
public void testMessageEndVerifyDeploymentId() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MessageEndEvent.bpmn2");
    TestWorkItemHandler handler = new TestWorkItemHandler();
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Send Task", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "MyValue");
    ProcessInstance processInstance = ksession.startProcess("MessageEndEvent", params);
    assertProcessInstanceCompleted(processInstance);
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
    long nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
    long nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
    String deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
    assertNotNull(nodeId);
    assertTrue(nodeId > 0);
    assertNotNull(nodeInstanceId);
    assertTrue(nodeInstanceId > 0);
    assertNull(deploymentId);
    // now set deployment id as part of ksession's env
    ksession.getEnvironment().set("deploymentId", "testDeploymentId");
    processInstance = ksession.startProcess("MessageEndEvent", params);
    assertProcessInstanceCompleted(processInstance);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
    nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
    nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
    deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
    assertNotNull(nodeId);
    assertTrue(nodeId > 0);
    assertNotNull(nodeInstanceId);
    assertTrue(nodeInstanceId > 0);
    assertNotNull(deploymentId);
    assertEquals("testDeploymentId", deploymentId);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 85 with StatefulKnowledgeSession

use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.

the class EndEventTest method testErrorEndEventProcess.

@Test
public void testErrorEndEventProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorEndEvent.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("ErrorEndEvent");
    assertProcessInstanceAborted(processInstance);
    assertEquals("error", ((org.jbpm.process.instance.ProcessInstance) processInstance).getOutcome());
}
Also used : KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)114 Test (org.junit.Test)79 KieBase (org.kie.api.KieBase)52 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)40 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)30 ArrayList (java.util.ArrayList)29 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)22 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)20 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)18 HashMap (java.util.HashMap)16 Environment (org.kie.api.runtime.Environment)12 KieSession (org.kie.api.runtime.KieSession)11 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)11 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)10 ClassPathResource (org.drools.core.io.impl.ClassPathResource)9 WorkItem (org.kie.api.runtime.process.WorkItem)9 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)8 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)8 Resource (org.kie.api.io.Resource)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7