刘光辉
4 小时以前 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
package jnpf.flowable.service;
 
import jnpf.exception.WorkFlowException;
import jnpf.flowable.entity.*;
import jnpf.flowable.mapper.TaskMapper;
import jnpf.flowable.mapper.TemplateNodeMapper;
import jnpf.flowable.util.OperatorUtil;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
 
public class WorkflowAuditContextResolverTest {
    private OperatorUtil operators;
    private TaskMapper tasks;
    private TemplateNodeMapper nodes;
    private OperatorEntity operator;
    private WorkflowAuditContextResolverImpl resolver;
    @Before public void setup() throws Exception {
        operators = mock(OperatorUtil.class); tasks = mock(TaskMapper.class); nodes = mock(TemplateNodeMapper.class);
        resolver = new WorkflowAuditContextResolverImpl(operators, tasks, nodes);
        operator = new OperatorEntity(); operator.setId("operator-round-2"); operator.setTaskId("task");
        operator.setNodeId("node"); operator.setNodeCode("review"); operator.setNodeName("审核");
        when(operators.checkOperator("operator-round-2")).thenReturn(operator);
        TaskEntity task = new TaskEntity(); task.setFlowId("version"); when(tasks.getInfo("task")).thenReturn(task);
        TemplateNodeEntity node = new TemplateNodeEntity(); node.setNodeCode("review"); node.setFormId("form");
        when(nodes.getList("version")).thenReturn(List.of(node));
    }
    @Test public void freezesServerNodeAndExistingHandlingRoundBeforeCompletion() throws Exception {
        Map<String,String> result = resolver.resolve("task", "form", "operator-round-2");
        operator.setNodeName("下一环节");
        assertEquals("审核", result.get("nodeName"));
        assertEquals("operator-round-2", result.get("operatorId"));
        assertEquals("task", result.get("taskId"));
        verify(operators).checkOperatorPermission("operator-round-2");
    }
    @Test public void rejectsReferenceFromAnotherTask() throws Exception {
        try { resolver.resolve("other", "form", "operator-round-2"); fail(); }
        catch (WorkFlowException expected) { }
        verifyNoInteractions(tasks, nodes);
    }
    @Test public void rejectsAnotherFormOnTheSameTask() throws Exception {
        try { resolver.resolve("task", "other", "operator-round-2"); fail(); }
        catch (WorkFlowException expected) { }
    }
    @Test public void rejectsUnauthorizedHandlingReference() throws Exception {
        doThrow(new WorkFlowException("no permission")).when(operators).checkOperatorPermission("operator-round-2");
        try { resolver.resolve("task", "form", "operator-round-2"); fail(); }
        catch (WorkFlowException expected) { }
        verifyNoInteractions(tasks, nodes);
    }
    @Test public void rejectsCompletedOrInvalidHandlingReference() throws Exception {
        when(operators.checkOperator("operator-round-2")).thenThrow(new WorkFlowException("already completed"));
        try { resolver.resolve("task", "form", "operator-round-2"); fail(); }
        catch (WorkFlowException expected) { }
        verifyNoInteractions(tasks, nodes);
    }
}