From 60eb002530362db85bca609459219d04bb36ae5c Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:00:47 +0100 Subject: [PATCH 1/7] [Fix #3809] Allowing additional properties on user input (#3810) --- .../workflow/models/JsonNodeModel.java | 9 ++++++++ .../workflow/models/JsonNodeModelInput.java | 21 ++++++++++++------- .../quarkus/workflows/ExpressionRestIT.java | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java index cd8bdb78ebf..0897cc77290 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java @@ -50,7 +50,15 @@ public JsonNodeModel(Object workflowdata) { this(null, workflowdata); } + public JsonNodeModel(Object workflowdata, Map additionalProperties) { + this(null, workflowdata, additionalProperties); + } + public JsonNodeModel(String id, Object workflowdata) { + this(id, workflowdata, Collections.emptyMap()); + } + + public JsonNodeModel(String id, Object workflowdata, Map additionalProperties) { this.id = id; if (workflowdata instanceof JsonNode) { this.workflowdata = (JsonNode) workflowdata; @@ -59,6 +67,7 @@ public JsonNodeModel(String id, Object workflowdata) { this.workflowdata = workflowdata == null ? mapper.createObjectNode() : mapper.convertValue(workflowdata, JsonNode.class); } this.input = this.workflowdata.deepCopy(); + this.additionalProperties = additionalProperties == null ? Collections.emptyMap() : additionalProperties; } public String getId() { diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java index 98adedb04f5..d53aa9ea777 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java @@ -18,20 +18,23 @@ */ package org.kie.kogito.serverless.workflow.models; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + import org.kie.kogito.MapInput; import org.kie.kogito.MapInputId; import org.kie.kogito.MapOutput; import org.kie.kogito.MappableToModel; import org.kie.kogito.Model; -import org.kie.kogito.jackson.utils.ObjectMapperFactory; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonNodeModelInput implements Model, MapInput, MapInputId, MapOutput, MappableToModel { private Object workflowdata; + private Map additionalProperties; public Object getWorkflowdata() { return workflowdata; @@ -39,16 +42,18 @@ public Object getWorkflowdata() { @JsonAnySetter public void setData(String key, JsonNode value) { - if (workflowdata == null) { - workflowdata = ObjectMapperFactory.listenerAware().createObjectNode(); - } - if (workflowdata instanceof ObjectNode) { - ((ObjectNode) workflowdata).set(key, value); + if (additionalProperties == null) { + additionalProperties = new LinkedHashMap<>(); } + additionalProperties.put(key, value); } @Override public JsonNodeModel toModel() { - return new JsonNodeModel(workflowdata); + if (workflowdata == null) { + workflowdata = additionalProperties; + additionalProperties = Collections.emptyMap(); + } + return new JsonNodeModel(workflowdata, additionalProperties); } } diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java index d6d4122929d..5f0b44234a8 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java @@ -38,7 +38,7 @@ void testExpressionRest() { .contentType(ContentType.JSON) .accept(ContentType.JSON) .header("pepe", "pepa") - .body("{\"workflowdata\":{\"numbers\":[{\"x\":2, \"y\": 1},{\"x\":4, \"y\": 3}]}}").when() + .body("{\"workflowdata\":{\"numbers\":[{\"x\":2, \"y\": 1},{\"x\":4, \"y\": 3}]}, \"randomAdditionalProperty\":\"Im ignored in runtimes but will be visible on data index\"}").when() .post("/expression") .then() .statusCode(201) From 23d23c22993d86e2837b42af8fd7f934cfeaa1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Mu=C3=B1oz?= Date: Tue, 10 Dec 2024 17:56:25 +0100 Subject: [PATCH 2/7] [Fix_#1632] Update postgres to 15.9 version (#3791) --- addons/common/persistence/postgresql/pom.xml | 7 ++++++- kogito-build/kogito-dependencies-bom/pom.xml | 9 ++++++++- .../pom.xml | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/common/persistence/postgresql/pom.xml b/addons/common/persistence/postgresql/pom.xml index 4b3048dbdba..3146ed7ce54 100644 --- a/addons/common/persistence/postgresql/pom.xml +++ b/addons/common/persistence/postgresql/pom.xml @@ -97,6 +97,11 @@ logback-classic test + + com.ongres.scram + client + test + @@ -142,4 +147,4 @@ - \ No newline at end of file + diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml index 9d4c812444c..255dcd8f91a 100644 --- a/kogito-build/kogito-dependencies-bom/pom.xml +++ b/kogito-build/kogito-dependencies-bom/pom.xml @@ -47,6 +47,7 @@ 2.17.2 2.17.2 2.9.0 + 2.1 2.4.10 1.0.0-preview.20240207 2.0.2 @@ -118,7 +119,7 @@ 4.4.14 1.7.13 2.0.4 - 13.4-alpine3.14 + 15.9-alpine3.20 1.11.4 3.24.2 @@ -595,6 +596,12 @@ ${version.com.github.tomakehurst.wiremock} test + + com.ongres.scram + client + ${version.com.ongres.scram} + test + org.apache.maven.shared diff --git a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/pom.xml b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/pom.xml index 4b3b7c24628..5a2782c45e4 100644 --- a/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/pom.xml +++ b/springboot/integration-tests/integration-tests-springboot-processes-persistence-it/integration-tests-springboot-processes-postgresql/pom.xml @@ -97,6 +97,16 @@ awaitility test + + io.vertx + vertx-pg-client + test + + + com.ongres.scram + client + test + From 880cc582831d593a35da2cacf91cca0dfa31b0bd Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Wed, 11 Dec 2024 16:49:31 +0900 Subject: [PATCH 3/7] [incubator-kie-drools-6160] Clean up leftover of .rf support (#3811) --- .../org/jbpm/weaver/DRFWeaverService.java | 30 ------------------- ...g.kie.api.internal.weaver.KieWeaverService | 3 +- 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100755 jbpm/jbpm-flow-builder/src/main/java/org/jbpm/weaver/DRFWeaverService.java diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/weaver/DRFWeaverService.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/weaver/DRFWeaverService.java deleted file mode 100755 index 881ee35e49a..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/weaver/DRFWeaverService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.weaver; - -import org.kie.api.io.ResourceType; - -public class DRFWeaverService extends AbstractWeaverService { - - @Override - public ResourceType getResourceType() { - return ResourceType.DRF; - } - -} diff --git a/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.kie.api.internal.weaver.KieWeaverService b/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.kie.api.internal.weaver.KieWeaverService index 94f5d1e8679..5e46d1c110b 100644 --- a/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.kie.api.internal.weaver.KieWeaverService +++ b/jbpm/jbpm-flow-builder/src/main/resources/META-INF/services/org.kie.api.internal.weaver.KieWeaverService @@ -17,5 +17,4 @@ # under the License. # -org.jbpm.weaver.BPMN2WeaverService -org.jbpm.weaver.DRFWeaverService \ No newline at end of file +org.jbpm.weaver.BPMN2WeaverService \ No newline at end of file From bc0702c1c6a36b655aed777f8696ef614377a028 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 13 Dec 2024 01:09:10 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[incubator-kie-issues-1682]=20Test=20cases?= =?UTF-8?q?=20in=20kogito=20repos=20GHA=20fail=20with=20=E2=80=A6=20(#3812?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [incubator-kie-issues-1682] Test cases in kogito repos GHA fail with "pull access denied for vectorized/redpanda" * Fix advertise-kafka-addr in script command --------- Co-authored-by: gmunozfe --- kogito-build/kogito-build-no-bom-parent/pom.xml | 2 +- .../kie/kogito/testcontainers/KogitoKafkaContainer.java | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/kogito-build/kogito-build-no-bom-parent/pom.xml b/kogito-build/kogito-build-no-bom-parent/pom.xml index afe76bd494e..2795ef00b81 100644 --- a/kogito-build/kogito-build-no-bom-parent/pom.xml +++ b/kogito-build/kogito-build-no-bom-parent/pom.xml @@ -50,7 +50,7 @@ infinispan/server:${version.org.infinispan} quay.io/keycloak/keycloak:${version.org.keycloak} - vectorized/redpanda:v21.11.8 + redpandadata/redpanda:v24.3.1 wurstmeister/kafka:${version.wurstmeister.kafka} library/mongo:${version.org.mongo-image} redislabs/redisearch:${version.org.redis} diff --git a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java index 6bd3a3dce7e..72c594d4f8f 100644 --- a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java +++ b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java @@ -53,14 +53,13 @@ public KogitoKafkaContainer() { @Override protected void containerIsStarting(InspectContainerResponse containerInfo, boolean reused) { super.containerIsStarting(containerInfo, reused); - String brokerAdvertisedListener = brokerAdvertisedListener(containerInfo); // Start and configure the advertised address String command = "#!/bin/bash\n"; command += "/usr/bin/rpk redpanda start --check=false --node-id 0 --smp 1 "; command += "--memory 1G --overprovisioned --reserve-memory 0M "; command += "--kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092 "; - command += format("--advertise-kafka-addr %s ", String.join(",", getBootstrapServers(), brokerAdvertisedListener)); + command += "--advertise-kafka-addr PLAINTEXT://kafka:29092,OUTSIDE://" + getHost() + ":" + getMappedPort(KAFKA_PORT) + " "; command += "--set redpanda.enable_idempotence=true "; command += "--set redpanda.enable_transactions=true "; @@ -73,10 +72,6 @@ public void start() { LOGGER.info("Kafka servers: {}", getBootstrapServers()); } - protected String brokerAdvertisedListener(InspectContainerResponse containerInfo) { - return String.format("PLAINTEXT://%s:29092", containerInfo.getConfig().getHostName()); - } - public String getBootstrapServers() { return format("OUTSIDE://%s:%d", getHost(), getMappedPort(KAFKA_PORT)); } From 368d76db38358b6164c8d01c8c2566a8dcc97bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Mu=C3=B1oz?= Date: Fri, 13 Dec 2024 12:38:54 +0100 Subject: [PATCH 5/7] [incubator-kie-issues-1682] Add kafka network alias (#3814) --- .../java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java index 72c594d4f8f..69f3e2285de 100644 --- a/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java +++ b/kogito-test-utils/src/main/java/org/kie/kogito/testcontainers/KogitoKafkaContainer.java @@ -47,6 +47,7 @@ public KogitoKafkaContainer() { withExposedPorts(KAFKA_PORT); withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh")); withCommand("-c", "while [ ! -f " + STARTER_SCRIPT + " ]; do sleep 0.1; done; " + STARTER_SCRIPT); + withNetworkAliases("kafka"); waitingFor(Wait.forLogMessage(".*Started Kafka API server.*", 1).withStartupTimeout(Constants.CONTAINER_START_TIMEOUT)); } From e0ebd4b295e34effa9bdfa8f0b5e2dcd5593c2f1 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Tue, 17 Dec 2024 03:28:41 -0500 Subject: [PATCH 6/7] [incubator-kie-issues-1131] test migration from V7 to code generation-35 (#3665) * [incubator-kie-issues-1131] v7 migration to code generation * incubator-kie-issues-1131 --- .../java/org/jbpm/bpmn2/ActivityTest.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java index 4a8cca632c9..4058c91904a 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java @@ -119,6 +119,9 @@ import org.jbpm.bpmn2.subprocess.CallActivityWithBoundaryEventProcess; import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionModel; import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionProcess; +import org.jbpm.bpmn2.subprocess.ErrorsBetweenProcessModel; +import org.jbpm.bpmn2.subprocess.ErrorsBetweenProcessProcess; +import org.jbpm.bpmn2.subprocess.ErrorsBetweenSubProcessProcess; import org.jbpm.bpmn2.subprocess.InputMappingUsingValueModel; import org.jbpm.bpmn2.subprocess.InputMappingUsingValueProcess; import org.jbpm.bpmn2.subprocess.MainGroupAssignmentModel; @@ -176,6 +179,7 @@ import org.kie.api.definition.process.NodeContainer; import org.kie.api.definition.process.Process; import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; @@ -1497,20 +1501,26 @@ public void testServiceTaskWithMvelJaxbTransformation() throws Exception { } @Test - public void testErrorBetweenProcessesProcess() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-ErrorsBetweenProcess.bpmn2", - "org/jbpm/bpmn2/subprocess/BPMN2-ErrorsBetweenSubProcess.bpmn2"); - - Map variables = new HashMap<>(); - - variables.put("tipoEvento", "error"); - variables.put("pasoVariable", 3); - KogitoProcessInstance processInstance = kruntime.startProcess("ErrorsBetweenProcess", variables); - - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); - assertProcessInstanceAborted(processInstance.getStringId() + 1, kruntime); + public void testErrorBetweenProcessesProcess() { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + if ("ErrorsBetweenSubProcess".equals(event.getProcessInstance().getProcessId())) { + assertThat(event.getProcessInstance().getState()).isEqualTo(ProcessInstance.STATE_ABORTED); + } + } + }); + ErrorsBetweenSubProcessProcess.newProcess(app); + org.kie.kogito.process.Process process = ErrorsBetweenProcessProcess.newProcess(app); + ErrorsBetweenProcessModel model = process.createModel(); + model.setTipoEvento("error"); + model.setPasoVariable(3); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); - assertProcessVarValue(processInstance, "event", "error desde Subproceso"); + assertThat(processInstance.variables().getEvent()).isEqualTo("error desde Subproceso"); } @Test From 6a3c526c2ad2231ccb62863d5372a282f777c853 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Tue, 17 Dec 2024 03:34:46 -0500 Subject: [PATCH 7/7] [incubator-kie-issues-1131] test migration from V7 to code generation-22 (#3639) * [incubator-kie-issues-1131] v7 migration to code generation * incubator-kie-issues-1612 * incubator-kie-issues-1131 --- .../org/jbpm/bpmn2/IntermediateEventTest.java | 1492 +++++++++-------- 1 file changed, 767 insertions(+), 725 deletions(-) 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 bace4169053..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 @@ -20,6 +20,7 @@ import java.time.OffsetDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -40,65 +41,7 @@ import org.jbpm.bpmn2.event.BoundaryTimerCycleISOProcess; import org.jbpm.bpmn2.event.BoundaryTimerCycleISOVariableModel; import org.jbpm.bpmn2.event.BoundaryTimerCycleISOVariableProcess; -import org.jbpm.bpmn2.intermediate.BoundarySignalEventOnTaskModel; -import org.jbpm.bpmn2.intermediate.BoundarySignalEventOnTaskProcess; -import org.jbpm.bpmn2.intermediate.EventBasedSplit2Model; -import org.jbpm.bpmn2.intermediate.EventBasedSplit2Process; -import org.jbpm.bpmn2.intermediate.EventBasedSplit4Model; -import org.jbpm.bpmn2.intermediate.EventBasedSplit4Process; -import org.jbpm.bpmn2.intermediate.EventBasedSplitModel; -import org.jbpm.bpmn2.intermediate.EventBasedSplitProcess; -import org.jbpm.bpmn2.intermediate.EventSubprocessErrorSignalEmbeddedModel; -import org.jbpm.bpmn2.intermediate.EventSubprocessErrorSignalEmbeddedProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithRefModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithRefProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Model; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Process; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle1Model; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle1Process; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle2Model; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle2Process; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Model; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Process; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleISOModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleISOProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDateISOModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDateISOProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationISOModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationISOProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcessInstance; -import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksProcess; -import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalSingleModel; -import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalSingleProcess; -import org.jbpm.bpmn2.intermediate.IntermediateLinkEventModel; -import org.jbpm.bpmn2.intermediate.IntermediateLinkEventProcess; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageProcess; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationModel; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationProcess; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventNoneModel; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventNoneProcess; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalModel; -import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalProcess; -import org.jbpm.bpmn2.intermediate.LinkEventCompositeProcessModel; -import org.jbpm.bpmn2.intermediate.LinkEventCompositeProcessProcess; -import org.jbpm.bpmn2.intermediate.SignalBoundaryEventInterruptingModel; -import org.jbpm.bpmn2.intermediate.SignalBoundaryEventInterruptingProcess; +import org.jbpm.bpmn2.intermediate.*; import org.jbpm.bpmn2.loop.MultiInstanceLoopBoundaryTimerModel; import org.jbpm.bpmn2.loop.MultiInstanceLoopBoundaryTimerProcess; import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsProcessSequentialModel; @@ -123,10 +66,22 @@ import org.jbpm.bpmn2.subprocess.EventSubprocessSignalWithTransformationModel; import org.jbpm.bpmn2.subprocess.EventSubprocessSignalWithTransformationProcess; import org.jbpm.bpmn2.test.RequirePersistence; +import org.jbpm.bpmn2.timer.IntermediateTimerEventMIModel; +import org.jbpm.bpmn2.timer.IntermediateTimerEventMIProcess; +import org.jbpm.bpmn2.timer.IntermediateTimerParallelGatewayModel; +import org.jbpm.bpmn2.timer.IntermediateTimerParallelGatewayProcess; import org.jbpm.bpmn2.timer.TimerBoundaryEventCycle1Model; import org.jbpm.bpmn2.timer.TimerBoundaryEventCycle1Process; import org.jbpm.bpmn2.timer.TimerBoundaryEventCycle2Model; import org.jbpm.bpmn2.timer.TimerBoundaryEventCycle2Process; +import org.jbpm.bpmn2.timer.TimerBoundaryEventCycleISOModel; +import org.jbpm.bpmn2.timer.TimerBoundaryEventCycleISOProcess; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDateISOModel; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDateISOProcess; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDurationISOModel; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDurationISOProcess; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDurationModel; +import org.jbpm.bpmn2.timer.TimerBoundaryEventDurationProcess; import org.jbpm.bpmn2.timer.TimerBoundaryEventInterruptingModel; import org.jbpm.bpmn2.timer.TimerBoundaryEventInterruptingOnTaskCancelTimerModel; import org.jbpm.bpmn2.timer.TimerBoundaryEventInterruptingOnTaskCancelTimerProcess; @@ -144,10 +99,10 @@ 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; -import org.kie.api.command.ExecutableCommand; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; @@ -159,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; @@ -170,9 +124,9 @@ import org.kie.kogito.process.impl.Sig; import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler; -import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.IterableAssert.assertThatIterable; import static org.jbpm.workflow.instance.node.TimerNodeInstance.TIMER_TRIGGERED_EVENT; public class IntermediateEventTest extends JbpmBpmn2TestCase { @@ -266,33 +220,31 @@ public void testSignalBoundaryEvent() { } @Test - public void testSignalBoundaryNonEffectiveEvent() throws Exception { + public void testSignalBoundaryNonEffectiveEvent() { final String signal = "signalTest"; final AtomicBoolean eventAfterNodeLeftTriggered = new AtomicBoolean(false); - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-BoundaryEventWithNonEffectiveSignal.bpmn2"); - + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - + ProcessTestHelper.registerHandler(app, "Human Task", handler); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { - // BoundaryEventNodeInstance if (signal.equals(event.getNodeInstance().getNodeName())) { eventAfterNodeLeftTriggered.set(true); } } }); - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryEventWithNonEffectiveSignal"); - - // outer human work - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), emptyMap()); - kruntime.signalEvent(signal, signal); - - assertProcessInstanceFinished(processInstance, kruntime); + org.kie.kogito.process.Process processDefinition = + BoundaryEventWithNonEffectiveSignalProcess.newProcess(app); + ProcessInstance processInstance = + processDefinition.createInstance(processDefinition.createModel()); + processInstance.start(); + KogitoWorkItem workItem = handler.getWorkItem(); + assertThat(workItem).isNotNull(); + processInstance.completeWorkItem(workItem.getStringId(), null); + processInstance.send(Sig.of(signal, signal)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(eventAfterNodeLeftTriggered).isTrue(); } @@ -589,217 +541,259 @@ 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); + 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()); - receiveTaskHandler.getWorkItemId().forEach(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"); - 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"))); + 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()); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + 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"); - receiveTaskHandler.getWorkItemId().forEach(id -> kruntime.getKogitoWorkItemManager().completeWorkItem(id, Map.of("Message", "YesValue"))); + } + @Test + public void testEventBasedSplitWithSubprocess() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process processDefinition = + ExclusiveEventBasedGatewayInSubprocessProcess.newProcess(app); + ExclusiveEventBasedGatewayInSubprocessModel model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = + processDefinition.createInstance(model); + // Stop + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("StopSignal", "")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + // Continue and Stop + instance = processDefinition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("ContinueSignal", "")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("StopSignal", "")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test - public void testEventBasedSplitWithSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-ExclusiveEventBasedGatewayInSubprocess.bpmn2"); + public void testEventSubprocessSignal() { + String[] nodes = { "start", "User Task 1", "end", "Sub Process 1", "start-sub", "sub-script", "end-sub" }; + Application app = ProcessTestHelper.newApplication(); - // Stop - KogitoProcessInstance processInstance = kruntime.startProcess("ExclusiveEventBasedGatewayInSubprocess"); - assertProcessInstanceActive(processInstance); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + List executedNodes = new ArrayList<>(); - kruntime.signalEvent("StopSignal", "", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); + KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - // Continue and Stop - processInstance = kruntime.startProcess("ExclusiveEventBasedGatewayInSubprocess"); - assertProcessInstanceActive(processInstance); + @Override + public void afterNodeLeft(ProcessNodeLeftEvent event) { + if (event.getNodeInstance().getNodeName().equals("sub-script")) { + executedNodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); + } + } + }; - kruntime.signalEvent("ContinueSignal", "", processInstance.getStringId()); + EventTrackerProcessListener eventTrackerProcessListener = new EventTrackerProcessListener(); - assertProcessInstanceActive(processInstance); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerProcessEventListener(app, eventTrackerProcessListener); - kruntime.signalEvent("StopSignal", "", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - } + org.kie.kogito.process.Process processDefinition = EventSubprocessSignalProcess.newProcess(app); + EventSubprocessSignalModel model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - @Test - public void testEventSubprocessSignal() throws Exception { - String[] nodes = { "start", "User Task 1", "end", "Sub Process 1", "start-sub", "sub-script", "end-sub" }; - runTestEventSubprocessSignal("org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessSignal.bpmn2", - "EventSubprocessSignal", nodes); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + Set> eventDescriptions = instance.events(); + assertThat(eventDescriptions).hasSize(2) // Adjusted to expect two events + .extracting(EventDescription::getEvent) + .contains("MySignal", "workItemCompleted"); + assertThat(eventDescriptions).extracting(EventDescription::getEventType) + .contains("signal", "workItem"); + assertThat(eventDescriptions).extracting(EventDescription::getProcessInstanceId) + .contains(instance.id()); + + for (int i = 0; i < 4; i++) { + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + } + + KogitoWorkItem workItem = workItemHandler.getWorkItem(); + assertThat(workItem).isNotNull(); + instance.completeWorkItem(workItem.getStringId(), null); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThatIterable(eventTrackerProcessListener.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); + assertThat(executedNodes).hasSize(4); } @Test - public void testEventSubprocessSignalNested() throws Exception { - String[] nodes = { "Start", "Sub Process", "Sub Start", "Sub Sub Process", "Sub Sub Start", "Sub Sub User Task", - "Sub Sub Sub Process", "start-sub", "sub-script", "end-sub", "Sub Sub End", "Sub End", "End" }; - runTestEventSubprocessSignal("org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessSignalNested.bpmn2", - "EventSubprocessSignalNested", nodes); - } + public void testEventSubprocessSignalNested() { + String[] nodes = { "Start", "Sub Process", "Sub Start", "Sub Sub Process", "Sub Sub Start", "Sub Sub User Task", "Sub Sub Sub Process", "start-sub", "sub-script", "end-sub", "Sub Sub End", + "Sub End", "End" }; + Application app = ProcessTestHelper.newApplication(); - public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception { - runTestEventSubprocessSignal(processFile, processFile, completedNodes); - } + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + List executedNodes = new ArrayList<>(); - public void runTestEventSubprocessSignal(String processFile, String processId, String[] completedNodes) - throws Exception { - kruntime = createKogitoProcessRuntime(processFile); - final List executednodes = new ArrayList<>(); KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { if (event.getNodeInstance().getNodeName().equals("sub-script")) { - executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); + executedNodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); } } - }; - kruntime.getProcessEventManager().addEventListener(listener); - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess(processId); - assertProcessInstanceActive(processInstance); - kruntime.getProcessEventManager().addEventListener(listener); + EventTrackerProcessListener eventTrackerProcessListener = new EventTrackerProcessListener(); - Set> eventDescriptions = processInstance.getEventDescriptions(); - assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal", "workItemCompleted"); - assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem"); - assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId()); - kruntime.signalEvent("MySignal", null, processInstance.getStringId()); - assertProcessInstanceActive(processInstance); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerProcessEventListener(app, eventTrackerProcessListener); - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); + org.kie.kogito.process.Process processDefinition = EventSubprocessSignalNestedProcess.newProcess(app); + EventSubprocessSignalNestedModel 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); + + Set> eventDescriptions = instance.events(); + assertThat(eventDescriptions).hasSize(2) // Adjusted to expect two events + .extracting(EventDescription::getEvent) + .contains("MySignal", "workItemCompleted"); + assertThat(eventDescriptions).extracting(EventDescription::getEventType) + .contains("signal", "workItem"); + assertThat(eventDescriptions).extracting(EventDescription::getProcessInstanceId) + .contains(instance.id()); + + for (int i = 0; i < 4; i++) { + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + } - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); + instance.completeWorkItem(workItem.getStringId(), null); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), completedNodes); - assertThat(executednodes).hasSize(4); - + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThatIterable(eventTrackerProcessListener.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); + assertThat(executedNodes).hasSize(4); } @Test - public void testEventSubprocessSignalWithStateNode() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessSignalWithStateNode.bpmn2"); - final List executednodes = new ArrayList<>(); + public void testEventSubprocessSignalWithStateNode() { + String[] nodes = { "start", "User Task 1", "end", "Sub Process 1", "start-sub", "User Task 2", "end-sub" }; + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + List executedNodes = new ArrayList<>(); KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { if (event.getNodeInstance().getNodeName().equals("User Task 2")) { - executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); + executedNodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); } } - }; + EventTrackerProcessListener eventTrackerProcessListener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerProcessEventListener(app, eventTrackerProcessListener); - kruntime.getProcessEventManager().addEventListener(listener); - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("EventSubprocessSignalWithStateNode"); - assertProcessInstanceActive(processInstance); - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); + org.kie.kogito.process.Process processDefinition = EventSubprocessSignalWithStateNodeProcess.newProcess(app); + EventSubprocessSignalWithStateNodeModel 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); KogitoWorkItem workItemTopProcess = workItemHandler.getWorkItem(); + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - kruntime.signalEvent("MySignal", null, processInstance.getStringId()); - assertProcessInstanceActive(processInstance); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); + instance.completeWorkItem(workItem.getStringId(), null); + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); + instance.completeWorkItem(workItem.getStringId(), null); + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); + instance.completeWorkItem(workItem.getStringId(), null); + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - kruntime.signalEvent("MySignal", null); - assertProcessInstanceActive(processInstance); workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); + instance.completeWorkItem(workItem.getStringId(), null); assertThat(workItemTopProcess).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItemTopProcess.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", - "User Task 2", "end-sub"); - assertThat(executednodes).hasSize(4); + instance.completeWorkItem(workItemTopProcess.getStringId(), null); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThatIterable(eventTrackerProcessListener.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); + assertThat(executedNodes).hasSize(4); } @Test - public void testEventSubprocessSignalInterrupting() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessSignalInterrupting.bpmn2"); - final List executednodes = new ArrayList<>(); + public void testEventSubprocessSignalInterrupting() { + String[] nodes = { "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub" }; + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + List executedNodes = new ArrayList<>(); KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { if (event.getNodeInstance().getNodeName().equals("Script Task 1")) { - executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); + executedNodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); } } - }; - kruntime.getProcessEventManager().addEventListener(listener); + EventTrackerProcessListener tracker = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerProcessEventListener(app, tracker); - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("EventSubprocessSignalInterrupting"); - assertProcessInstanceActive(processInstance); - kruntime.getProcessEventManager().addEventListener(listener); + org.kie.kogito.process.Process processDefinition = EventSubprocessSignalInterruptingProcess.newProcess(app); + EventSubprocessSignalInterruptingModel model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); - kruntime.signalEvent("MySignal", null, processInstance.getStringId()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "Sub Process 1", "start-sub", - "Script Task 1", "end-sub"); - assertThat(executednodes).hasSize(1); + instance.send(Sig.of("MySignal")); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); + assertThat(executedNodes).hasSize(1); + assertThatIterable(tracker.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); } @Test @@ -982,37 +976,32 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) { } @Test - public void testEventSubprocessMessageWithLocalVars() throws Exception { + public void testEventSubprocessMessageWithLocalVars() { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1); - - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-EventSubProcessWithLocalVariables.bpmn2"); - final Set variablevalues = new HashSet(); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + final Set variableValues = new HashSet<>(); KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { @SuppressWarnings("unchecked") Map variable = (Map) event.getNodeInstance().getVariable("richiesta"); if (variable != null) { - variablevalues.addAll(variable.keySet()); + variableValues.addAll(variable.keySet()); } } - }; - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getProcessEventManager().addEventListener(countDownListener); - KogitoProcessInstance processInstance = kruntime.startProcess("EventSubProcessWithLocalVariables"); - assertProcessInstanceActive(processInstance); - + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process process = EventSubProcessWithLocalVariablesProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); Map data = new HashMap<>(); - kruntime.signalEvent("Message-MAIL", data, processInstance.getStringId()); + processInstance.send(Sig.of("Message-MAIL", data)); countDownListener.waitTillCompleted(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance).isNull(); - assertThat(variablevalues).hasSize(2).contains("SCRIPT1", "SCRIPT2"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); + assertThat(variableValues).hasSize(2).contains("SCRIPT1", "SCRIPT2"); } @Test @@ -1043,102 +1032,131 @@ public void produce(KogitoProcessInstance pi, String eventData) { } @Test - public void testMessageBoundaryEventOnTask() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-BoundaryMessageEventOnTask.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler()); + public void testMessageBoundaryEventOnTask() { + Application app = ProcessTestHelper.newApplication(); + List triggeredNodes = new ArrayList<>(); - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryMessageEventOnTask"); - kruntime.signalEvent("Message-HelloMessage", "message data"); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "User Task", "Boundary event", - "Condition met", "End2"); + KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { + @Override + public void afterNodeLeft(ProcessNodeLeftEvent event) { + triggeredNodes.add(event.getNodeInstance().getNodeName()); + } + }; + ProcessTestHelper.registerProcessEventListener(app, listener); - } + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); - @Test - public void testMessageBoundaryEventOnTaskComplete() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-BoundaryMessageEventOnTask.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); + org.kie.kogito.process.Process process = BoundaryMessageEventOnTaskProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryMessageEventOnTask"); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - kruntime.signalEvent("Message-HelloMessage", "message data"); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "User Task", "User Task2", "End1"); + processInstance.send(Sig.of("Message-HelloMessage", "message data")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(triggeredNodes).containsExactlyInAnyOrder("StartProcess", "User Task", "Boundary event", "Condition met", "End2"); } @Test - public void testTimerBoundaryEventDuration() throws Exception { - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-TimerBoundaryEventDuration.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(countDownListener); - KogitoProcessInstance processInstance = kruntime.startProcess("TimerBoundaryEventDuration"); - assertProcessInstanceActive(processInstance); + public void testMessageBoundaryEventOnTaskComplete() { + String[] nodes = { "StartProcess", "User Task", "User Task2", "End1" }; + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); - Set> eventDescriptions = processInstance.getEventDescriptions(); - assertThat(eventDescriptions).hasSize(2).extracting("event").contains("workItemCompleted", - TIMER_TRIGGERED_EVENT); - assertThat(eventDescriptions).extracting("eventType").contains("workItem", "timer"); - assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId()); - assertThat(eventDescriptions).filteredOn("eventType", "timer").hasSize(1).extracting("properties", Map.class) - .anyMatch(m -> m.containsKey("TimerID") && m.containsKey("Period")); + org.kie.kogito.process.Process process = BoundaryMessageEventOnTaskProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); - countDownListener.waitTillCompleted(); - - assertProcessInstanceFinished(processInstance, kruntime); + processInstance.completeWorkItem(workItemHandler.getWorkItem().getStringId(), null); + processInstance.send(Sig.of("Message-HelloMessage", "message data")); + processInstance.completeWorkItem(workItemHandler.getWorkItem().getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThatIterable(listener.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); } @Test - public void testTimerBoundaryEventDurationISO() throws Exception { - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-TimerBoundaryEventDurationISO.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(countDownListener); - KogitoProcessInstance processInstance = kruntime.startProcess("TimerBoundaryEventDurationISO"); - assertProcessInstanceActive(processInstance); + public void testTimerBoundaryEventDuration() { + Application app = ProcessTestHelper.newApplication(); + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); + org.kie.kogito.process.Process process = TimerBoundaryEventDurationProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + Set> eventDescriptions = processInstance.events(); + assertThat(eventDescriptions).hasSize(2) + .extracting("event") + .contains("workItemCompleted", TIMER_TRIGGERED_EVENT); + assertThat(eventDescriptions).extracting("eventType") + .contains("workItem", "timer"); + assertThat(eventDescriptions).extracting("processInstanceId") + .contains(processInstance.id()); + assertThat(eventDescriptions).filteredOn("eventType", "timer") + .hasSize(1) + .extracting("properties", Map.class) + .anyMatch(m -> m.containsKey("TimerID") && m.containsKey("Period")); countDownListener.waitTillCompleted(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + } - assertProcessInstanceFinished(processInstance, kruntime); + @Test + public void testTimerBoundaryEventDurationISO() { + Application app = ProcessTestHelper.newApplication(); + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); + + org.kie.kogito.process.Process definition = TimerBoundaryEventDurationISOProcess.newProcess(app); + TimerBoundaryEventDurationISOModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + countDownListener.waitTillCompleted(); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test - public void testTimerBoundaryEventDateISO() throws Exception { - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); + public void testTimerBoundaryEventDateISO() { + Application app = ProcessTestHelper.newApplication(); + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); + + org.kie.kogito.process.Process definition = TimerBoundaryEventDateISOProcess.newProcess(app); + TimerBoundaryEventDateISOModel model = definition.createModel(); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-TimerBoundaryEventDateISO.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler()); - HashMap params = new HashMap<>(); OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2); - params.put("date", plusTwoSeconds.toString()); - KogitoProcessInstance processInstance = kruntime.startProcess("TimerBoundaryEventDateISO", params); - assertProcessInstanceActive(processInstance); - countDownListener.waitTillCompleted(); + model.setDate(plusTwoSeconds.toString()); - assertProcessInstanceFinished(processInstance, kruntime); + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + countDownListener.waitTillCompleted(); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test - public void testTimerBoundaryEventCycle1() { - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); + public void testTimerBoundaryEventCycle1() throws Exception { Application app = ProcessTestHelper.newApplication(); - ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); + NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 3); ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = TimerBoundaryEventCycle1Process.newProcess(app); - TimerBoundaryEventCycle1Model model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); + org.kie.kogito.process.Process definition = TimerBoundaryEventCycle1Process.newProcess(app); + TimerBoundaryEventCycle1Model model = definition.createModel(); + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); countDownListener.waitTillCompleted(); - assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test @@ -1162,17 +1180,24 @@ public void testTimerBoundaryEventCycle2() { @Test @RequirePersistence(false) - public void testTimerBoundaryEventCycleISO() throws Exception { - NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener( - "TimerEvent", 2); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-TimerBoundaryEventCycleISO.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("TimerBoundaryEventCycleISO"); - assertProcessInstanceActive(processInstance); + public void testTimerBoundaryEventCycleISO() { + Application app = ProcessTestHelper.newApplication(); + NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "MyTask", new DoNothingWorkItemHandler()); + + org.kie.kogito.process.Process definition = TimerBoundaryEventCycleISOProcess.newProcess(app); + TimerBoundaryEventCycleISOModel model = definition.createModel(); + + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + countDownListener.waitTillCompleted(); - assertProcessInstanceActive(processInstance); - kruntime.abortProcessInstance(processInstance.getStringId()); + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + processInstance.abort(); } @Test @@ -1216,33 +1241,44 @@ public void testTimerBoundaryEventInterruptingOnTaskCancelTimer() { Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); ProcessTestHelper.registerHandler(app, "Human Task", handler); - org.kie.kogito.process.Process processDefinition = TimerBoundaryEventInterruptingOnTaskCancelTimerProcess.newProcess(app); - TimerBoundaryEventInterruptingOnTaskCancelTimerModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); + org.kie.kogito.process.Process definition = + TimerBoundaryEventInterruptingOnTaskCancelTimerProcess.newProcess(app); + TimerBoundaryEventInterruptingOnTaskCancelTimerModel model = definition.createModel(); + ProcessInstance processInstance = definition.createInstance(model); + + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + KogitoWorkItem workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull(); - instance.completeWorkItem(workItem.getStringId(), null); + if (workItem != null) { + processInstance.completeWorkItem(workItem.getStringId(), null); + } workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull(); - instance.completeWorkItem(workItem.getStringId(), null); - - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + if (workItem != null) { + processInstance.completeWorkItem(workItem.getStringId(), null); + } + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventSignal() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignal"); - assertProcessInstanceActive(processInstance); - - // now signal process instance - kruntime.signalEvent("MyMessage", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "UserTask", "EndProcess", "event"); - + public void testIntermediateCatchEventSignal() { + Application app = ProcessTestHelper.newApplication(); + List triggeredNodes = new ArrayList<>(); + KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { + @Override + public void afterNodeLeft(ProcessNodeLeftEvent event) { + triggeredNodes.add(event.getNodeInstance().getNodeName()); + } + }; + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process process = IntermediateCatchEventSignalProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("MyMessage", "SomeValue")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(triggeredNodes).containsExactlyInAnyOrder("StartProcess", "UserTask", "Event", "event", "EndProcess"); } @Test @@ -1259,16 +1295,16 @@ public void testIntermediateCatchEventMessage() { } @Test - public void testIntermediateCatchEventMessageWithRef() { + public void testIntermediateCatchEventMessageWithRef() throws Exception { Application app = ProcessTestHelper.newApplication(); ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventMessageWithRefProcess.newProcess(app); - IntermediateCatchEventMessageWithRefModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - instance.send(Sig.of("Message-HelloMessage", "SomeValue")); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + org.kie.kogito.process.Process process = IntermediateCatchEventMessageWithRefProcess.newProcess(app); + ProcessInstance processInstance = process.createInstance(process.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + // now signal process instance + processInstance.send(Sig.of("Message-HelloMessage", "SomeValue")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -1290,98 +1326,113 @@ public void testIntermediateCatchEventTimerDuration() { } @Test - public void testIntermediateCatchEventTimerDateISO() { + public void testIntermediateCatchEventTimerDateISO() throws Exception { Application app = ProcessTestHelper.newApplication(); - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); ProcessTestHelper.registerProcessEventListener(app, countDownListener); ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventTimerDateISOProcess.newProcess(app); - IntermediateCatchEventTimerDateISOModel model = processDefinition.createModel(); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerDateISOProcess.newProcess(app); + IntermediateCatchEventTimerDateISOModel model = definition.createModel(); + OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2); model.setDate(plusTwoSeconds.toString()); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - boolean completed = countDownListener.waitTillCompleted(3000); - assertThat(completed).isTrue(); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + + // Wait for the timer to trigger + countDownListener.waitTillCompleted(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventTimerDurationISO() { + public void testIntermediateCatchEventTimerDurationISO() throws Exception { Application app = ProcessTestHelper.newApplication(); + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); + + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerDurationISOProcess.newProcess(app); + IntermediateCatchEventTimerDurationISOModel model = definition.createModel(); + + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); - ProcessTestHelper.registerProcessEventListener(app, countDownListener); - ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); + // Wait for the timer to trigger + countDownListener.waitTillCompleted(); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventTimerDurationISOProcess.newProcess(app); - IntermediateCatchEventTimerDurationISOModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - boolean completed = countDownListener.waitTillCompleted(2000); - assertThat(completed).isTrue(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventTimerCycle1() { + public void testIntermediateCatchEventTimerCycle1() throws Exception { Application app = ProcessTestHelper.newApplication(); - ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(); // Expecting 1 completion event + ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); ProcessTestHelper.registerProcessEventListener(app, countDownListener); ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventTimerCycle1Process.newProcess(app); - IntermediateCatchEventTimerCycle1Model model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - boolean completed = countDownListener.waitTillCompleted(2000); // Wait for up to 2 seconds - assertThat(completed).isTrue(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycle1Process.newProcess(app); + IntermediateCatchEventTimerCycle1Model model = definition.createModel(); + + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + + // Wait for the timer to trigger + countDownListener.waitTillCompleted(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventTimerCycleISO() { + public void testIntermediateCatchEventTimerCycleISO() throws Exception { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 5); ProcessTestHelper.registerProcessEventListener(app, countDownListener); ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventTimerCycleISOProcess.newProcess(app); - IntermediateCatchEventTimerCycleISOModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - boolean completed = countDownListener.waitTillCompleted(); - assertThat(completed).isTrue(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - instance.abort(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ABORTED); + + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycleISOProcess.newProcess(app); + IntermediateCatchEventTimerCycleISOModel model = definition.createModel(); + + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + countDownListener.waitTillCompleted(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + processInstance.abort(); } @Test - public void testIntermediateCatchEventTimerCycle2() { + public void testIntermediateCatchEventTimerCycle2() throws Exception { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3); ProcessTestHelper.registerProcessEventListener(app, countDownListener); ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); - org.kie.kogito.process.Process processDefinition = IntermediateCatchEventTimerCycle2Process.newProcess(app); - IntermediateCatchEventTimerCycle2Model model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycle2Process.newProcess(app); + IntermediateCatchEventTimerCycle2Model model = definition.createModel(); - // now wait for 1 second for timer to trigger - boolean completed = countDownListener.waitTillCompleted(); // Wait for up to 10 seconds - assertThat(completed).isTrue(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); - instance.abort(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ABORTED); + org.kie.kogito.process.ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + countDownListener.waitTillCompleted(); + + assertThat(processInstance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + processInstance.abort(); } @Test @@ -1390,13 +1441,11 @@ public void testIntermediateCatchEventCondition() throws Exception { "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventCondition.bpmn2"); KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventCondition"); assertProcessInstanceActive(processInstance); - // now activate condition Person person = new Person(); person.setName("Jack"); kruntime.getKieSession().insert(person); assertProcessInstanceFinished(processInstance, kruntime); - } @Test @@ -1443,95 +1492,91 @@ 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); } @Test @RequirePersistence - public void testIntermediateCatchEventTimerCycleWithErrorWithPersistence() throws Exception { + public void testIntermediateCatchEventTimerCycleWithErrorWithPersistence() { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(countDownListener); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventTimerCycleWithError"); - assertProcessInstanceActive(processInstance); + org.kie.kogito.process.Process definition = + IntermediateCatchEventTimerCycleWithErrorProcess.newProcess(app); - final String piId = processInstance.getStringId(); - kruntime.getKieSession().execute((ExecutableCommand) context -> { - KogitoWorkflowProcessInstance processInstance1 = (KogitoWorkflowProcessInstance) kruntime - .getProcessInstance(piId); - processInstance1.setVariable("x", 0); - return null; - }); + IntermediateCatchEventTimerCycleWithErrorModel model = definition.createModel(); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + model.setX(0); + processInstance.updateVariables(model); - // now wait for 1 second for timer to trigger + // Wait for the timer to trigger countDownListener.waitTillCompleted(); - assertProcessInstanceActive(processInstance); - Integer xValue = kruntime.getKieSession().execute((ExecutableCommand) context -> { - KogitoWorkflowProcessInstance processInstance2 = (KogitoWorkflowProcessInstance) kruntime - .getProcessInstance(piId); - return (Integer) processInstance2.getVariable("x"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - }); - assertThat(xValue).isEqualTo(2); - kruntime.abortProcessInstance(processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); + // Retrieve the updated model variables + model = processInstance.variables(); + Integer xValue = model.getX(); + assertThat(xValue).isGreaterThanOrEqualTo(1); + + processInstance.abort(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); } @Test public void testNoneIntermediateThrow() { Application app = ProcessTestHelper.newApplication(); - org.kie.kogito.process.Process processDefinition = IntermediateThrowEventNoneProcess.newProcess(app); - IntermediateThrowEventNoneModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + org.kie.kogito.process.Process process = IntermediateThrowEventNoneProcess.newProcess(app); + IntermediateThrowEventNoneModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test public void testLinkIntermediateEvent() { Application app = ProcessTestHelper.newApplication(); - org.kie.kogito.process.Process processDefinition = IntermediateLinkEventProcess.newProcess(app); - IntermediateLinkEventModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + org.kie.kogito.process.Process process = IntermediateLinkEventProcess.newProcess(app); + IntermediateLinkEventModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testLinkEventCompositeProcess() { + public void testLinkEventCompositeProcess() throws Exception { Application app = ProcessTestHelper.newApplication(); - - org.kie.kogito.process.Process processDefinition = LinkEventCompositeProcessProcess.newProcess(app); - LinkEventCompositeProcessModel model = processDefinition.createModel(); - org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); - instance.start(); - assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + org.kie.kogito.process.Process process = LinkEventCompositeProcessProcess.newProcess(app); + LinkEventCompositeProcessModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -1539,15 +1584,12 @@ public void testConditionalBoundaryEventOnTask() throws Exception { kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-BoundaryConditionalEventOnTask.bpmn2"); kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler()); KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryConditionalEventOnTask"); - Person person = new Person(); person.setName("john"); kruntime.getKieSession().insert(person); - assertProcessInstanceFinished(processInstance, kruntime); assertNodeTriggered(processInstance.getStringId(), "StartProcess", "User Task", "Boundary event", "Condition met", "End2"); - } @Test @@ -1604,20 +1646,20 @@ public void testConditionalBoundaryEventInterrupting() throws Exception { } @Test - public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-SignalBoundaryOnSubProcess.bpmn"); - - KogitoProcessInstance processInstance = kruntime.startProcess("SignalBoundaryOnSubProcess"); - assertProcessInstanceActive(processInstance); - - kruntime.signalEvent("continue", null, processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - - processInstance = kruntime.startProcess("SignalBoundaryOnSubProcess"); - assertProcessInstanceActive(processInstance); + public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = SignalBoundaryOnSubProcessProcess.newProcess(app); - kruntime.signalEvent("forward", null); - assertProcessInstanceFinished(processInstance, kruntime); + ProcessInstance processInstance = definition.createInstance(definition.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("continue", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + processInstance = definition.createInstance(definition.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("forward", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -1663,118 +1705,99 @@ public void testIntermediateCatchEventNoIncommingConnection() throws Exception { } @Test - public void testSignalBoundaryEventOnMultiInstanceSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-MultiInstanceSubprocessWithBoundarySignal.bpmn2"); - + public void testSignalBoundaryEventOnMultiInstanceSubprocess() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - Map params = new HashMap<>(); - List approvers = new ArrayList<>(); - approvers.add("john"); - approvers.add("john"); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - params.put("approvers", approvers); + org.kie.kogito.process.Process definition = MultiInstanceSubprocessWithBoundarySignalProcess.newProcess(app); + MultiInstanceSubprocessWithBoundarySignalModel model = definition.createModel(); + model.setApprovers(Arrays.asList("john", "john")); + ProcessInstance processInstance = definition.createInstance(model); - KogitoProcessInstance processInstance = kruntime.startProcess("MultiInstanceSubprocessWithBoundarySignal", - params); - assertProcessInstanceActive(processInstance); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); - kruntime.signalEvent("Outside", null, processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - + processInstance.send(Sig.of("Outside", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testSignalBoundaryEventNoInteruptOnMultiInstanceSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-MultiInstanceSubprocessWithBoundarySignalNoInterupting.bpmn2"); - + public void testSignalBoundaryEventNoInteruptOnMultiInstanceSubprocess() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - Map params = new HashMap<>(); - List approvers = new ArrayList<>(); - approvers.add("john"); - approvers.add("john"); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - params.put("approvers", approvers); + org.kie.kogito.process.Process definition = + MultiInstanceSubprocessWithBoundarySignalNoInteruptingProcess.newProcess(app); + MultiInstanceSubprocessWithBoundarySignalNoInteruptingModel model = definition.createModel(); + model.setApprovers(Arrays.asList("john", "john")); - KogitoProcessInstance processInstance = kruntime - .startProcess("MultiInstanceSubprocessWithBoundarySignalNoInterupting", params); - assertProcessInstanceActive(processInstance); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); - kruntime.signalEvent("Outside", null, processInstance.getStringId()); - - assertProcessInstanceActive(processInstance.getStringId(), kruntime); + processInstance.send(Sig.of("Outside", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); for (KogitoWorkItem wi : workItems) { - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), null); + processInstance.completeWorkItem(wi.getStringId(), null); } - assertProcessInstanceFinished(processInstance, kruntime); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testErrorBoundaryEventOnMultiInstanceSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-MultiInstanceSubprocessWithBoundaryError.bpmn2"); - + public void testErrorBoundaryEventOnMultiInstanceSubprocess() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - Map params = new HashMap<>(); - List approvers = new ArrayList<>(); - approvers.add("john"); - approvers.add("john"); - - params.put("approvers", approvers); - - KogitoProcessInstance processInstance = kruntime.startProcess("MultiInstanceSubprocessWithBoundaryError", - params); - assertProcessInstanceActive(processInstance); - Set> eventDescriptions = processInstance.getEventDescriptions(); - assertThat(eventDescriptions).hasSize(3).extracting("event").contains("workItemCompleted", "Inside", - "Error-_D83CFC28-3322-4ABC-A12D-83476B08C7E8-MyError"); - assertThat(eventDescriptions).extracting("eventType").contains("workItem", "signal"); - assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId()); - assertThat(eventDescriptions).filteredOn("eventType", "signal").hasSize(2).extracting("properties", Map.class) + ProcessTestHelper.registerHandler(app, "Human Task", handler); + org.kie.kogito.process.Process definition = + MultiInstanceSubprocessWithBoundaryErrorProcess.newProcess(app); + MultiInstanceSubprocessWithBoundaryErrorModel model = definition.createModel(); + model.setApprovers(Arrays.asList("john", "john")); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + Set> eventDescriptions = processInstance.events(); + assertThat(eventDescriptions).hasSize(3) + .extracting("event") + .contains("workItemCompleted", "Inside", "Error-_D83CFC28-3322-4ABC-A12D-83476B08C7E8-MyError"); + assertThat(eventDescriptions).extracting("eventType") + .contains("workItem", "signal"); + assertThat(eventDescriptions).extracting("processInstanceId") + .contains(processInstance.id()); + assertThat(eventDescriptions).filteredOn("eventType", "signal").hasSize(2) + .extracting("properties", Map.class) .anyMatch(m -> m.containsKey("AttachedToID") && m.containsKey("AttachedToName")); - List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); - - kruntime.signalEvent("Inside", null, processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - + processInstance.send(Sig.of("Inside", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventSignalAndBoundarySignalEvent() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-BoundaryEventWithSignals.bpmn2"); + public void testIntermediateCatchEventSignalAndBoundarySignalEvent() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryEventWithSignals"); - assertProcessInstanceActive(processInstance); - - // now signal process instance - kruntime.signalEvent("moveon", "", processInstance.getStringId()); - assertProcessInstanceActive(processInstance); - + ProcessTestHelper.registerHandler(app, "Human Task", handler); + org.kie.kogito.process.Process process = BoundaryEventWithSignalsProcess.newProcess(app); + BoundaryEventWithSignalsModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("moveon", "")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem wi = handler.getWorkItem(); assertThat(wi).isNotNull(); - - // signal boundary event on user task - kruntime.signalEvent("moveon", "", processInstance.getStringId()); - - assertProcessInstanceFinished(processInstance, kruntime); + processInstance.send(Sig.of("moveon", "")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -1987,38 +2010,40 @@ public void testEventSubprocessSignalWithTransformation() throws Exception { } @Test - public void testMultipleMessageSignalSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-MultipleMessageSignalSubprocess.bpmn2"); - KogitoProcessInstance processInstance = kruntime.startProcess("MultipleMessageSignalSubprocess"); - logger.debug("Parent Process ID: " + processInstance.getStringId()); - - kruntime.signalEvent("Message-Message 1", "Test", processInstance.getStringId()); - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - - kruntime.signalEvent("Message-Message 1", "Test", processInstance.getStringId()); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + public void testMultipleMessageSignalSubprocess() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process process = MultipleMessageSignalSubprocessProcess.newProcess(app); + MultipleMessageSignalSubprocessModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + logger.debug("Parent Process ID: " + processInstance.id()); + processInstance.send(Sig.of("Message-Message 1", "Test")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("Message-Message 1", "Test")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventSignalWithRef() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithRef.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignalWithRef"); - assertProcessInstanceActive(processInstance); - - // now signal process instance - kruntime.signalEvent("Signal1", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "UserTask", "EndProcess", "event"); - + public void testIntermediateCatchEventSignalWithRef() { + String[] nodes = { "StartProcess", "UserTask", "EndProcess", "event" }; + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + EventTrackerProcessListener tracker = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, tracker); + org.kie.kogito.process.Process process = IntermediateCatchEventSignalWithRefProcess.newProcess(app); + IntermediateCatchEventSignalWithRefModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("Signal1", "SomeValue")); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThatIterable(tracker.tracked()).extracting(a -> a.getNodeInstance().getNodeName()).contains(nodes); } @Test public void testMultiInstanceLoopBoundaryTimer() throws Exception { Application app = ProcessTestHelper.newApplication(); - NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3); + NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2); ProcessTestHelper.registerProcessEventListener(app, countDownListener); TestUserTaskWorkItemHandler handler = new TestUserTaskWorkItemHandler(); ProcessTestHelper.registerHandler(app, "Human Task", handler); @@ -2196,208 +2221,229 @@ public void testMultiInstanceLoopCharacteristicsTaskWithOutputCmpCondSequential( } @Test - public void testIntermediateTimerParallelGateway() throws Exception { - NodeLeftCountDownProcessEventListener countDownListener1 = new NodeLeftCountDownProcessEventListener("Timer1", - 1); - NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Timer2", - 1); - NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Timer3", - 1); + public void testIntermediateTimerParallelGateway() { + Application app = ProcessTestHelper.newApplication(); + NodeLeftCountDownProcessEventListener countDownListener1 = new NodeLeftCountDownProcessEventListener("Timer1", 1); + NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Timer2", 1); + NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Timer3", 1); ProcessCompletedCountDownProcessEventListener countDownProcessEventListener = new ProcessCompletedCountDownProcessEventListener(); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-IntermediateTimerParallelGateway.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener1); - kruntime.getProcessEventManager().addEventListener(countDownListener2); - kruntime.getProcessEventManager().addEventListener(countDownListener3); - kruntime.getProcessEventManager().addEventListener(countDownProcessEventListener); + + ProcessTestHelper.registerProcessEventListener(app, countDownListener1); + ProcessTestHelper.registerProcessEventListener(app, countDownListener2); + ProcessTestHelper.registerProcessEventListener(app, countDownListener3); + ProcessTestHelper.registerProcessEventListener(app, countDownProcessEventListener); + TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateTimerParallelGateway"); - assertProcessInstanceActive(processInstance); + org.kie.kogito.process.Process process = IntermediateTimerParallelGatewayProcess.newProcess(app); + IntermediateTimerParallelGatewayModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); countDownListener1.waitTillCompleted(); countDownListener2.waitTillCompleted(); countDownListener3.waitTillCompleted(); countDownProcessEventListener.waitTillCompleted(); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateTimerEventMI() throws Exception { - NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener( - "After timer", 3); - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/timer/BPMN2-IntermediateTimerEventMI.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener); + public void testIntermediateTimerEventMI() { + Application app = ProcessTestHelper.newApplication(); + NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("After timer", 3); + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateTimerEventMI"); - assertProcessInstanceActive(processInstance); + org.kie.kogito.process.Process process = IntermediateTimerEventMIProcess.newProcess(app); + IntermediateTimerEventMIModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); countDownListener.waitTillCompleted(); - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - kruntime.abortProcessInstance(processInstance.getStringId()); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - assertProcessInstanceAborted(processInstance.getStringId(), kruntime); + processInstance.abort(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); } @Test - public void testThrowIntermediateSignalWithScope() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventScope.bpmn2"); + public void testThrowIntermediateSignalWithScope() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - Map params = new HashMap<>(); + org.kie.kogito.process.Process process = IntermediateThrowEventScopeProcess.newProcess(app); + IntermediateThrowEventScopeModel model1 = process.createModel(); + IntermediateThrowEventScopeModel model2 = process.createModel(); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventScope", params); - KogitoProcessInstance processInstance2 = kruntime.startProcess("IntermediateThrowEventScope", params); + ProcessInstance processInstance1 = process.createInstance(model1); + ProcessInstance processInstance2 = process.createInstance(model2); - assertProcessInstanceActive(processInstance); - assertProcessInstanceActive(processInstance2); + processInstance1.start(); + processInstance2.start(); - assertNodeActive(processInstance.getStringId(), kruntime, "Complete work", "Wait"); - assertNodeActive(processInstance2.getStringId(), kruntime, "Complete work", "Wait"); + assertThat(processInstance1.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List items = handler.getWorkItems(); - - KogitoWorkItem wi = items.get(0); - + KogitoWorkItem wi1 = items.get(0); Map result = new HashMap<>(); result.put("_output", "sending event"); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), result); + processInstance1.completeWorkItem(wi1.getStringId(), result); - assertProcessInstanceCompleted(processInstance); - assertProcessInstanceActive(processInstance2); - assertNodeActive(processInstance2.getStringId(), kruntime, "Complete work", "Wait"); + assertThat(processInstance1.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - wi = items.get(1); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), result); - assertProcessInstanceCompleted(processInstance2); + KogitoWorkItem wi2 = items.get(1); + processInstance2.completeWorkItem(wi2.getStringId(), result); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testThrowEndSignalWithScope() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-EndThrowEventScope.bpmn2"); + public void testThrowEndSignalWithScope() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - Map params = new HashMap<>(); + org.kie.kogito.process.Process process = EndThrowEventScopeProcess.newProcess(app); + EndThrowEventScopeModel model1 = process.createModel(); + EndThrowEventScopeModel model2 = process.createModel(); - KogitoProcessInstance processInstance = kruntime.startProcess("EndThrowEventScope", params); - KogitoProcessInstance processInstance2 = kruntime.startProcess("EndThrowEventScope", params); + ProcessInstance processInstance1 = process.createInstance(model1); + ProcessInstance processInstance2 = process.createInstance(model2); - assertProcessInstanceActive(processInstance); - assertProcessInstanceActive(processInstance2); + processInstance1.start(); + processInstance2.start(); - assertNodeActive(processInstance.getStringId(), kruntime, "Complete work", "Wait"); - assertNodeActive(processInstance2.getStringId(), kruntime, "Complete work", "Wait"); + assertThat(processInstance1.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List items = handler.getWorkItems(); - - KogitoWorkItem wi = items.get(0); - + KogitoWorkItem wi1 = items.get(0); Map result = new HashMap<>(); result.put("_output", "sending event"); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), result); + processInstance1.completeWorkItem(wi1.getStringId(), result); - assertProcessInstanceCompleted(processInstance); - assertProcessInstanceActive(processInstance2); - assertNodeActive(processInstance2.getStringId(), kruntime, "Complete work", "Wait"); + assertThat(processInstance1.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - wi = items.get(1); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), result); - assertProcessInstanceCompleted(processInstance2); + KogitoWorkItem wi2 = items.get(1); + processInstance2.completeWorkItem(wi2.getStringId(), result); + assertThat(processInstance2.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testThrowIntermediateSignalWithExternalScope() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventExternalScope.bpmn2"); + public void testThrowIntermediateSignalWithExternalScope() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); KogitoWorkItemHandler externalHandler = new DefaultKogitoWorkItemHandler() { @Override public Optional activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) { String signal = (String) workItem.getParameter("Signal"); - kruntime.signalEvent(signal, null); + workItem.getProcessInstance().signalEvent(signal, null); return Optional.of(this.workItemLifeCycle.newTransition("complete", workItem.getPhaseStatus(), Collections.emptyMap())); } }; + ProcessTestHelper.registerHandler(app, "External Send Task", externalHandler); + org.kie.kogito.process.Process process = IntermediateThrowEventExternalScopeProcess.newProcess(app); + IntermediateThrowEventExternalScopeModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("External Send Task", externalHandler); - Map params = new HashMap<>(); - - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventExternalScope", params); - - assertProcessInstanceActive(processInstance); - - assertNodeActive(processInstance.getStringId(), kruntime, "Complete work", "Wait"); - + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List items = handler.getWorkItems(); assertThat(items).hasSize(1); KogitoWorkItem wi = items.get(0); - Map result = new HashMap<>(); result.put("_output", "sending event"); + processInstance.completeWorkItem(wi.getStringId(), result); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), result); - - assertProcessInstanceCompleted(processInstance); - + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test - public void testIntermediateCatchEventSignalWithVariable() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithVariable.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); + public void testIntermediateCatchEventSignalWithVariable() { + Application app = ProcessTestHelper.newApplication(); + List triggeredNodes = new ArrayList<>(); + + KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { + @Override + public void afterNodeLeft(ProcessNodeLeftEvent event) { + triggeredNodes.add(event.getNodeInstance().getNodeName()); + } + }; + + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); String signalVar = "myVarSignal"; Map parameters = new HashMap<>(); parameters.put("signalName", signalVar); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignalWithVariable", - parameters); - assertProcessInstanceActive(processInstance); - // now signal process instance - kruntime.signalEvent(signalVar, "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "UserTask", "EndProcess", "event"); + org.kie.kogito.process.Process process = IntermediateCatchEventSignalWithVariableProcess.newProcess(app); + IntermediateCatchEventSignalWithVariableModel model = process.createModel(); + model.fromMap(parameters); + + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + + processInstance.send(Sig.of(signalVar, "SomeValue")); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(triggeredNodes).containsExactlyInAnyOrder("StartProcess", "UserTask", "Event", "event", "EndProcess"); } @Test public void testSignalIntermediateThrowWithVariable() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithVariable.bpmn2", - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithVariable.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - // create catch process instance + Application app = ProcessTestHelper.newApplication(); + List triggeredNodes = new ArrayList<>(); + KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { + @Override + public void afterNodeLeft(ProcessNodeLeftEvent event) { + triggeredNodes.add(event.getNodeInstance().getNodeName()); + } + }; + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); String signalVar = "myVarSignal"; - Map parameters = new HashMap<>(); - parameters.put("signalName", signalVar); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignalWithVariable", - parameters); - assertProcessInstanceActive(processInstance); - - Map params = new HashMap<>(); - params.put("x", "MyValue"); - params.put("signalName", signalVar); - KogitoProcessInstance processInstanceThrow = kruntime.startProcess("IntermediateThrowEventSignalWithVariable", - params); - assertThat(processInstanceThrow.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); - - // catch process instance should now be completed - assertProcessInstanceFinished(processInstance, kruntime); - + Map catchParameters = new HashMap<>(); + catchParameters.put("signalName", signalVar); + org.kie.kogito.process.Process catchProcess = IntermediateCatchEventSignalWithVariableProcess.newProcess(app); + IntermediateCatchEventSignalWithVariableModel catchModel = catchProcess.createModel(); + catchModel.fromMap(catchParameters); + ProcessInstance catchProcessInstance = catchProcess.createInstance(catchModel); + catchProcessInstance.start(); + assertThat(catchProcessInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + Map throwParameters = new HashMap<>(); + throwParameters.put("x", "MyValue"); + throwParameters.put("signalName", signalVar); + org.kie.kogito.process.Process throwProcess = IntermediateThrowEventSignalWithVariableProcess.newProcess(app); + IntermediateThrowEventSignalWithVariableModel throwModel = throwProcess.createModel(); + throwModel.fromMap(throwParameters); + ProcessInstance throwProcessInstance = throwProcess.createInstance(throwModel); + throwProcessInstance.start(); + assertThat(throwProcessInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(catchProcessInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(triggeredNodes).contains("StartProcess", "UserTask", "Event", "event", "EndProcess"); } @Test @@ -2559,20 +2605,22 @@ public void testEventSubprocessWithEmbeddedSignals() throws Exception { } @Test - public void testEventSubprocessWithExpression() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessSignalExpression.bpmn2"); + public void testEventSubprocessWithExpression() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - Map params = new HashMap<>(); - params.put("x", "signalling"); - KogitoProcessInstance processInstance = kruntime.startProcess("EventSubprocessSignalExpression", params); + ProcessTestHelper.registerHandler(app, "Human Task", handler); - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - assertProcessInstanceActive(processInstance); - kruntime.signalEvent("signalling", null, processInstance.getStringId()); + org.kie.kogito.process.Process process = EventSubprocessSignalExpressionProcess.newProcess(app); + EventSubprocessSignalExpressionModel model = process.createModel(); + model.setX("signalling"); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); - assertProcessInstanceFinished(processInstance, kruntime); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + + processInstance.send(Sig.of("signalling")); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); } @Test @@ -2584,63 +2632,57 @@ public void testConditionalProcessFactInsertedBefore() throws Exception { kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); Person person0 = new Person("john"); kruntime.getKieSession().insert(person0); - Map params0 = new HashMap<>(); params0.put("name", "john"); KogitoProcessInstance pi0 = kruntime.startProcess("IntermediateCatchEventSignal", params0); kruntime.getKieSession().insert(pi0); - Person person = new Person("Jack"); kruntime.getKieSession().insert(person); - Map params = new HashMap<>(); params.put("name", "Poul"); KogitoProcessInstance pi = kruntime.startProcess("IntermediateCatchEventConditionPI", params); kruntime.getKieSession().insert(pi); pi = kruntime.getProcessInstance(pi.getStringId()); assertThat(pi).isNotNull(); - Person person2 = new Person("Poul"); kruntime.getKieSession().insert(person2); - pi = kruntime.getProcessInstance(pi.getStringId()); assertThat(pi).isNull(); - } @Test - public void testBoundarySignalEventOnSubprocessWithVariableResolution() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-SubprocessWithSignalEndEventAndSignalBoundaryEvent.bpmn2"); - kruntime.getProcessEventManager().addEventListener(LOGGING_EVENT_LISTENER); + public void testBoundarySignalEventOnSubprocessWithVariableResolution() { + Application app = ProcessTestHelper.newApplication(); + + org.kie.kogito.process.Process process = + SubprocessWithSignalEndEventAndSignalBoundaryEventProcess.newProcess(app); Map params = new HashMap<>(); params.put("document-ref", "signalling"); params.put("message", "hello"); - KogitoProcessInstance processInstance = kruntime - .startProcess("SubprocessWithSignalEndEventAndSignalBoundaryEvent", params); - - assertNodeTriggered(processInstance.getStringId(), "sysout from boundary", "end2"); - assertNotNodeTriggered(processInstance.getStringId(), "end1"); - - assertProcessInstanceFinished(processInstance, kruntime); - } - - @Test - public void testSignalEndWithData() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithData.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - Map params = new HashMap<>(); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventSignalWithData", params); + SubprocessWithSignalEndEventAndSignalBoundaryEventModel model = process.createModel(); + model.fromMap(params); - assertProcessInstanceActive(processInstance); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); - kruntime.signalEvent("mysignal", null, processInstance.getStringId()); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); - assertProcessInstanceCompleted(processInstance); + } + @Test + public void testSignalEndWithData() { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = + IntermediateThrowEventSignalWithDataProcess.newProcess(app); + IntermediateThrowEventSignalWithDataModel model = definition.createModel(); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.send(Sig.of("mysignal", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test