Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JacekMiszczak committed Dec 11, 2024
1 parent 9888c5c commit f185fba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,34 @@
*/
package org.flowable.engine.test.api.task;

import java.util.HashSet;
import java.util.Set;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.identitylink.api.IdentityLink;
import org.flowable.task.service.delegate.DelegateTask;

public class DeleteCandidateTaskListener implements TaskListener {
public static final String VARNAME_CANDIDATE_USERS = "candidateUsers";
public static final String VARNAME_CANDIDATE_GROUPS = "candidateGroups";

@Override
public void notify(DelegateTask delegateTask) {
delegateTask.deleteCandidateUser("admin");
delegateTask.deleteCandidateGroup("admins");

Set<IdentityLink> candidates = delegateTask.getCandidates();
Set<String> candidateUsers = new HashSet<>();
Set<String> candidateGroups = new HashSet<>();
for (IdentityLink candidate : candidates) {
if (candidate.getUserId() != null) {
candidateUsers.add(candidate.getUserId());
} else if (candidate.getGroupId() != null) {
candidateGroups.add(candidate.getGroupId());
}
}
delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.history.HistoryLevel;
Expand Down Expand Up @@ -321,16 +322,32 @@ public void testDeleteOwner() {
}

@Test
@Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testDeleteCandidateUser.bpmn20.xml")
public void testDeleteCandidateUser() {
@Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testDeleteCandidates.bpmn20.xml")
public void testDeleteCandidates() {
runtimeService.startProcessInstanceByKey("TaskIdentityLinks");

String taskId = taskService.createTaskQuery().singleResult().getId();

List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
assertThat(identityLinks)
.filteredOn(identityLink -> identityLink.getUserId() != null)
.extracting(IdentityLink::getUserId)
.containsExactly("user");

assertThat(identityLinks)
.filteredOn(identityLink -> identityLink.getGroupId() != null)
.extracting(IdentityLink::getGroupId)
.containsExactly("users");

@SuppressWarnings("unchecked")
Set<String> candidateUsers = (Set<String>) taskService.getVariable(taskId, DeleteCandidateTaskListener.VARNAME_CANDIDATE_USERS);
assertThat(candidateUsers)
.containsExactly("user");

@SuppressWarnings("unchecked")
Set<String> candidateGroups = (Set<String>) taskService.getVariable(taskId, DeleteCandidateTaskListener.VARNAME_CANDIDATE_GROUPS);
assertThat(candidateGroups)
.containsExactly("users");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</extensionElements>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>user(user),user(admin)</formalExpression>
<formalExpression>user(user),user(admin),group(users),group(admins)</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
Expand Down

0 comments on commit f185fba

Please sign in to comment.