|
|
@@ -0,0 +1,171 @@
|
|
|
+package cn.iselab.mooctest.site.web.ctrl.fromDev;
|
|
|
+
|
|
|
+import cn.iselab.mooctest.site.Application;
|
|
|
+import cn.iselab.mooctest.site.models.Weight;
|
|
|
+import cn.iselab.mooctest.site.web.data.fromDev.DevTaskVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.fromDev.ResponseVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.fromDev.StResponse;
|
|
|
+import cn.iselab.mooctest.site.web.logic.TaskLogic;
|
|
|
+import cn.iselab.mooctest.site.web.logic.fromDev.IndexLogic;
|
|
|
+import net.sf.json.JSON;
|
|
|
+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.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.junit.Assert.*;
|
|
|
+
|
|
|
+import static org.mockito.Matchers.*;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+import static org.mockito.MockitoAnnotations.initMocks;
|
|
|
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ROGK on 2017/6/29.
|
|
|
+ */
|
|
|
+@WebAppConfiguration
|
|
|
+@SpringApplicationConfiguration(classes = Application.class)
|
|
|
+@RunWith(MockitoJUnitRunner.class)
|
|
|
+public class IndexControllerTest {
|
|
|
+
|
|
|
+ private MockMvc mockMvc;
|
|
|
+
|
|
|
+ @InjectMocks
|
|
|
+ IndexController indexController=new IndexController();
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ IndexLogic indexLogic;
|
|
|
+ @Mock
|
|
|
+ TaskLogic taskLogic;
|
|
|
+
|
|
|
+ ResponseVO expect;
|
|
|
+ DevTaskVO devTaskVO=new DevTaskVO();
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void setupMockMvc() throws Exception {
|
|
|
+ initMocks(this);
|
|
|
+ mockMvc= MockMvcBuilders.standaloneSetup(indexController).build();
|
|
|
+
|
|
|
+// expect.setStatus("test");
|
|
|
+// expect.setMessage("test");
|
|
|
+//
|
|
|
+// devTaskVO.setBeginTime("test");
|
|
|
+// devTaskVO.setBeginTimeMillis(1);
|
|
|
+// devTaskVO.setDuration(1);
|
|
|
+// devTaskVO.setEndTime("test");
|
|
|
+// devTaskVO.setEndTimeMillis(1);
|
|
|
+// devTaskVO.setGroups(new ArrayList<String>());
|
|
|
+// devTaskVO.setManagerName("test");
|
|
|
+// devTaskVO.setInformation("test");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_DevTaskVO_when_DevTaskVOExists() throws Exception{
|
|
|
+ expect=new ResponseVO(devTaskVO);
|
|
|
+
|
|
|
+ when(indexLogic.getTaskInfo(anyLong(),anyLong())).thenReturn(expect);
|
|
|
+
|
|
|
+ MvcResult result=mockMvc.perform(
|
|
|
+ get("/api/dev/taskInfo")
|
|
|
+ .param("taskID","306")
|
|
|
+ .param("stuID","1")
|
|
|
+ ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
+
|
|
|
+ Assert.assertEquals("{\"status\":null,\"message\":null,\"data\":{\"information\":null,\"duration\":0,\"managerName\":null" +
|
|
|
+ ",\"name\":null,\"beginTime\":null,\"endTime\":null,\"beginTimeMillis\":0,\"endTimeMillis\":0,\"groups\":null}}",result.getResponse().getContentAsString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_Weight_when_WeightExists()throws Exception{
|
|
|
+ Weight expect=new Weight();
|
|
|
+ expect.setId(1);
|
|
|
+ expect.setCid(1);
|
|
|
+ expect.setTid(1);
|
|
|
+ expect.setAd(0.5);
|
|
|
+ expect.setAdu(0.5);
|
|
|
+ expect.setApfd(0.5);
|
|
|
+ expect.setAu(0.5);
|
|
|
+ expect.setBc(0.5);
|
|
|
+ expect.setCovercom(1);
|
|
|
+ expect.setMc_dc(0.5);
|
|
|
+ expect.setMutation(0.5);
|
|
|
+ expect.setMutationcom(1);
|
|
|
+ expect.setPpc(0.5);
|
|
|
+ expect.setSc(0.5);
|
|
|
+ when(indexLogic.getWeight(anyLong(),anyLong())).thenReturn(expect);
|
|
|
+
|
|
|
+ MvcResult result=mockMvc.perform(
|
|
|
+ get("/api/dev/weight")
|
|
|
+ .param("cid","11")
|
|
|
+ .param("tid","303")
|
|
|
+ ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject jsonObject=new JSONObject(result.getResponse().getContentAsString());
|
|
|
+ Assert.assertEquals(expect.getId(),jsonObject.getLong("id"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_TaskSecret_when_TaskSecretExists() throws Exception{
|
|
|
+ String secret="test";
|
|
|
+ expect=new ResponseVO(secret);
|
|
|
+
|
|
|
+ when(indexLogic.getTaskSecret(anyString(),anyString())).thenReturn(expect);
|
|
|
+
|
|
|
+ MvcResult result=mockMvc.perform(
|
|
|
+ get("/api/dev/taskSecret")
|
|
|
+ .param("stuID","1")
|
|
|
+ .param("taskID","1")
|
|
|
+ ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
+
|
|
|
+ JSONObject jsonObject=new JSONObject(result.getResponse().getContentAsString());
|
|
|
+
|
|
|
+ Assert.assertEquals(expect.getData(),jsonObject.getString("data"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_SourceUrl_when_SourceUrlExists()throws Exception{
|
|
|
+ String url="test";
|
|
|
+ String expect= StResponse.success(url);
|
|
|
+ when(taskLogic.getSourceUrl(anyLong(),anyLong(),anyLong())).thenReturn(url);
|
|
|
+
|
|
|
+ MvcResult result=mockMvc.perform(
|
|
|
+ get("/api/dev/source")
|
|
|
+ .param("taskID","1")
|
|
|
+ .param("stuID","1")
|
|
|
+ .param("caseID","1")
|
|
|
+ ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
+
|
|
|
+ Assert.assertEquals(expect,result.getResponse().getContentAsString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_UserNameList_when_UserNameListExists() throws Exception{
|
|
|
+ List<String> expect=new ArrayList<>();
|
|
|
+ expect.add("test");
|
|
|
+
|
|
|
+ when(indexLogic.getUserNameList(anyString())).thenReturn(expect);
|
|
|
+
|
|
|
+ MvcResult result=mockMvc.perform(
|
|
|
+ get("/api/dev/username").param("workerIds","test")
|
|
|
+ ).andDo(print()).andExpect(status().isOk()).andReturn();
|
|
|
+
|
|
|
+ Assert.assertEquals("[\"test\"]",result.getResponse().getContentAsString());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|