|
@@ -1,109 +0,0 @@
|
|
|
-package cn.iselab.mooctest.site.web.ctrl;
|
|
|
-
|
|
|
-import cn.iselab.mooctest.site.Application;
|
|
|
-import cn.iselab.mooctest.site.web.response.ResponseMessage;
|
|
|
-import cn.iselab.mooctest.site.web.response.SuccessResult;
|
|
|
-import cn.iselab.mooctest.site.web.data.TargetDevVO;
|
|
|
-import cn.iselab.mooctest.site.web.data.TargetKibugVO;
|
|
|
-import cn.iselab.mooctest.site.web.data.TargetVO;
|
|
|
-import cn.iselab.mooctest.site.web.logic.TargetLogic;
|
|
|
-import org.json.JSONArray;
|
|
|
-import org.json.JSONObject;
|
|
|
-import org.junit.Assert;
|
|
|
-import org.junit.Before;
|
|
|
-import org.junit.Test;
|
|
|
-import org.junit.runner.RunWith;
|
|
|
-import org.mockito.InjectMocks;
|
|
|
-import org.mockito.Mock;
|
|
|
-import org.mockito.runners.MockitoJUnitRunner;
|
|
|
-import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.test.context.web.WebAppConfiguration;
|
|
|
-import org.springframework.test.web.servlet.MockMvc;
|
|
|
-import org.springframework.test.web.servlet.MvcResult;
|
|
|
-import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static org.mockito.Matchers.*;
|
|
|
-import static org.mockito.MockitoAnnotations.initMocks;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by ROGK on 2017/6/26.
|
|
|
- */
|
|
|
-@RunWith(MockitoJUnitRunner.class)
|
|
|
-@WebAppConfiguration
|
|
|
-@SpringApplicationConfiguration(classes = Application.class)
|
|
|
-public class TargetControllerTest {
|
|
|
-
|
|
|
- private MockMvc mockMvc;
|
|
|
-
|
|
|
- @InjectMocks
|
|
|
- TargetController targetController=new TargetController();
|
|
|
-
|
|
|
- @Mock
|
|
|
- TargetLogic targetLogic;
|
|
|
-
|
|
|
- Pageable pageable;
|
|
|
- List<TargetVO> targets=new ArrayList<>();
|
|
|
- TargetVO targetVO=new TargetVO();
|
|
|
- TargetKibugVO targetKibugVO=new TargetKibugVO();
|
|
|
- SuccessResult expect=new SuccessResult();
|
|
|
- long expectId;
|
|
|
- @Before
|
|
|
- public void setupMockMvc() throws Exception {
|
|
|
- initMocks(this);
|
|
|
- mockMvc= MockMvcBuilders.standaloneSetup(targetController).build();
|
|
|
-
|
|
|
- targetVO.setVisible(false);
|
|
|
- targetVO.setId(1L);
|
|
|
- targetVO.setName("test");
|
|
|
- targetVO.setUrl("test");
|
|
|
- targetVO.setTargetType(1L);
|
|
|
- targetVO.setCreateTimeMillis(1497856288L);
|
|
|
- targetVO.setStatus(1);
|
|
|
- targetVO.setEndTimeMillis(1497856289L);
|
|
|
- targetVO.setFromCloud(1);
|
|
|
-
|
|
|
- targetKibugVO.setVisible(false);
|
|
|
- targetKibugVO.setId(1L);
|
|
|
- targetKibugVO.setName("test");
|
|
|
- targetKibugVO.setUrl("test");
|
|
|
- targetKibugVO.setTargetType(1L);
|
|
|
- targetKibugVO.setCreateTimeMillis(1497856288L);
|
|
|
- targetKibugVO.setStatus(1);
|
|
|
- targetKibugVO.setEndTimeMillis(1497856289L);
|
|
|
- targetKibugVO.setFromCloud(1);
|
|
|
- targetKibugVO.setAppLocation("test");
|
|
|
- targetKibugVO.setPlatform("Android");
|
|
|
- targetKibugVO.setKibugId(1L);
|
|
|
-
|
|
|
- expect.put(ResponseMessage.ITEM_RESULT,targetKibugVO);
|
|
|
-
|
|
|
- targets.add(targetVO);
|
|
|
- pageable=new PageRequest(0, 10);
|
|
|
- expectId=1;
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_TargetKibugVO_when_TargetKibugVOExists()throws Exception{
|
|
|
- when(targetLogic.getTarget(anyLong())).thenReturn(null);
|
|
|
-
|
|
|
- MvcResult result=mockMvc.perform(
|
|
|
- get("/api/target/kibug").param("targetId","1")
|
|
|
- ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
-
|
|
|
- JSONObject object=new JSONObject(result.getResponse().getContentAsString());
|
|
|
- Assert.assertEquals(targetKibugVO.getName(),object.getJSONObject("data").getString("name"));
|
|
|
- }
|
|
|
-}
|