diff --git a/api/kogito-api/src/main/java/org/kie/kogito/usertask/UserTaskInstance.java b/api/kogito-api/src/main/java/org/kie/kogito/usertask/UserTaskInstance.java index 6fcdd84c6f0..2f9078be17e 100644 --- a/api/kogito-api/src/main/java/org/kie/kogito/usertask/UserTaskInstance.java +++ b/api/kogito-api/src/main/java/org/kie/kogito/usertask/UserTaskInstance.java @@ -19,6 +19,7 @@ package org.kie.kogito.usertask; import java.util.Collection; +import java.util.Date; import java.util.Map; import java.util.Set; @@ -65,6 +66,8 @@ public interface UserTaskInstance { Map getInputs(); + Date getSlaDueDate(); + void setInput(String key, Object value); void setOutput(String key, Object value); diff --git a/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java b/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java index ac4cfa7b9b0..8fb02ea8c4e 100644 --- a/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java +++ b/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java @@ -49,6 +49,8 @@ public class UserTaskInstanceStateEventBody { private String externalReferenceId; + private Date slaDueDate; + public Date getEventDate() { return eventDate; } @@ -101,6 +103,10 @@ public String getExternalReferenceId() { return externalReferenceId; } + public Date getSlaDueDate() { + return slaDueDate; + } + public Map metaData() { Map metadata = new HashMap<>(); metadata.put(UserTaskInstanceEventMetadata.USER_TASK_INSTANCE_ID_META_DATA, userTaskInstanceId); @@ -114,7 +120,7 @@ public String toString() { return "UserTaskInstanceStateEventBody [eventDate=" + eventDate + ", eventUser=" + eventUser + ", userTaskDefinitionId=" + userTaskDefinitionId + ", userTaskInstanceId=" + userTaskInstanceId + ", userTaskName=" + userTaskName + ", userTaskDescription=" + userTaskDescription + ", userTaskPriority=" + userTaskPriority + ", userTaskReferenceName=" + userTaskReferenceName - + ", state=" + state + ", actualOwner=" + actualOwner + ", processInstanceId=" + processInstanceId + "]"; + + ", state=" + state + ", actualOwner=" + actualOwner + ", processInstanceId=" + processInstanceId + ", slaDueDate=" + slaDueDate + "]"; } public Builder update() { @@ -215,6 +221,11 @@ public Builder processInstanceId(String processInstanceId) { return this; } + public Builder slaDueDate(Date slaDueDate) { + this.instance.slaDueDate = slaDueDate; + return this; + } + public UserTaskInstanceStateEventBody build() { return this.instance; } diff --git a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/adapter/UserTaskStateEventDataEventAdapter.java b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/adapter/UserTaskStateEventDataEventAdapter.java index 68ade25916e..9df94e473db 100644 --- a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/adapter/UserTaskStateEventDataEventAdapter.java +++ b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/adapter/UserTaskStateEventDataEventAdapter.java @@ -42,7 +42,6 @@ public boolean accept(Object payload) { public DataEvent adapt(Object payload) { UserTaskStateEvent event = (UserTaskStateEvent) payload; Map metadata = AdapterHelper.buildUserTaskMetadata(event.getUserTaskInstance()); - UserTaskInstanceStateEventBody.Builder builder = UserTaskInstanceStateEventBody.create() .eventDate(new Date()) .eventUser(event.getEventUser()) @@ -56,7 +55,8 @@ public DataEvent adapt(Object payload) { .state(event.getNewStatus().getName()) .actualOwner(event.getUserTaskInstance().getActualOwner()) .eventType(isTransition(event) ? event.getNewStatus().getName() : "Modify") - .processInstanceId((String) event.getUserTaskInstance().getMetadata().get("ProcessInstanceId")); + .processInstanceId((String) event.getUserTaskInstance().getMetadata().get("ProcessInstanceId")) + .slaDueDate(event.getUserTaskInstance().getSlaDueDate()); UserTaskInstanceStateEventBody body = builder.build(); UserTaskInstanceStateDataEvent utEvent = 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/bpmn/org/jbpm/bpmn2/activity/BPMN2-ScriptTaskFEEL.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-ScriptTaskFEEL.bpmn2 index 0b5aaca47c0..4a3ee8caf6d 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-ScriptTaskFEEL.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/activity/BPMN2-ScriptTaskFEEL.bpmn2 @@ -33,6 +33,7 @@ + @@ -41,6 +42,7 @@ + diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/loop/BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutputCmpCondSequential.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/loop/BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutputCmpCondSequential.bpmn2 index 0b8a32113a4..284b56fc3d6 100644 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/loop/BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutputCmpCondSequential.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/loop/BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutputCmpCondSequential.bpmn2 @@ -45,8 +45,8 @@ - - System.out.println("Hello");context.setVariable("itemOut", "test"); + + System.out.println("Hello");kcontext.setVariable("itemOut", "test"); @@ -122,4 +122,4 @@ - \ No newline at end of file + diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-DynamicSignalParent.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-DynamicSignalParent.bpmn2 index 5a373981527..a3e3717e44f 100755 --- a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-DynamicSignalParent.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-DynamicSignalParent.bpmn2 @@ -20,7 +20,7 @@ - + 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 4058c91904a..8e36d1a04f1 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 @@ -31,6 +31,8 @@ import java.util.stream.Collectors; import org.drools.compiler.rule.builder.PackageBuildContext; +import org.jbpm.bpmn2.activity.ScriptTaskFEELModel; +import org.jbpm.bpmn2.activity.ScriptTaskFEELProcess; import org.jbpm.bpmn2.activity.ScriptTaskModel; import org.jbpm.bpmn2.activity.ScriptTaskProcess; import org.jbpm.bpmn2.activity.ScriptTaskWithIOModel; @@ -1815,28 +1817,27 @@ public void testBusinessRuleTaskFireLimitAsParameter() throws Exception { } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testScriptTaskFEEL() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ScriptTaskFEEL.bpmn2"); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - Map params = new HashMap<>(); - params.put("name", "krisv"); + public void testScriptTaskFEEL() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + EventTrackerProcessListener tracker = new EventTrackerProcessListener(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, tracker); + org.kie.kogito.process.Process processDefinition = ScriptTaskFEELProcess.newProcess(app); + ScriptTaskFEELModel model = processDefinition.createModel(); + model.setName("krisv"); Person person = new Person(); person.setName("krisv"); - params.put("person", person); - - KogitoProcessInstance processInstance = kruntime.startProcess("ScriptTask", params); - assertThat(((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance).getVariable("x")).isEqualTo("Entry"); - assertThat(((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance).getVariable("y")).isNull(); - - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertThat(getProcessVarValue(processInstance, "y")).isEqualTo("Exit"); - assertThat(((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance).getVariable("surname")).isEqualTo("tester"); - - assertNodeTriggered(processInstance.getStringId(), "Script1"); + model.setPerson(person); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.variables().getX()).isEqualTo("Entry"); + assertThat(processInstance.variables().getY()).isNull(); + ProcessTestHelper.completeWorkItem(processInstance, Collections.emptyMap()); + assertThat(processInstance.variables().getY()).isEqualTo("Exit"); + assertThat(processInstance.variables().getSurname()).isEqualTo("tester"); + Set nodes = tracker.tracked().stream().map(event -> event.getNodeInstance().getNodeName()).collect(Collectors.toSet()); + assertThat(nodes.contains("Script1")).isTrue(); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java index 7d80ffd4b3e..da9341b1bc3 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java @@ -25,6 +25,10 @@ import java.util.Map; import java.util.Optional; +import org.jbpm.bpmn2.error.BoundaryErrorEventCatchingOnEntryExceptionModel; +import org.jbpm.bpmn2.error.BoundaryErrorEventCatchingOnEntryExceptionProcess; +import org.jbpm.bpmn2.error.BoundaryErrorEventCatchingOnExitExceptionModel; +import org.jbpm.bpmn2.error.BoundaryErrorEventCatchingOnExitExceptionProcess; import org.jbpm.bpmn2.error.BoundaryErrorEventDefaultHandlerByErrorCodeModel; import org.jbpm.bpmn2.error.BoundaryErrorEventDefaultHandlerByErrorCodeProcess; import org.jbpm.bpmn2.error.BoundaryErrorEventDefaultHandlerWithErrorCodeWithStructureRefModel; @@ -71,7 +75,6 @@ import org.jbpm.process.workitem.builtin.SystemOutWorkItemHandler; import org.jbpm.test.utils.EventTrackerProcessListener; import org.jbpm.test.utils.ProcessTestHelper; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.event.process.DefaultProcessEventListener; import org.kie.api.event.process.ProcessNodeLeftEvent; @@ -445,31 +448,31 @@ public void testEventSubProcessErrorWithScript() throws Exception { } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testErrorBoundaryEventOnEntry() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundaryErrorEventCatchingOnEntryException.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryErrorEventOnEntry"); - - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - assertThat(handler.getWorkItems()).hasSize(1); + public void testErrorBoundaryEventOnEntry() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process processDefinition = BoundaryErrorEventCatchingOnEntryExceptionProcess.newProcess(app); + BoundaryErrorEventCatchingOnEntryExceptionModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + assertThat(workItemHandler.getWorkItems()).hasSize(1); } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testErrorBoundaryEventOnExit() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundaryErrorEventCatchingOnExitException.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - - KogitoProcessInstance processInstance = kruntime.startProcess("BoundaryErrorEventOnExit"); - - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - KogitoWorkItem workItem = handler.getWorkItem(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertThat(handler.getWorkItems()).hasSize(1); + public void testErrorBoundaryEventOnExit() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process processDefinition = BoundaryErrorEventCatchingOnExitExceptionProcess.newProcess(app); + BoundaryErrorEventCatchingOnExitExceptionModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + KogitoWorkItem workItem = workItemHandler.getWorkItem(); + processInstance.completeWorkItem(workItem.getStringId(), Collections.emptyMap()); + assertThat(workItemHandler.getWorkItems()).hasSize(1); } @Test 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..4da5bd3497b 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,10 @@ import org.jbpm.bpmn2.flow.InclusiveGatewayWithDefaultProcess; import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessModel; import org.jbpm.bpmn2.flow.InclusiveGatewayWithHumanTasksProcessProcess; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithLoopInsideModel; +import org.jbpm.bpmn2.flow.InclusiveGatewayWithLoopInsideProcess; +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; @@ -93,6 +97,8 @@ import org.jbpm.bpmn2.flow.MultiInstanceLoopNumberingProcess; import org.jbpm.bpmn2.flow.MultipleGatewaysProcessModel; import org.jbpm.bpmn2.flow.MultipleGatewaysProcessProcess; +import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsProcessWithOutputAndScriptsModel; +import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsProcessWithOutputAndScriptsProcess; import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsTaskModel; import org.jbpm.bpmn2.loop.MultiInstanceLoopCharacteristicsTaskProcess; import org.jbpm.bpmn2.objects.TestUserTaskWorkItemHandler; @@ -779,50 +785,55 @@ public void testInclusiveSplitNested() { } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testInclusiveSplitWithLoopInside() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-InclusiveGatewayWithLoopInside.bpmn2"); - + public void testInclusiveSplitWithLoopInside() { + 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) { logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel()); Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName()); if (value == null) { - value = new Integer(0); + value = 0; } - value++; nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value); } - }); + 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); + + org.kie.kogito.process.Process processDefinition = InclusiveGatewayWithLoopInsideProcess.newProcess(app); + InclusiveGatewayWithLoopInsideModel model = processDefinition.createModel(); + model.setX(-1); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - assertProcessInstanceActive(processInstance); List workItems = handler.getWorkItems(); assertThat(workItems).isNotNull().hasSize(2); for (KogitoWorkItem wi : workItems) { - assertProcessInstanceActive(processInstance); - kruntime.getKogitoWorkItemManager().completeWorkItem(wi.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.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(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.completeWorkItem(handler2.getWorkItem().getStringId(), null); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.completeWorkItem(handler2.getWorkItem().getStringId(), null); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + processInstance.completeWorkItem(handler.getWorkItem().getStringId(), null); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(nodeInstanceExecutionCounter).hasSize(10); assertThat((int) nodeInstanceExecutionCounter.get("Start")).isEqualTo(1); assertThat((int) nodeInstanceExecutionCounter.get("OR diverging")).isEqualTo(1); @@ -837,12 +848,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 +866,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); + 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); @@ -1124,69 +1135,59 @@ public void testMultiInstanceLoopCharacteristicsProcessWithOutputCompletionCondi } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testMultiInstanceLoopCharacteristicsProcessWithOutputAndScripts() - throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MultiInstanceLoopCharacteristicsProcessWithOutputAndScripts.bpmn2"); - Map params = new HashMap<>(); + public void testMultiInstanceLoopCharacteristicsProcessWithOutputAndScripts() { + Application app = ProcessTestHelper.newApplication(); List myList = new ArrayList<>(); List myListOut = new ArrayList<>(); List scriptList = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - params.put("listOut", myListOut); - params.put("scriptList", scriptList); assertThat(myListOut).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess("MultiInstanceLoopCharacteristicsProcessWithOutput", params); - assertProcessInstanceCompleted(processInstance); + org.kie.kogito.process.Process processDefinition = + MultiInstanceLoopCharacteristicsProcessWithOutputAndScriptsProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessWithOutputAndScriptsModel model = processDefinition.createModel(); + model.setList(myList); + model.setListOut(myListOut); + model.setScriptList(scriptList); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(myListOut).hasSize(2); assertThat(scriptList).hasSize(2); - } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testMultiInstanceLoopCharacteristicsTaskWithOutput() - throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutput.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", + public void testMultiInstanceLoopCharacteristicsTaskWithOutput() { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); - Map params = new HashMap<>(); List myList = new ArrayList<>(); - List myListOut = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - params.put("listOut", myListOut); - assertThat(myListOut).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MultiInstanceLoopCharacteristicsTask", params); - assertProcessInstanceCompleted(processInstance); - assertThat(myListOut).hasSize(2); - + Process process = MultiInstanceLoopCharacteristicsProcessWithOutputProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessWithOutputModel model = process.createModel(); + model.setList(myList); + ProcessInstance instance = process.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getListOut()).hasSize(2); } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testMultiInstanceLoopCharacteristicsTaskWithOutputCompletionCondition() - throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MultiInstanceLoopCharacteristicsTaskWithOutputCmpCond.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", + public void testMultiInstanceLoopCharacteristicsTaskWithOutputCompletionCondition() { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); - Map params = new HashMap<>(); List myList = new ArrayList<>(); - List myListOut = new ArrayList<>(); myList.add("First Item"); myList.add("Second Item"); - params.put("list", myList); - params.put("listOut", myListOut); - assertThat(myListOut).isEmpty(); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MultiInstanceLoopCharacteristicsTask", params); - assertProcessInstanceCompleted(processInstance); - assertThat(myListOut).hasSize(1); - + Process process = MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondProcess.newProcess(app); + MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondModel model = process.createModel(); + model.setList(myList); + ProcessInstance instance = process.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getListOut()).hasSize(1); } @Test @@ -1213,7 +1214,6 @@ public void testMultiInstanceLoopCharacteristicsTaskWithOutputCompletionConditio // only two approved outcomes are required to complete multiinstance and since there was reject in between we should have // three elements in the list assertThat(myListOut).hasSize(3); - } @Test 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 7029ebd9832..0b8a201e2cf 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 @@ -59,6 +59,10 @@ import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestUserTaskWorkItemHandler; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.subprocess.DynamicSignalChildModel; +import org.jbpm.bpmn2.subprocess.DynamicSignalChildProcess; +import org.jbpm.bpmn2.subprocess.DynamicSignalParentModel; +import org.jbpm.bpmn2.subprocess.DynamicSignalParentProcess; import org.jbpm.bpmn2.subprocess.EventSubprocessConditionalModel; import org.jbpm.bpmn2.subprocess.EventSubprocessConditionalProcess; import org.jbpm.bpmn2.subprocess.EventSubprocessMessageModel; @@ -2686,45 +2690,23 @@ public void testSignalEndWithData() { } @Test - @Disabled("On Exit not supported, see https://issues.redhat.com/browse/KOGITO-2067") - public void testDynamicCatchEventSignal() throws Exception { - kruntime = createKogitoProcessRuntime("subprocess/dynamic-signal-parent.bpmn2", - "subprocess/dynamic-signal-child.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - final List instances = new ArrayList<>(); - - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { - - @Override - public void beforeProcessStarted(ProcessStartedEvent event) { - instances.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId()); - } - - }); - - KogitoProcessInstance processInstance = kruntime.startProcess("src.father"); - assertProcessInstanceActive(processInstance); - assertThat(instances).hasSize(4); - - // remove the parent process instance - instances.remove(processInstance.getStringId()); - - for (String id : instances) { - KogitoProcessInstance child = kruntime.getProcessInstance(id); - assertProcessInstanceActive(child); - } - - // now complete user task to signal all child instances to stop - KogitoWorkItem workItem = handler.getWorkItem(); + void testDynamicCatchEventSignal() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process processDefinition = DynamicSignalParentProcess.newProcess(app); + DynamicSignalParentModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + org.kie.kogito.process.Process childProcessDefinition = DynamicSignalChildProcess.newProcess(app); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + List> childInstances = childProcessDefinition.instances().stream().toList(); + assertThat(childInstances).hasSize(3); + childInstances.forEach(instance -> assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE)); + KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - - for (String id : instances) { - assertThat(kruntime.getProcessInstance(id)).as("Child process instance has not been finished.").isNull(); - } + processInstance.completeWorkItem(workItem.getStringId(), Collections.emptyMap()); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test diff --git a/jbpm/jbpm-usertask-workitem/src/main/java/org/kie/kogito/jbpm/usertask/handler/UserTaskKogitoWorkItemHandler.java b/jbpm/jbpm-usertask-workitem/src/main/java/org/kie/kogito/jbpm/usertask/handler/UserTaskKogitoWorkItemHandler.java index 000e78a2d2c..02b46ecd56b 100644 --- a/jbpm/jbpm-usertask-workitem/src/main/java/org/kie/kogito/jbpm/usertask/handler/UserTaskKogitoWorkItemHandler.java +++ b/jbpm/jbpm-usertask-workitem/src/main/java/org/kie/kogito/jbpm/usertask/handler/UserTaskKogitoWorkItemHandler.java @@ -88,6 +88,7 @@ public Optional activateWorkItemHandler(KogitoWorkItemManage instance.setTaskName(ofNullable((String) workItem.getParameter(TASK_NAME)).orElse((String) workItem.getParameter(NODE_NAME))); instance.setTaskDescription((String) workItem.getParameter(DESCRIPTION)); instance.setTaskPriority(priority != null ? priority.toString() : null); + instance.setSlaDueDate(workItem.getNodeInstance().getSlaDueDate()); instance.setMetadata("ProcessId", workItem.getProcessInstance().getProcessId()); instance.setMetadata("ProcessType", workItem.getProcessInstance().getProcess().getType()); diff --git a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskInstance.java b/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskInstance.java index 26cfb631a8b..287b7b4fe8a 100644 --- a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskInstance.java +++ b/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/DefaultUserTaskInstance.java @@ -82,6 +82,7 @@ public class DefaultUserTaskInstance implements UserTaskInstance { private List attachments; private List comments; private String externalReferenceId; + private Date slaDueDate; private Map inputs; private Map outputs; @@ -242,6 +243,15 @@ public void setExternalReferenceId(String externalReferenceId) { this.externalReferenceId = externalReferenceId; } + @Override + public Date getSlaDueDate() { + return slaDueDate; + } + + public void setSlaDueDate(Date slaDueDate) { + this.slaDueDate = slaDueDate; + } + @Override public void initialize(Map data, IdentityProvider identity) { transition(this.userTaskLifeCycle.startTransition(), data, identity); @@ -782,7 +792,7 @@ private void reassign(Reassignment reassignment) { @Override public String toString() { return "DefaultUserTaskInstance [id=" + id + ", status=" + status + ", actualOwner=" + actualOwner + ", taskName=" + taskName + ", taskDescription=" + taskDescription + ", taskPriority=" - + taskPriority + "]"; + + taskPriority + ", slaDueDate=" + slaDueDate + "]"; } }