刘光辉
15 小时以前 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
package jnpf.dmsController;
 
import jnpf.dmsService.DmsDanganCundangJieshouService;
import jnpf.dmsEntity.DmsDanganCundangShenqingDanganheEntity;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
 
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
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 DmsDanganCundangJieshouControllerTest {
 
    private MockMvc mockMvc;
    private DmsDanganCundangJieshouService jieshouService;
 
    @Before
    public void setUp() {
        jieshouService = mock(DmsDanganCundangJieshouService.class);
        DmsDanganCundangJieshouController controller = new DmsDanganCundangJieshouController(jieshouService);
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
    }
 
    @Test
    public void jieshouPassesSnakeCaseRequestFieldsToService() throws Exception {
        mockMvc.perform(post("/biz/dangan/cundang/jieshou")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"danganhe_xinxi\":[{\"id\":\"box-1\",\"f_id\":\"box-1\"}],"
                                + "\"biz_review_user\":\"reviewer-1\",\"biz_user_id\":\"receiver-1\","
                                + "\"biz_sign\":\"sign-1\",\"biz_review_sign\":\"review-sign-1\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("档案存档接收成功"));
 
        ArgumentCaptor<jnpf.dmsEntity.form.DmsDanganCundangJieshouForm> captor = ArgumentCaptor.forClass(
                jnpf.dmsEntity.form.DmsDanganCundangJieshouForm.class);
        verify(jieshouService).jieshou(captor.capture());
        assertEquals("receiver-1", captor.getValue().getBizUserId());
        assertEquals("reviewer-1", captor.getValue().getBizReviewUser());
        assertEquals("box-1", captor.getValue().getDanganheXinxi().get(0).getFId());
    }
 
    @Test
    public void checkPassesDanganheBianhaoToService() throws Exception {
        DmsDanganCundangShenqingDanganheEntity danganhe = new DmsDanganCundangShenqingDanganheEntity();
        danganhe.setId("box-1");
        danganhe.setDanganheBianhao("DAH-001");
        when(jieshouService.check("box-1")).thenReturn(danganhe);
 
        mockMvc.perform(post("/biz/dangan/cundang/jieshou/check")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"danganhe_bianhao\":\"box-1\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("档案盒可接收"))
                .andExpect(jsonPath("$.data.f_id").value("box-1"))
                .andExpect(jsonPath("$.data.danganhe_bianhao").value("DAH-001"));
 
        verify(jieshouService).check("box-1");
    }
}