刘光辉
3 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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());
    }
}