刘光辉
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
80
package jnpf.dmsController;
 
import jnpf.dmsEntity.form.DmsDanganJieyueFuyinGuihuanForm;
import jnpf.dmsEntity.vo.DmsDanganJieyueFuyinGuihuanCheckVO;
import jnpf.dmsService.DmsDanganJieyueFuyinGuihuanService;
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 DmsDanganJieyueFuyinGuihuanControllerTest {
 
    private MockMvc mockMvc;
    private DmsDanganJieyueFuyinGuihuanService guihuanService;
 
    @Before
    public void setUp() {
        guihuanService = mock(DmsDanganJieyueFuyinGuihuanService.class);
        mockMvc = MockMvcBuilders.standaloneSetup(new DmsDanganJieyueFuyinGuihuanController(guihuanService)).build();
    }
 
    @Test
    public void guihuanAcceptsTheRequestedDataArrayFormat() throws Exception {
        mockMvc.perform(post("/biz/dangan/jieyue/fuyin/guihuan")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"data\":[{\"f_id\":\"detail-1\",\"id\":\"detail-1\"}]}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.msg").value("档案借阅复印归还成功"));
 
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
        verify(guihuanService).guihuan(captor.capture());
        DmsDanganJieyueFuyinGuihuanForm form = (DmsDanganJieyueFuyinGuihuanForm) captor.getValue().get(0);
        assertEquals("detail-1", form.getFId());
        assertEquals("detail-1", form.getId());
    }
 
    @Test
    public void checkPassesTheBoxNumberAndReturnsTheAvailableDetail() throws Exception {
        DmsDanganJieyueFuyinGuihuanCheckVO detail = new DmsDanganJieyueFuyinGuihuanCheckVO();
        detail.setId("detail-1");
        detail.setDanganheId("box-1");
        detail.setDanganheBianhao("DAH-001");
        detail.setDanganheMingcheng("档案盒一");
        detail.setShenqingRen("applicant-1");
        detail.setShenqingBumen("department-1");
        detail.setJieshouRen("receiver-1");
        detail.setJieshouBumen("receiving-department-1");
        when(guihuanService.check("DAH-001")).thenReturn(detail);
 
        mockMvc.perform(post("/biz/dangan/jieyue/fuyin/guihuan/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"))
                .andExpect(jsonPath("$.data.jieshou_ren").value("receiver-1"))
                .andExpect(jsonPath("$.data.jieshou_bumen").value("receiving-department-1"));
 
        verify(guihuanService).check("DAH-001");
    }
}