Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-issues-1518] Testing external reference between userTasks and processes. #3702

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UserTaskInstance> 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);
Expand All @@ -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"));
Expand All @@ -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<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");

Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);

ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();

assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);

List<WorkItem> 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<UserTaskInstance> userTaskList = userTasks.instances().findByIdentity(IdentityProviders.of("mary"));
assertThat(userTaskList).hasSize(1);
// now we check the external reference properly sets one to the other
Optional<UserTaskInstance> 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
Expand Down
Loading