Java Code Examples for org.kie.internal.runtime.StatefulKnowledgeSession#startProcess()

The following examples show how to use org.kie.internal.runtime.StatefulKnowledgeSession#startProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalBetweenProcesses() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "BPMN2-IntermediateCatchSignalSingle.bpmn2",
            "BPMN2-IntermediateThrowEventSignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
            handler);

    ProcessInstance processInstance = ksession
            .startProcess("BPMN2-IntermediateCatchSignalSingle");
    ksession.getWorkItemManager().completeWorkItem(
            handler.getWorkItem().getId(), null);

    ProcessInstance processInstance2 = ksession
            .startProcess("SignalIntermediateEvent");
    assertProcessInstanceFinished(processInstance2, ksession);

    assertProcessInstanceFinished(processInstance, ksession);
}
 
Example 2
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "BPMN2-SignalBoundaryOnSubProcess.bpmn");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);

    ProcessInstance processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);

    ksession.signalEvent("continue", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();

    ksession = createKnowledgeSession(kbase);

    processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);

    ksession.signalEvent("forward", null);
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example 3
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalEndWithData() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventSignalWithData.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
                                                          new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("testThrowingSignalEvent", params);

    assertProcessInstanceActive(processInstance);
    
    ksession.signalEvent("mysignal", null, processInstance.getId());
    
    assertProcessInstanceCompleted(processInstance);

}
 
Example 4
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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);
    
}
 
Example 5
Source File: ProcessFactoryTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(10)
public void testActionNodeIsDroolsAction() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory
            .name("ActionNodeActionProcess")
            .version("1")
            .startNode(1)
                .name("Start")
                .done()
            .endNode(3)
                .name("End")
                .done()
            .actionNode(2)
                .name("printTextActionNode")
                .action("java",
                        "System.out.println(\"test print\");",
                        true)
                .done()
            .connection(1, 2)
            .connection(2, 3);
    RuleFlowProcess process = factory.validate().getProcess();

    assertNotNull(process);

    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    res.setSourcePath("/tmp/processFactory.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");

    assertNotNull(pi);

    assertEquals(ProcessInstance.STATE_COMPLETED,
                 pi.getState());

    ksession.dispose();
}
 
Example 6
Source File: CamelFileTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleFileProcess() throws IOException {
    final String testData = "test-data";

    HashMap<String, Object> context = setupWithPoolingDataSource("org.jbpm.contrib.camel-workitem");
    Environment env = createEnvironment(context);

    KieBase kbase = createBase();
    StatefulKnowledgeSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
                                                                                          null,
                                                                                          env);

    kieSession.getWorkItemManager().registerWorkItemHandler("CamelFile",
                                                            new FileCamelWorkitemHandler());

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("payloadVar",
               testData);
    params.put("pathVar",
               tempDir.getAbsolutePath());
    params.put("fileNameVar",
               testFile.getName());

    ProcessInstance pi = kieSession.startProcess("camelFileProcess",
                                                 params);

    ProcessInstance result = kieSession.getProcessInstance(pi.getId());
    Assert.assertNull(result);

    Assert.assertTrue("Expected file does not exist.",
                      testFile.exists());

    String resultText = FileUtils.readFileToString(testFile, StandardCharsets.UTF_8);
    Assert.assertEquals(resultText,
                        testData);
}
 
Example 7
Source File: ProcessFactoryTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessFactory() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory
            // header
            .name("My process")
            .packageName("org.jbpm")
            // nodes
            .startNode(1)
                .name("Start")
                .done()
            .actionNode(2)
                .name("Action")
                .action("java",
                        "System.out.println(\"Action\");")
                .done()
            .endNode(3)
                .name("End")
                .done()
            // connections
            .connection(1, 2)
            .connection(2, 3);
    RuleFlowProcess process = factory.validate().getProcess();
    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    res.setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.startProcess("org.jbpm.process");
    ksession.dispose();
}
 
Example 8
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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.
}
 
Example 9
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignalEndWithData() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EndEventSignalWithData.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("src.simpleEndSignal", params);
    
    assertProcessInstanceCompleted(processInstance);
    
}
 
Example 10
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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);
    
}
 
Example 11
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testImplicitEndParallel() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ParallelSplit.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceCompleted(processInstance);
    
}
 
Example 12
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnEntryExitScriptDesigner() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-OnEntryExitDesignerScriptProcess.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());
    
}
 
Example 13
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignalBoundaryEventNoInteruptOnMultiInstanceSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "subprocess/BPMN2-MultiInstanceSubprocessWithBoundarySignalNoInterupting.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    Map<String, Object> params = new HashMap<String, Object>();
    List<String> approvers = new ArrayList<String>();
    approvers.add("john");
    approvers.add("john");

    params.put("approvers", approvers);

    ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
    assertProcessInstanceActive(processInstance);

    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(2);

    ksession.signalEvent("Outside", null, processInstance.getId());

    assertProcessInstanceActive(processInstance.getId(), ksession);

    for (WorkItem wi : workItems) {
    	ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    }
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example 14
Source File: IntermediateEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignalBoundaryEventOnMultiInstanceSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase(
            "subprocess/BPMN2-MultiInstanceSubprocessWithBoundarySignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    Map<String, Object> params = new HashMap<String, Object>();
    List<String> approvers = new ArrayList<String>();
    approvers.add("john");
    approvers.add("john");

    params.put("approvers", approvers);

    ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
    assertProcessInstanceActive(processInstance);

    List<WorkItem> workItems = handler.getWorkItems();
    assertThat(workItems).isNotNull();
    assertThat(workItems.size()).isEqualTo(2);

    ksession.signalEvent("Outside", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);

    ksession.dispose();
}
 
Example 15
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageEnd() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MessageEndEvent.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Send Task",
            new SendTaskHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "MyValue");
    ProcessInstance processInstance = ksession.startProcess(
            "MessageEndEvent", params);
    assertProcessInstanceCompleted(processInstance);
    
}
 
Example 16
Source File: CamelSqlTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelect() {
    Environment env = createEnvironment(context);

    KieBase kbase = createBase();
    StatefulKnowledgeSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
                                                                                          null,
                                                                                          env);

    kieSession.getWorkItemManager().registerWorkItemHandler("CamelSql",
                                                            handler);

    String sqlQuery = "select NAME from TEST";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("Query",
               sqlQuery);
    params.put("DataSource",
               "jdbc/testDS1");

    WorkflowProcessInstance wpi = (WorkflowProcessInstance) kieSession.startProcess("camelSqlProcess",
                                                                                    params);

    Assert.assertEquals(2,
                        ((RuleFlowProcessInstance) wpi).getVariables().size());

    kieSession.dispose();
}
 
Example 17
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEscalationEndEventProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationEndEvent.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession
            .startProcess("EscalationEndEvent");
    assertProcessInstanceAborted(processInstance);
    
}
 
Example 18
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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());
    
}
 
Example 19
Source File: EndEventTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@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);
    
    String 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);
    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();
    
    assertNotNull(nodeId);
    assertTrue(nodeId > 0);
    assertNotNull(nodeInstanceId);
}
 
Example 20
Source File: ProcessFactoryTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
@Timeout(10)
public void testBoundaryTimerTimeCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent",
                                                                                                        1);
    String timeCycle = "1s###5s";
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory
            // header
            .name("My process")
            .packageName("org.jbpm")
            // nodes
            .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)
                .metaData(TIME_CYCLE, timeCycle)
                .metaData(CANCEL_ACTIVITY, false)
                .eventType(EVENT_TYPE_TIMER, timeCycle)
                .done()
            .endNode(5)
                .name("End2")
                .terminate(false)
                .done()
            // connections
            .connection(1, 2)
            .connection(2, 3)
            .connection(4, 5);
    RuleFlowProcess process = factory.validate().getProcess();

    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    res.setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase
    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);

    countDownListener.waitTillCompleted(); // wait for boundary timer firing

    assertNodeTriggered(pi.getId(),
                        "End2");
    assertProcessInstanceActive(pi); // still active because CancelActivity = false

    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(),
                                                   null);
    assertProcessInstanceCompleted(pi);

    ksession.dispose();
}