刘光辉
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
74
75
76
77
78
79
package jnpf.dmsController;
 
import jnpf.dmsEntity.form.DmsDanganJieyueFuyinJieshouForm;
import jnpf.dmsEntity.vo.DmsDanganJieyueFuyinJieshouCheckVO;
import jnpf.dmsService.DmsDanganJieyueFuyinJieshouService;
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 java.util.List;
 
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 DmsDanganJieyueFuyinJieshouControllerTest {
 
    private MockMvc mockMvc;
    private DmsDanganJieyueFuyinJieshouService jieshouService;
 
    @Before
    public void setUp() {
        jieshouService = mock(DmsDanganJieyueFuyinJieshouService.class);
        mockMvc = MockMvcBuilders.standaloneSetup(new DmsDanganJieyueFuyinJieshouController(jieshouService)).build();
    }
 
    @Test
    public void jieshouAcceptsTheRequestedDataArrayFormat() throws Exception {
        mockMvc.perform(post("/biz/dangan/jieyue/fuyin/jieshou")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"data\":[{\"f_id\":\"detail-1\",\"id\":\"detail-1\","
                                + "\"jieshou_ren\":\"receiver-1\",\"jieshou_bumen\":\"org-1\"}]}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("档案借阅复印接收成功"));
 
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
        verify(jieshouService).jieshou(captor.capture());
        DmsDanganJieyueFuyinJieshouForm form = (DmsDanganJieyueFuyinJieshouForm) captor.getValue().get(0);
        assertEquals("detail-1", form.getFId());
        assertEquals("detail-1", form.getId());
        assertEquals("receiver-1", form.getJieshouRen());
        assertEquals("org-1", form.getJieshouBumen());
    }
 
    @Test
    public void checkPassesTheBoxNumberAndReturnsTheAvailableDetail() throws Exception {
        DmsDanganJieyueFuyinJieshouCheckVO detail = new DmsDanganJieyueFuyinJieshouCheckVO();
        detail.setId("detail-1");
        detail.setDanganheId("box-1");
        detail.setDanganheBianhao("DAH-001");
        detail.setDanganheMingcheng("档案盒一");
        detail.setShenqingRen("applicant-1");
        detail.setShenqingBumen("department-1");
        when(jieshouService.check("DAH-001")).thenReturn(detail);
 
        mockMvc.perform(post("/biz/dangan/jieyue/fuyin/jieshou/check")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"danganhe_bianhao\":\"DAH-001\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("档案借阅复印子项可接收"))
                .andExpect(jsonPath("$.data.f_id").value("detail-1"))
                .andExpect(jsonPath("$.data.danganhe_id").value("box-1"))
                .andExpect(jsonPath("$.data.danganhe_bianhao").value("DAH-001"))
                .andExpect(jsonPath("$.data.danganhe_mingcheng").value("档案盒一"))
                .andExpect(jsonPath("$.data.shenqing_ren").value("applicant-1"))
                .andExpect(jsonPath("$.data.shenqing_bumen").value("department-1"));
 
        verify(jieshouService).check("DAH-001");
    }
}