刘光辉
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package jnpf.dmsController;
 
import jnpf.dmsService.DmsWenjianBianhaoGuizeFeiqiService;
import jnpf.dmsService.DmsWenjianBianhaoGuizeShengbanCheckService;
import jnpf.dmsService.DmsWenjianBianhaoGuizeTongguoService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
 
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
public class DmsWenjianBianhaoGuizeControllerTest {
 
    private MockMvc mockMvc;
    private DmsWenjianBianhaoGuizeFeiqiService feiqiService;
    private DmsWenjianBianhaoGuizeTongguoService tongguoService;
    private DmsWenjianBianhaoGuizeShengbanCheckService shengbanCheckService;
 
    @Before
    public void setUp() {
        DmsWenjianBianhaoGuizeController controller = new DmsWenjianBianhaoGuizeController();
        feiqiService = mock(DmsWenjianBianhaoGuizeFeiqiService.class);
        tongguoService = mock(DmsWenjianBianhaoGuizeTongguoService.class);
        shengbanCheckService = mock(DmsWenjianBianhaoGuizeShengbanCheckService.class);
        ReflectionTestUtils.setField(controller, "feiqiService", feiqiService);
        ReflectionTestUtils.setField(controller, "tongguoService", tongguoService);
        ReflectionTestUtils.setField(controller, "shengbanCheckService", shengbanCheckService);
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
    }
 
    @Test
    public void feiqiReadsFlowAndTaskIdsFromRequestBody() throws Exception {
        mockMvc.perform(post("/biz/wenjian/bianhao/guize/feiqi")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"flow_id\":\"flow-1\",\"task_id\":\"task-1\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("文件编号规则废弃成功"));
 
        verify(feiqiService).feiqiGuize("flow-1", "task-1");
    }
 
    @Test
    public void tongguoReadsFlowAndTaskIdsFromRequestBody() throws Exception {
        mockMvc.perform(post("/biz/wenjian/bianhao/guize/tongguo")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"flow_id\":\"flow-1\",\"task_id\":\"task-1\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("文件编号规则审核通过处理成功"));
 
        verify(tongguoService).tongguo("flow-1", "task-1");
    }
 
    @Test
    public void shengbanCheckReadsSerialNumberAndVersionFromRequestBody() throws Exception {
        mockMvc.perform(post("/biz/wenjian/bianhao/guize/shengban/check")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"f_id\":\"rule-1\",\"guize_liushuihao\":\"serial-1\",\"banbenhao\":\"V2\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("文件编号规则升版校验通过"));
 
        verify(shengbanCheckService).check("rule-1", "serial-1", "V2");
    }
}