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");
|
}
|
}
|