package jnpf.flowable.service.dev;
|
|
import jnpf.flowable.entity.TaskEntity;
|
import jnpf.flowable.entity.TemplateNodeEntity;
|
import jnpf.flowable.model.task.FlowMethod;
|
import jnpf.flowable.model.task.FlowModel;
|
import jnpf.flowable.model.util.DevApprovalActor;
|
import jnpf.flowable.util.FlowUtil;
|
import jnpf.flowable.util.ServiceUtil;
|
import jnpf.permission.entity.UserEntity;
|
import org.junit.Test;
|
|
import java.util.List;
|
|
import static org.junit.Assert.*;
|
import static org.mockito.Mockito.*;
|
|
public class DevApprovalCandidatesTest {
|
private final FlowUtil flow = mock(FlowUtil.class, CALLS_REAL_METHODS);
|
|
private FlowMethod method(String taskId, String type) throws Exception {
|
ServiceUtil service = mock(ServiceUtil.class);
|
var field = FlowUtil.class.getDeclaredField("serviceUtil");
|
field.setAccessible(true);
|
field.set(flow, service);
|
UserEntity user = new UserEntity(); user.setId("signer");
|
when(service.getUserName(List.of("signer"), true)).thenReturn(List.of(user));
|
TaskEntity task = new TaskEntity(); task.setId(taskId); task.setCreatorUserId("signer");
|
TemplateNodeEntity node = new TemplateNodeEntity();
|
node.setNodeJson("{\"type\":\"" + type + "\",\"assigneeType\":3,\"isCandidates\":false}");
|
TemplateNodeEntity global = new TemplateNodeEntity(); global.setNodeType("global"); global.setNodeJson("{}");
|
FlowMethod method = new FlowMethod(); method.setTaskEntity(task); method.setNodeEntity(node);
|
method.setNodeEntityList(List.of(global)); method.setFlowModel(new FlowModel());
|
return method;
|
}
|
|
@Test public void automaticApproverUsesSignerAndClearsExhaustion() throws Exception {
|
FlowMethod method = method("task", "approver");
|
method.setAdjacentHandlerCandidatesExhausted(true);
|
try (DevApprovalActor ignored = DevApprovalActor.open("op", "signer", "task")) {
|
assertEquals(List.of("signer"), flow.userListAll(method));
|
assertFalse(method.getAdjacentHandlerCandidatesExhausted());
|
verify(flow, never()).excludePreviousHandlerForOrSign(anyList(), any(), anyString());
|
}
|
assertTrue(flow.userListAll(method).isEmpty());
|
assertTrue(method.getAdjacentHandlerCandidatesExhausted());
|
}
|
|
@Test public void processingAndSelfSelectedCandidatesUseSigner() throws Exception {
|
for (String type : List.of("approver", "processing")) {
|
FlowMethod method = method("task", type);
|
method.getNodeEntity().setNodeJson("{\"type\":\"" + type + "\",\"isCandidates\":true}");
|
try (DevApprovalActor ignored = DevApprovalActor.open("op", "signer", "task")) {
|
assertEquals(List.of("signer"), flow.userListAll(method));
|
}
|
}
|
}
|
|
@Test public void otherTaskCannotInheritSigner() throws Exception {
|
FlowMethod method = method("other-task", "approver");
|
try (DevApprovalActor ignored = DevApprovalActor.open("op", "signer", "task")) {
|
assertNull(DevApprovalActor.candidateForTask("other-task"));
|
assertTrue(flow.userListAll(method).isEmpty());
|
assertTrue(method.getAdjacentHandlerCandidatesExhausted());
|
}
|
}
|
|
@Test public void normalApprovalStillExcludesPreviousHandler() throws Exception {
|
assertNull(DevApprovalActor.candidateForTask("task"));
|
FlowMethod method = method("task", "approver");
|
assertTrue(flow.userListAll(method).isEmpty());
|
assertTrue(method.getAdjacentHandlerCandidatesExhausted());
|
}
|
}
|