diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java index ba2976103a3..bfe035767a6 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java @@ -51,6 +51,8 @@ import org.jbpm.bpmn2.flow.InclusiveGatewayNestedProcess; import org.jbpm.bpmn2.flow.InclusiveGatewayWithDefaultModel; import org.jbpm.bpmn2.flow.InclusiveGatewayWithDefaultProcess; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessModel; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessProcess; import org.jbpm.bpmn2.flow.InclusiveNestedInParallelNestedInExclusiveModel; import org.jbpm.bpmn2.flow.InclusiveNestedInParallelNestedInExclusiveProcess; import org.jbpm.bpmn2.flow.InclusiveSplitAndJoinEmbeddedModel; @@ -75,9 +77,23 @@ import org.jbpm.bpmn2.flow.InclusiveSplitDefaultProcess; import org.jbpm.bpmn2.flow.InclusiveSplitModel; import org.jbpm.bpmn2.flow.InclusiveSplitProcess; +import org.jbpm.bpmn2.flow.MultiConnEnabledModel; +import org.jbpm.bpmn2.flow.MultiConnEnabledProcess; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessModel; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessProcess; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondModel; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondProcess; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputModel; +import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputProcess; +import org.jbpm.bpmn2.flow.MultiInstanceLoopNumberingModel; +import org.jbpm.bpmn2.flow.MultiInstanceLoopNumberingProcess; +import org.jbpm.bpmn2.flow.MultipleGatewaysProcessModel; +import org.jbpm.bpmn2.flow.MultipleGatewaysProcessProcess; import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsTaskModel; import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsTaskProcess; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.timer.ParallelSplitWithTimerProcessModel; +import org.jbpm.bpmn2.timer.ParallelSplitWithTimerProcessProcess; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.instance.InternalProcessRuntime; import org.jbpm.process.instance.context.variable.VariableScopeInstance; @@ -97,7 +113,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.kie.api.command.ExecutableCommand; -import org.kie.api.definition.process.WorkflowElementIdentifier; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.runtime.Context; @@ -943,55 +958,49 @@ public void testMultiInstanceLoopCharacteristicsProcessWithORGateway() } @Test - public void testInclusiveJoinWithLoopAndHumanTasks() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-InclusiveGatewayWithHumanTasksProcess.bpmn2"); - + public void testInclusiveJoinWithLoopAndHumanTasks() { + Application app = ProcessTestHelper.newApplication(); final Map nodeInstanceExecutionCounter = new HashMap<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { - logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel()); Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName()); if (value == null) { value = 0; } - value++; nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value); } - }); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - Map params = new HashMap<>(); - params.put("firstXor", true); - params.put("secondXor", true); - params.put("thirdXor", true); - KogitoProcessInstance processInstance = kruntime.startProcess("InclusiveGatewayWithHumanTasksProcess", params); - // simulate completion of first task - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertProcessInstanceActive(processInstance); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + org.kie.kogito.process.Process definition = InclusiveGatewayWithHumanTasksProcessProcess.newProcess(app); + InclusiveGatewayWithHumanTasksProcessModel model = definition.createModel(); + model.setFirstXor(true); + model.setSecondXor(true); + model.setThirdXor(true); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.completeWorkItem(handler.getWorkItem().getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); - KogitoWorkItem remainingWork = null; for (KogitoWorkItem wi : workItems) { - assertProcessInstanceActive(processInstance); - // complete second task that will trigger converging OR gateway + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); if (wi.getParameter("NodeName").equals("HT Form2")) { - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), null); + processInstance.completeWorkItem(wi.getStringId(), null); } else { remainingWork = wi; } } - - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(remainingWork.getStringId(), null); - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertProcessInstanceCompleted(processInstance); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + assertThat(remainingWork).isNotNull(); + processInstance.completeWorkItem(remainingWork.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.completeWorkItem(handler.getWorkItem().getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(nodeInstanceExecutionCounter).hasSize(13); assertThat((int) nodeInstanceExecutionCounter.get("Start")).isEqualTo(1); assertThat((int) nodeInstanceExecutionCounter.get("HT Form1")).isEqualTo(1); @@ -1009,50 +1018,48 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { } @Test - public void testMultiInstanceLoopCharacteristicsProcess() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultiInstanceLoopCharacteristicsProcess.bpmn2"); - Map params = new HashMap<>(); + public void testMultiInstanceLoopCharacteristicsProcess() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process definition = MultiInstanceLoopCharacteristicsProcessProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessModel model = definition.createModel(); List myList = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MultiInstanceLoopCharacteristicsProcess", params); - assertProcessInstanceCompleted(processInstance); + model.setList(myList); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testMultiInstanceLoopNumberTest() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultiInstanceLoopNumbering.bpmn2"); - Map params = new HashMap<>(); - + public void testMultiInstanceLoopNumberTest() { + Application app = ProcessTestHelper.newApplication(); final Map nodeIdNodeNameMap = new HashMap<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { NodeInstance nodeInstance = event.getNodeInstance(); String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId(); String nodeName = nodeInstance.getNode().getName(); - String prevNodeName = nodeIdNodeNameMap.put(uniqId, nodeName); if (prevNodeName != null) { assertThat(prevNodeName).as(uniqId + " is used for more than one node instance: ").isEqualTo(nodeName); } } - }); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - KogitoProcessInstance processInstance = kruntime.startProcess("MultiInstanceLoopNumbering", params); - + ProcessTestHelper.registerHandler(app, "Human Task", handler); + org.kie.kogito.process.Process definition = MultiInstanceLoopNumberingProcess.newProcess(app); + MultiInstanceLoopNumberingModel model = definition.createModel(); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); List workItems = handler.getWorkItems(); logger.debug("COMPLETING TASKS."); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItems.remove(0).getStringId(), null); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItems.remove(0).getStringId(), null); - assertProcessInstanceCompleted(processInstance); - + processInstance.completeWorkItem(workItems.remove(0).getStringId(), null); + processInstance.completeWorkItem(workItems.remove(0).getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -1094,41 +1101,39 @@ public void testMultiInstanceLoopCharacteristicsProcess2() throws Exception { } @Test - public void testMultiInstanceLoopCharacteristicsProcessWithOutput() - throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultiInstanceLoopCharacteristicsProcessWithOutput.bpmn2"); - Map params = new HashMap<>(); + public void testMultiInstanceLoopCharacteristicsProcessWithOutput() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = MultiInstanceLoopCharacteristicsProcessWithOutputProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessWithOutputModel model = definition.createModel(); List myList = new ArrayList<>(); List myListOut = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - params.put("listOut", myListOut); + model.setList(myList); + model.setListOut(myListOut); assertThat(myListOut).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MultiInstanceLoopCharacteristicsProcessWithOutput", params); - assertProcessInstanceCompleted(processInstance); - assertThat(myListOut).hasSize(2); - + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(model.getListOut()).hasSize(2); } @Test - public void testMultiInstanceLoopCharacteristicsProcessWithOutputCompletionCondition() - throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultiInstanceLoopCharacteristicsProcessWithOutputCmpCond.bpmn2"); - Map params = new HashMap<>(); + public void testMultiInstanceLoopCharacteristicsProcessWithOutputCompletionCondition() throws Exception { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondModel model = definition.createModel(); List myList = new ArrayList<>(); List myListOut = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - params.put("listOut", myListOut); + model.setList(myList); + model.setListOut(myListOut); assertThat(myListOut).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MultiInstanceLoopCharacteristicsProcessWithOutputCmpCond", params); - assertProcessInstanceCompleted(processInstance); - assertThat(myListOut).hasSize(1); - + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(model.getListOut()).hasSize(1); } @Test @@ -1284,26 +1289,25 @@ public void testMultipleIncomingFlowToEndNode() throws Exception { @Test public void testMultipleEnabledOnSingleConditionalSequenceFlow() throws Exception { System.setProperty("jbpm.enable.multi.con", "true"); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultiConnEnabled.bpmn2"); - - final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - public void afterNodeTriggered(org.kie.api.event.process.ProcessNodeTriggeredEvent event) { + Application app = ProcessTestHelper.newApplication(); + final List list = new ArrayList<>(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { if ("Task2".equals(event.getNodeInstance().getNodeName())) { - list.add(event.getNodeInstance().getNodeId()); + list.add(String.valueOf(event.getNodeInstance().getNodeId())); } } }); - + org.kie.kogito.process.Process definition = MultiConnEnabledProcess.newProcess(app); + ProcessInstance processInstance = definition.createInstance(definition.createModel()); assertThat(list).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess("MultiConnEnabled"); - assertProcessInstanceActive(processInstance); - kruntime.signalEvent("signal", null, processInstance.getStringId()); - assertProcessInstanceCompleted(processInstance); - + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("signal", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(list).hasSize(1); System.clearProperty("jbpm.enable.multi.con"); - } @Test @@ -1373,15 +1377,19 @@ public void testExclusiveSplitDefaultNoCondition() throws Exception { } @Test - public void testMultipleGatewaysProcess() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-MultipleGatewaysProcess.bpmn2"); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - KogitoProcessInstance pi; + public void testMultipleGatewaysProcess() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = MultipleGatewaysProcessProcess.newProcess(app); + MultipleGatewaysProcessModel model = definition.createModel(); + model.setAction("CreateAgent"); + + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + ProcessInstance pi; @Override public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { if (event.getNodeInstance().getNodeName().equals("CreateAgent")) { - pi.signalEvent("Signal_1", null); + pi.send(Sig.of("Signal_1", null)); } } @@ -1392,53 +1400,37 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { @Override public void beforeProcessStarted(ProcessStartedEvent event) { - pi = (KogitoProcessInstance) event.getProcessInstance(); - + pi = (ProcessInstance) event.getProcessInstance(); } }); - Map params = new HashMap<>(); - params.put("action", "CreateAgent"); - KogitoProcessInstance processInstance = kruntime.startProcess("MultipleGatewaysProcess", params); - assertProcessInstanceCompleted(processInstance); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testTimerAndGateway() throws Exception { + public void testTimerAndGateway() { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-ParallelSplitWithTimerProcess.bpmn2"); - - kruntime.getProcessEventManager().addEventListener(countDownListener); - + ProcessTestHelper.registerProcessEventListener(app, countDownListener); TestWorkItemHandler handler1 = new TestWorkItemHandler(); TestWorkItemHandler handler2 = new TestWorkItemHandler(); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task1", handler1); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task2", handler2); - - KogitoProcessInstance instance = kruntime.createProcessInstance("ParallelSplitWithTimerProcess", new HashMap<>()); - kruntime.startProcessInstance(instance.getStringId()); - + ProcessTestHelper.registerHandler(app, "task1", handler1); + ProcessTestHelper.registerHandler(app, "task2", handler2); + org.kie.kogito.process.Process definition = ParallelSplitWithTimerProcessProcess.newProcess(app); + ProcessInstance processInstance = definition.createInstance(definition.createModel()); + processInstance.start(); KogitoWorkItem workItem1 = handler1.getWorkItem(); assertThat(workItem1).isNotNull(); assertThat(handler1.getWorkItem()).isNull(); - //first safe state: task1 completed - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem1.getStringId(), null); - kruntime.getProcessEventManager().addEventListener(countDownListener); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task1", handler1); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task2", handler2); - //second safe state: timer completed, waiting on task2 + processInstance.completeWorkItem(workItem1.getStringId(), null); countDownListener.waitTillCompleted(); - KogitoWorkItem workItem2 = handler2.getWorkItem(); - //Both sides of the join are completed. But on the process instance, there are two - //JoinInstance for the same Join, and since it is an AND join, it never reaches task2 - //It fails after the next assertion assertThat(workItem2).isNotNull(); assertThat(handler2.getWorkItem()).isNull(); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem2.getStringId(), null); - assertProcessInstanceCompleted(instance); + processInstance.completeWorkItem(workItem2.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } private static class GetProcessVariableCommand implements ExecutableCommand {