Skip to content

Commit

Permalink
[incubator-kie-issues#1719] Enable onEntry/onExit scripts in embedded…
Browse files Browse the repository at this point in the history
… nodes
  • Loading branch information
martinweiler committed Dec 17, 2024
1 parent 626c85e commit 0b90de2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected <U extends Node> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private <U extends org.kie.api.definition.process.Node> void visitNodes(List<U>
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);
}
}

Expand Down
44 changes: 23 additions & 21 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Integer> nodeInstanceExecutionCounter = new HashMap<>();
kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {
ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() {

@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
Expand All @@ -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<String, Object> 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<InclusiveGatewayWithLoopInsideSubprocessModel> process = InclusiveGatewayWithLoopInsideSubprocessProcess.newProcess(app);
InclusiveGatewayWithLoopInsideSubprocessModel model = process.createModel();
model.setX(-1);
ProcessInstance<InclusiveGatewayWithLoopInsideSubprocessModel> instance = process.createInstance(model);
instance.start();

assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<KogitoWorkItem> 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);
Expand Down

0 comments on commit 0b90de2

Please sign in to comment.