刘光辉
12 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package jnpf.dmsController;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import jnpf.dmsEntity.wenjianbianhao.DmsFlowEventType;
import jnpf.dmsEntity.wenjianbianhao.form.DmsFlowEventForm;
import jnpf.dmsEntity.wenjianbianhao.vo.DmsWenjianBianhaoRuleVO;
import jnpf.dmsService.DmsWenjianBianhaoApplicationService;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import org.junit.jupiter.api.Test;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class DmsWenjianBianhaoControllerTest {
 
    private final DmsWenjianBianhaoApplicationService service =
            mock(DmsWenjianBianhaoApplicationService.class);
    private final WorkFlowApi workFlowApi = mock(WorkFlowApi.class);
    private final DmsWenjianBianhaoController controller =
            new DmsWenjianBianhaoController(service, workFlowApi);
 
    @Test
    void startEventReadsWorkflowStateBeforeCallingBusinessService() throws DataException {
        DmsFlowEventForm form = form("flow-1", "task-1", DmsFlowEventType.START);
        TaskEntity task = new TaskEntity();
        task.setId("task-1");
        task.setStatus(1);
        when(workFlowApi.getInfoSubmit("task-1")).thenReturn(task);
 
        controller.syncApplicationFlowEvent(form);
 
        verify(service).syncApplicationFlow(
                "flow-1", "task-1", 1, DmsFlowEventType.START);
    }
 
    @Test
    void rejectsMissingWorkflowTask() {
        DmsFlowEventForm form = form("flow-1", "task-1", DmsFlowEventType.END);
        when(workFlowApi.getInfoSubmit("task-1")).thenReturn(null);
 
        assertThrows(DataException.class, () -> controller.syncApplicationFlowEvent(form));
    }
 
    @Test
    void acceptsJnpfSnakeCaseEventParameters() throws Exception {
        DmsFlowEventForm form = new ObjectMapper().readValue(
                "{\"flow_id\":\"flow-1\",\"task_id\":\"task-1\",\"event_type\":\"recall\"}",
                DmsFlowEventForm.class);
 
        assertEquals("flow-1", form.getFlowId());
        assertEquals("task-1", form.getTaskId());
        assertEquals(DmsFlowEventType.RECALL, form.getEventType());
    }
 
    @Test
    void ruleOptionUsesJnpfInterfaceFieldNames() throws Exception {
        DmsWenjianBianhaoRuleVO rule = new DmsWenjianBianhaoRuleVO();
        rule.setId("rule-1");
        rule.setGuizeMingcheng("QC-SOP规则");
        rule.setYulanBianhao("QC-SOP-待审");
        rule.setGuizeXianshi("QC-SOP规则 / QC-SOP-待审");
 
        String json = new ObjectMapper().writeValueAsString(rule);
 
        org.junit.jupiter.api.Assertions.assertTrue(json.contains("\"f_id\":\"rule-1\""));
        org.junit.jupiter.api.Assertions.assertTrue(
                json.contains("\"yulan_bianhao\":\"QC-SOP-待审\""));
        org.junit.jupiter.api.Assertions.assertTrue(json.contains("\"guize_xianshi\""));
    }
 
    @Test
    void nameChangeUsesItsIndependentBusinessService() throws DataException {
        DmsFlowEventForm form = form("flow-2", "task-2", DmsFlowEventType.END);
        TaskEntity task = new TaskEntity();
        task.setId("task-2");
        task.setStatus(2);
        when(workFlowApi.getInfoSubmit("task-2")).thenReturn(task);
 
        controller.syncNameChangeFlowEvent(form);
 
        verify(service).syncNameChangeFlow(
                "flow-2", "task-2", 2, DmsFlowEventType.END);
    }
 
    private DmsFlowEventForm form(String flowId, String taskId,
                                  DmsFlowEventType eventType) {
        DmsFlowEventForm form = new DmsFlowEventForm();
        form.setFlowId(flowId);
        form.setTaskId(taskId);
        form.setEventType(eventType);
        return form;
    }
}