diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index 03a7e6be1d8..7029ebd9832 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java @@ -99,6 +99,7 @@ import org.jbpm.test.utils.EventTrackerProcessListener; import org.jbpm.test.utils.ProcessTestHelper; import org.jbpm.test.utils.ProcessTestHelper.CompletionKogitoEventListener; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -113,7 +114,6 @@ import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.internal.process.workitem.KogitoWorkItem; import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler; import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager; @@ -541,36 +541,34 @@ public void testEventBasedSplit4() { } @Test - public void testEventBasedSplit5() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-EventBasedSplit5.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler()); + public void testEventBasedSplit5() { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Email1", new SystemOutWorkItemHandler()); + ProcessTestHelper.registerHandler(app, "Email2", new SystemOutWorkItemHandler()); ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler); - // Yes - KogitoProcessInstance processInstance = kruntime.startProcess("EventBasedSplit5"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler); + ProcessTestHelper.registerHandler(app, "Receive Task", receiveTaskHandler); - receiveTaskHandler.getWorkItemId().stream().findFirst().ifPresent(id -> kruntime.getKogitoWorkItemManager().completeWorkItem(id, Map.of("Message", "YesValue"))); - - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); - - receiveTaskHandler.getWorkItemId().forEach(id -> kruntime.getKogitoWorkItemManager().completeWorkItem(id, Map.of("Message", "NoValue"))); + org.kie.kogito.process.Process processDefinition = EventBasedSplit5Process.newProcess(app); + EventBasedSplit5Model model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + Assertions.assertNull(instance.variables().getX()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler); - // No - processInstance = kruntime.startProcess("EventBasedSplit5"); - receiveTaskHandler.getWorkItemId().stream().findFirst().ifPresent(id -> kruntime.getKogitoWorkItemManager().completeWorkItem(id, Map.of("Message", "NoValue"))); + receiveTaskHandler.getWorkItemId().stream().findFirst().ifPresent(id -> instance.completeWorkItem(id, Map.of("Message", "YesValue"))); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isEqualTo("YesValue"); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + processDefinition = EventBasedSplit5Process.newProcess(app); + model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance2 = processDefinition.createInstance(model); + instance2.start(); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + Assertions.assertNull(instance2.variables().getX()); - receiveTaskHandler.getWorkItemId().forEach(id -> kruntime.getKogitoWorkItemManager().completeWorkItem(id, Map.of("Message", "YesValue"))); + receiveTaskHandler.getWorkItemId().stream().findFirst().ifPresent(id -> instance2.completeWorkItem(id, Map.of("Message", "NoValue"))); + assertThat(instance2.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instance2.variables().getX()).isEqualTo("NoValue"); } @@ -1494,28 +1492,27 @@ public void testIntermediateCatchEventConditionFilterByProcessInstance() throws @Test @RequirePersistence(false) - public void testIntermediateCatchEventTimerCycleWithError() throws Exception { + public void testIntermediateCatchEventTimerCycleWithError() { + + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(countDownListener); - Map params = new HashMap<>(); - params.put("x", 0); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventTimerCycleWithError", - params); - assertProcessInstanceActive(processInstance); - // now wait for 1 second for timer to trigger - countDownListener.waitTillCompleted(); - assertProcessInstanceActive(processInstance); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycleWithErrorProcess.newProcess(app); + IntermediateCatchEventTimerCycleWithErrorModel model = definition.createModel(); + model.setX(0); + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - Integer xValue = (Integer) ((KogitoWorkflowProcessInstance) processInstance).getVariable("x"); - assertThat(xValue).isEqualTo(3); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - kruntime.abortProcessInstance(processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); + countDownListener.waitTillCompleted(); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + Integer xValue = processInstance.variables().getX(); + assertThat(xValue).isGreaterThan(0); + assertThat(xValue).isLessThanOrEqualTo(3); + processInstance.abort(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); }