From 0b90de2e181b85ba02bbf291271b179eb329d38f Mon Sep 17 00:00:00 2001 From: Martin Weiler Date: Tue, 17 Dec 2024 16:20:59 -0700 Subject: [PATCH] [incubator-kie-issues#1719] Enable onEntry/onExit scripts in embedded nodes --- .../AbstractCompositeNodeVisitor.java | 2 +- .../canonical/AbstractNodeVisitor.java | 4 +- .../compiler/canonical/ProcessVisitor.java | 2 +- .../test/java/org/jbpm/bpmn2/FlowTest.java | 44 ++++++++++--------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractCompositeNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractCompositeNodeVisitor.java index fd7b95c4454..b013e532640 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractCompositeNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractCompositeNodeVisitor.java @@ -40,7 +40,7 @@ protected void visitNodes(String factoryField, U[] nodes, Block if (visitor == null) { continue; } - visitor.visitNode(factoryField, node, body, variableScope, metadata); + visitor.visitNodeEntryPoint(factoryField, node, body, variableScope, metadata); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java index 1946318d05c..d54eafedc3a 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java @@ -114,8 +114,8 @@ public ReturnValueEvaluatorBuilderService getReturnValueEvaluatorBuilderService( return returnValueEvaluatorBuilderService; } - public void visitNode(T node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { - visitNode(FACTORY_FIELD_NAME, node, body, variableScope, metadata); + public void visitNodeEntryPoint(String factoryName, T node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { + visitNode((factoryName != null ? factoryName : FACTORY_FIELD_NAME), node, body, variableScope, metadata); if (isAdHocNode(node)) { metadata.addSignal(node.getName(), null); } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java index 39605eafc5e..0883e0d0ec5 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java @@ -230,7 +230,7 @@ private void visitNodes(List if (visitor == null) { throw new IllegalStateException("No visitor found for node " + node.getClass().getName()); } - visitor.visitNode(node, body, variableScope, metadata); + visitor.visitNodeEntryPoint(null, node, body, variableScope, metadata); } } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java index 4223c3ed323..86a845c6937 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java @@ -55,6 +55,8 @@ import org.jbpm.bpmn2.flow.InclusiveGatewayWithDefaultProcess; import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessModel; import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessProcess; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithLoopInsideSubprocessModel; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithLoopInsideSubprocessProcess; import org.jbpm.bpmn2.flow.InclusiveNestedInParallelNestedInExclusiveModel; import org.jbpm.bpmn2.flow.InclusiveNestedInParallelNestedInExclusiveProcess; import org.jbpm.bpmn2.flow.InclusiveSplitAndJoinEmbeddedModel; @@ -837,12 +839,10 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") public void testInclusiveSplitWithLoopInsideSubprocess() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-InclusiveGatewayWithLoopInsideSubprocess.bpmn2"); - + Application app = ProcessTestHelper.newApplication(); final Map nodeInstanceExecutionCounter = new HashMap<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { @@ -857,30 +857,32 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { } }); + TestWorkItemHandler handler = new TestWorkItemHandler(); TestWorkItemHandler handler2 = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("testWI", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("testWI2", handler2); - Map params = new HashMap<>(); - params.put("x", -1); - KogitoProcessInstance processInstance = kruntime.startProcess("Process_1", params); + ProcessTestHelper.registerHandler(app, "testWI", handler); + ProcessTestHelper.registerHandler(app, "testWI2", handler2); - assertProcessInstanceActive(processInstance); + Process process = InclusiveGatewayWithLoopInsideSubprocessProcess.newProcess(app); + InclusiveGatewayWithLoopInsideSubprocessModel model = process.createModel(); + model.setX(-1); + ProcessInstance instance = process.createInstance(model); + instance.start(); + + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); - for (KogitoWorkItem wi : workItems) { - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), null); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + instance.completeWorkItem(wi.getStringId(), null); } - - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler2.getWorkItem().getStringId(), null); - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler2.getWorkItem().getStringId(), null); - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertProcessInstanceCompleted(processInstance); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + instance.completeWorkItem(handler2.getWorkItem().getStringId(), null);//After this line, state of the process instance is error state instead of active + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + instance.completeWorkItem(handler2.getWorkItem().getStringId(), null); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + instance.completeWorkItem(handler.getWorkItem().getStringId(), null); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(nodeInstanceExecutionCounter).hasSize(13); assertThat((int) nodeInstanceExecutionCounter.get("Start")).isEqualTo(1); assertThat((int) nodeInstanceExecutionCounter.get("Sub Process 1")).isEqualTo(1);