From 7b184edec55957c14fb10b718126975d004a5ffa Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Thu, 16 May 2024 01:30:41 -0400 Subject: [PATCH 1/4] [incubator-kie-issues-1131] Process test migration from v7 legacy runtime to code generation --- .../java/org/jbpm/bpmn2/ActivityTest.java | 166 +++++++++--------- 1 file changed, 79 insertions(+), 87 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 319595851d3..f93c3cec789 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 @@ -19,29 +19,19 @@ package org.jbpm.bpmn2; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import org.drools.compiler.rule.builder.PackageBuildContext; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; import org.jbpm.bpmn2.handler.ServiceTaskHandler; -import org.jbpm.bpmn2.objects.Account; -import org.jbpm.bpmn2.objects.Address; -import org.jbpm.bpmn2.objects.HelloService; -import org.jbpm.bpmn2.objects.Person; -import org.jbpm.bpmn2.objects.TestWorkItemHandler; -import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsModel; -import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsProcess; +import org.jbpm.bpmn2.objects.*; +import org.jbpm.bpmn2.subprocess.*; +import org.jbpm.bpmn2.task.ReceiveTaskModel; +import org.jbpm.bpmn2.task.ReceiveTaskProcess; import org.jbpm.bpmn2.test.RequirePersistence; -import org.jbpm.process.builder.ActionBuilder; -import org.jbpm.process.builder.AssignmentBuilder; -import org.jbpm.process.builder.ProcessBuildContext; -import org.jbpm.process.builder.ProcessClassBuilder; -import org.jbpm.process.builder.ReturnValueEvaluatorBuilder; +import org.jbpm.process.builder.*; import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; import org.jbpm.process.core.context.variable.VariableScope; @@ -61,6 +51,8 @@ import org.jbpm.workflow.instance.WorkflowRuntimeException; import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl; import org.jbpm.workflow.instance.node.DynamicUtils; +import org.jbpm.workflow.instance.node.EndNodeInstance; +import org.jbpm.workflow.instance.node.StartNodeInstance; import org.jbpm.workflow.instance.node.WorkItemNodeInstance; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -70,30 +62,20 @@ 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.ProcessNodeEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.event.process.ProcessVariableChangedEvent; -import org.kie.api.event.rule.AfterMatchFiredEvent; -import org.kie.api.event.rule.AgendaEventListener; -import org.kie.api.event.rule.BeforeMatchFiredEvent; -import org.kie.api.event.rule.MatchCancelledEvent; -import org.kie.api.event.rule.MatchCreatedEvent; +import org.kie.api.event.rule.*; import org.kie.api.runtime.process.DataTransformer; import org.kie.api.runtime.process.NodeInstance; import org.kie.kogito.Application; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; -import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer; -import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; -import org.kie.kogito.internal.process.runtime.KogitoWorkItem; -import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager; -import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; +import org.kie.kogito.internal.process.runtime.*; import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assertions.*; public class ActivityTest extends JbpmBpmn2TestCase { @@ -410,25 +392,27 @@ public void testUserTaskVerifyParameters() throws Exception { } @Test - public void testCallActivityWithContantsAssignment() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/subprocess/BPMN2-SingleTaskWithVarDef.bpmn2", - "org/jbpm/bpmn2/subprocess/BPMN2-InputMappingUsingValue.bpmn2"); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("CustomTask", handler); - Map params = new HashMap<>(); - KogitoProcessInstance processInstance = kruntime.startProcess("InputMappingUsingValue", params); - - org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = handler.getWorkItem(); + public void testCallActivityWithContantsAssignment() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "CustomTask", workItemHandler); + org.kie.kogito.process.Process singleTaskWithVarDefModelProcess = SingleTaskWithVarDefProcess.newProcess(app); + SingleTaskWithVarDefModel singleTaskWithVarDefModel = singleTaskWithVarDefModelProcess.createModel(); + ProcessInstance singleTaskWithVarDefModelProcessInstance = singleTaskWithVarDefModelProcess.createInstance(singleTaskWithVarDefModel); + + org.kie.kogito.process.Process processDefinition = InputMappingUsingValueProcess.newProcess(app); + InputMappingUsingValueModel model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); + KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - Object value = workItem.getParameter("TaskName"); assertThat(value).isNotNull().isEqualTo("test string"); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - - assertProcessInstanceCompleted(processInstance); + singleTaskWithVarDefModelProcessInstance.completeWorkItem(workItem.getStringId(), Collections.emptyMap()); + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test @@ -456,16 +440,18 @@ public void testSubProcessWithEntryExitScripts() throws Exception { } @Test - public void testCallActivity() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-CallActivity.bpmn2", - "org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcess.bpmn2"); + public void testCallActivity() { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process processDefinition = CallActivityProcess.newProcess(app); + CallActivityModel model = processDefinition.createModel(); + model.setX("oldValue"); + ProcessInstance instance = processDefinition.createInstance(model); - Map params = new HashMap<>(); - params.put("x", "oldValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "CallActivity", params); - assertProcessInstanceCompleted(processInstance); - assertThat(((KogitoWorkflowProcessInstance) processInstance).getVariable("y")).isEqualTo("new value"); + CallActivitySubProcessProcess.newProcess(app); + + instance.start(); + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getY()).isEqualTo("new value"); } @Test @@ -607,36 +593,40 @@ public void testMultiinstanceSubProcessWrongStartEvent() throws Exception { } @Test - public void testSubProcessWithTerminateEndEvent() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-SubProcessWithTerminateEndEvent.bpmn2"); - final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + public void testSubProcessWithTerminateEndEvent() { + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = SubProcessWithTerminateEndEventProcess.newProcess(app); + SubProcessWithTerminateEndEventModel model = processDefinition.createModel(); + + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + Set processNodeEvents = listener.tracked().stream() + .map(ProcessNodeEvent::getNodeInstance) + .collect(Collectors.toSet()); + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processNodeEvents).hasSize(7); - @Override - public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { - list.add(event.getNodeInstance().getNodeName()); - } - }); - KogitoProcessInstance processInstance = kruntime.startProcess("SubProcessWithTerminateEndEvent"); - assertProcessInstanceCompleted(processInstance); - assertThat(list).hasSize(7); } @Test - public void testSubProcessWithTerminateEndEventProcessScope() - throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-SubProcessWithTerminateEndEventProcessScope.bpmn2"); - final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + public void testSubProcessWithTerminateEndEventProcessScope() { - @Override - public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { - list.add(event.getNodeInstance().getNodeName()); - } - }); - KogitoProcessInstance processInstance = kruntime.startProcess("SubProcessWithTerminateEndEventProcessScope"); - assertProcessInstanceCompleted(processInstance); - assertThat(list).hasSize(5); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = SubProcessWithTerminateEndEventProcessScopeProcess.newProcess(app); + SubProcessWithTerminateEndEventProcessScopeModel model = processDefinition.createModel(); + + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + Set processNodeEvents = listener.tracked().stream() + .map(ProcessNodeEvent::getNodeInstance) + .filter(nodeInstance -> !(nodeInstance instanceof EndNodeInstance || nodeInstance instanceof StartNodeInstance)) + .collect(Collectors.toSet()); + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(processNodeEvents).hasSize(3); } @Test @@ -841,17 +831,19 @@ public void testSendTask() throws Exception { @Test public void testReceiveTask() throws Exception { + Application app = ProcessTestHelper.newApplication(); kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/task/BPMN2-ReceiveTask.bpmn2"); ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(kruntime); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Receive Task", - receiveTaskHandler); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ReceiveTask"); - assertProcessInstanceActive(processInstance); + ProcessTestHelper.registerHandler(app, "Receive Task", receiveTaskHandler); + org.kie.kogito.process.Process processDefinition = ReceiveTaskProcess.newProcess(app); + ReceiveTaskModel model = processDefinition.createModel(); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_ACTIVE); receiveTaskHandler.setKnowledgeRuntime(kruntime); receiveTaskHandler.messageReceived("HelloMessage", "Hello john!"); - assertProcessInstanceFinished(processInstance, kruntime); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test From b8484d190757df434676b18e37aa61d725193f80 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Thu, 16 May 2024 12:33:49 -0400 Subject: [PATCH 2/4] moved the newProcess to same code block --- jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java | 1 - 1 file changed, 1 deletion(-) 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 f93c3cec789..7ee8eb71396 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 @@ -399,7 +399,6 @@ public void testCallActivityWithContantsAssignment() { org.kie.kogito.process.Process singleTaskWithVarDefModelProcess = SingleTaskWithVarDefProcess.newProcess(app); SingleTaskWithVarDefModel singleTaskWithVarDefModel = singleTaskWithVarDefModelProcess.createModel(); ProcessInstance singleTaskWithVarDefModelProcessInstance = singleTaskWithVarDefModelProcess.createInstance(singleTaskWithVarDefModel); - org.kie.kogito.process.Process processDefinition = InputMappingUsingValueProcess.newProcess(app); InputMappingUsingValueModel model = processDefinition.createModel(); org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); From 76142d94abf2881a91aaf42bedb0d1d98637958f Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Mon, 20 May 2024 08:26:21 -0400 Subject: [PATCH 3/4] [incubator-kie-issues-1131] Formatted code style --- .../java/org/jbpm/bpmn2/ActivityTest.java | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 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 f93c3cec789..849c7458e1b 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 @@ -19,19 +19,44 @@ package org.jbpm.bpmn2; import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import org.drools.compiler.rule.builder.PackageBuildContext; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; import org.jbpm.bpmn2.handler.ServiceTaskHandler; -import org.jbpm.bpmn2.objects.*; -import org.jbpm.bpmn2.subprocess.*; +import org.jbpm.bpmn2.objects.Account; +import org.jbpm.bpmn2.objects.Address; +import org.jbpm.bpmn2.objects.HelloService; +import org.jbpm.bpmn2.objects.Person; +import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.subprocess.CallActivityModel; +import org.jbpm.bpmn2.subprocess.CallActivityProcess; +import org.jbpm.bpmn2.subprocess.CallActivitySubProcessProcess; +import org.jbpm.bpmn2.subprocess.InputMappingUsingValueModel; +import org.jbpm.bpmn2.subprocess.InputMappingUsingValueProcess; +import org.jbpm.bpmn2.subprocess.SingleTaskWithVarDefModel; +import org.jbpm.bpmn2.subprocess.SingleTaskWithVarDefProcess; +import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsModel; +import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsProcess; +import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventModel; +import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcess; +import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeModel; +import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeProcess; import org.jbpm.bpmn2.task.ReceiveTaskModel; import org.jbpm.bpmn2.task.ReceiveTaskProcess; import org.jbpm.bpmn2.test.RequirePersistence; -import org.jbpm.process.builder.*; +import org.jbpm.process.builder.ActionBuilder; +import org.jbpm.process.builder.AssignmentBuilder; +import org.jbpm.process.builder.ProcessBuildContext; +import org.jbpm.process.builder.ProcessClassBuilder; +import org.jbpm.process.builder.ReturnValueEvaluatorBuilder; import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; import org.jbpm.process.core.context.variable.VariableScope; @@ -66,16 +91,27 @@ import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.event.process.ProcessVariableChangedEvent; -import org.kie.api.event.rule.*; +import org.kie.api.event.rule.AfterMatchFiredEvent; +import org.kie.api.event.rule.AgendaEventListener; +import org.kie.api.event.rule.BeforeMatchFiredEvent; +import org.kie.api.event.rule.MatchCancelledEvent; +import org.kie.api.event.rule.MatchCreatedEvent; import org.kie.api.runtime.process.DataTransformer; import org.kie.api.runtime.process.NodeInstance; import org.kie.kogito.Application; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; -import org.kie.kogito.internal.process.runtime.*; +import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer; +import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; +import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; +import org.kie.kogito.internal.process.runtime.KogitoWorkItem; +import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager; +import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.fail; public class ActivityTest extends JbpmBpmn2TestCase { From bea34158d975b873ef89f49c50e831619d9940d5 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Mon, 20 May 2024 22:58:05 -0400 Subject: [PATCH 4/4] [incubator-kie-issues-1131] testSubProcessWithTerminateEndEventProcessScope changes --- .../test/java/org/jbpm/bpmn2/ActivityTest.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 dd2c32e6008..d24bd80386f 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 @@ -649,19 +649,25 @@ public void testSubProcessWithTerminateEndEvent() { public void testSubProcessWithTerminateEndEventProcessScope() { Application app = ProcessTestHelper.newApplication(); - EventTrackerProcessListener listener = new EventTrackerProcessListener(); + final List nodeList = new ArrayList<>(); + EventTrackerProcessListener listener = new EventTrackerProcessListener() { + + @Override + public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { + NodeInstance nodeInstance = event.getNodeInstance(); + if (!(nodeInstance instanceof EndNodeInstance || nodeInstance instanceof StartNodeInstance)) { + nodeList.add(nodeInstance.getNodeName()); + } + } + }; ProcessTestHelper.registerProcessEventListener(app, listener); org.kie.kogito.process.Process processDefinition = SubProcessWithTerminateEndEventProcessScopeProcess.newProcess(app); SubProcessWithTerminateEndEventProcessScopeModel model = processDefinition.createModel(); org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); instance.start(); - Set processNodeEvents = listener.tracked().stream() - .map(ProcessNodeEvent::getNodeInstance) - .filter(nodeInstance -> !(nodeInstance instanceof EndNodeInstance || nodeInstance instanceof StartNodeInstance)) - .collect(Collectors.toSet()); assertThat(instance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED); - assertThat(processNodeEvents).hasSize(3); + assertThat(nodeList).hasSize(3); } @Test