From 71d32b06d95d4750637004655d0258c431d3f702 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Tue, 8 Oct 2024 11:32:14 +0200 Subject: [PATCH] [incubator-kie-issues-1518] Testing external reference between user tasks and processes. --- .../process/impl/AbstractProcessInstance.java | 2 +- .../kie/kogito/codegen/tests/UserTaskIT.java | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java index 99f32900da2..106208afb05 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java @@ -539,7 +539,7 @@ private WorkItem toBaseWorkItem(WorkItemNodeInstance workItemNodeInstance) { workItem.getPhaseStatus(), workItem.getParameters(), workItem.getResults(), - workItem.getParameter(KogitoWorkItem.PARAMETER_UNIQUE_TASK_ID) + ":" + workItem.getExternalReferenceId()); + workItem.getExternalReferenceId()); } private boolean enforce(KogitoWorkItem kogitoWorkItem, Policy... policies) { diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/java/org/kie/kogito/codegen/tests/UserTaskIT.java b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/java/org/kie/kogito/codegen/tests/UserTaskIT.java index 7a0e493fa4f..6fb8fe66380 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/java/org/kie/kogito/codegen/tests/UserTaskIT.java +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/java/org/kie/kogito/codegen/tests/UserTaskIT.java @@ -47,7 +47,6 @@ import org.kie.kogito.process.Processes; import org.kie.kogito.process.VariableViolationException; import org.kie.kogito.process.WorkItem; -import org.kie.kogito.usertask.UserTask; import org.kie.kogito.usertask.UserTaskConfig; import org.kie.kogito.usertask.UserTaskInstance; import org.kie.kogito.usertask.UserTasks; @@ -107,17 +106,16 @@ public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) { UserTasks userTasks = app.get(UserTasks.class); - UserTask userTask_1 = userTasks.userTaskById(getUserTaskId(wi_1.getExternalReferenceId())); - UserTaskInstance userTaskInstance_1 = userTask_1.instances().findById(getUserTaskInstanceId(wi_1.getExternalReferenceId())).get(); + UserTaskInstance userTaskInstance_1 = userTasks.instances().findById(wi_1.getExternalReferenceId()).get(); assertThat(userTaskInstance_1).isNotNull(); List userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("mary")); assertThat(userTaskList).hasSize(1); - userTaskList = userTask_1.instances().findByIdentity(IdentityProviders.of("invalid")); + userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("invalid")); assertThat(userTaskList).hasSize(0); - userTaskList = userTask_1.instances().findByIdentity(IdentityProviders.of("john")); + userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("john")); assertThat(userTaskList).hasSize(1); userTaskInstance_1 = userTaskList.get(0); @@ -131,8 +129,7 @@ public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) { assertThat(workItems.get(0).getName()).isEqualTo("SecondTask"); WorkItem wi_2 = workItems.get(0); - UserTask userTask_2 = userTasks.userTaskById(getUserTaskId(wi_2.getExternalReferenceId())); - UserTaskInstance userTaskInstance_2 = userTask_2.instances().findById(getUserTaskInstanceId(wi_2.getExternalReferenceId())).get(); + UserTaskInstance userTaskInstance_2 = userTasks.instances().findById(wi_2.getExternalReferenceId()).get(); assertThat(userTaskInstance_2).isNotNull(); userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("john")); @@ -146,12 +143,44 @@ public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) { assertThat(workItemTransitionEvents).hasSize(8); } - private String getUserTaskInstanceId(String externalReference) { - return externalReference.split(":")[1]; - } + @Test + public void testDoubleLinkUserTaskProcesses() throws Exception { + + Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2"); + assertThat(app).isNotNull(); + + // we wired user tasks and processes + app.config().get(UserTaskConfig.class).userTaskEventListeners().listeners().add(new UserTaskKogitoWorkItemHandlerProcessListener(app.get(Processes.class))); + + Process p = app.get(Processes.class).processById("UserTasksProcess"); + + Model m = p.createModel(); + Map parameters = new HashMap<>(); + m.fromMap(parameters); + + ProcessInstance processInstance = p.createInstance(m); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + + List workItems = processInstance.workItems(); + assertThat(workItems).hasSize(1); + assertThat(workItems.get(0).getName()).isEqualTo("FirstTask"); + WorkItem wi_1 = workItems.get(0); - private String getUserTaskId(String externalReference) { - return externalReference.split(":")[0]; + UserTasks userTasks = app.get(UserTasks.class); + + UserTaskInstance userTaskInstance_1 = userTasks.instances().findById(wi_1.getExternalReferenceId()).get(); + assertThat(userTaskInstance_1).isNotNull(); + + List userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("mary")); + assertThat(userTaskList).hasSize(1); + // now we check the external reference properly sets one to the other + Optional utLinked = userTasks.instances().findById(wi_1.getExternalReferenceId()); + assertThat(utLinked).isPresent().get().extracting(UserTaskInstance::getExternalReferenceId).isEqualTo(wi_1.getId()); + assertThat(wi_1.getExternalReferenceId()).isEqualTo(utLinked.get().getId()); + + processInstance.abort(); } @Test