|
@@ -1,10 +1,13 @@
|
|
package net.mooctest.www.android_auto_test.ctrl;
|
|
package net.mooctest.www.android_auto_test.ctrl;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import net.mooctest.www.android_auto_test.common.constant.enums.TraceStatus;
|
|
import net.mooctest.www.android_auto_test.common.constant.enums.TraceStatus;
|
|
import net.mooctest.www.android_auto_test.controller.AutoTestController;
|
|
import net.mooctest.www.android_auto_test.controller.AutoTestController;
|
|
import net.mooctest.www.android_auto_test.services.AutoTestService;
|
|
import net.mooctest.www.android_auto_test.services.AutoTestService;
|
|
|
|
+import net.mooctest.www.android_auto_test.vo.TraceMetaInfo;
|
|
import net.mooctest.www.android_auto_test.vo.TraceStatusResult;
|
|
import net.mooctest.www.android_auto_test.vo.TraceStatusResult;
|
|
|
|
+import org.apache.commons.lang.exception.NestableRuntimeException;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
@@ -17,6 +20,7 @@ import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.MvcResult;
|
|
import org.springframework.test.web.servlet.MvcResult;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
+import org.springframework.web.util.NestedServletException;
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
@@ -52,10 +56,13 @@ public class AutoTestControllerTest {
|
|
ts.setStatusCode(TraceStatus.INIT.getCode());
|
|
ts.setStatusCode(TraceStatus.INIT.getCode());
|
|
ts.setDescription(TraceStatus.INIT.getDescription());
|
|
ts.setDescription(TraceStatus.INIT.getDescription());
|
|
when(autoTestService.executeAutoTestTask(any())).thenReturn(ts);
|
|
when(autoTestService.executeAutoTestTask(any())).thenReturn(ts);
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
+ object.put("traceId", "123");
|
|
|
|
+ object.put("downloadUrl", "url");
|
|
// action
|
|
// action
|
|
MvcResult result = mockMvc.perform(post("/api/v1/runTest")
|
|
MvcResult result = mockMvc.perform(post("/api/v1/runTest")
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
- .content("{}"))
|
|
|
|
|
|
+ .content(object.toString()))
|
|
.andDo(print()).andExpect(status().isOk()).andReturn();
|
|
.andDo(print()).andExpect(status().isOk()).andReturn();
|
|
// assert
|
|
// assert
|
|
JSONObject re = new JSONObject(result.getResponse().getContentAsString());
|
|
JSONObject re = new JSONObject(result.getResponse().getContentAsString());
|
|
@@ -64,6 +71,26 @@ public class AutoTestControllerTest {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
|
+ public void testStartWithWrongParams() throws Exception{
|
|
|
|
+ // arrange
|
|
|
|
+ ts.setStatusCode(TraceStatus.INIT.getCode());
|
|
|
|
+ ts.setDescription(TraceStatus.INIT.getDescription());
|
|
|
|
+ when(autoTestService.executeAutoTestTask(any())).thenReturn(ts);
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
+ object.put("traceId", "123");
|
|
|
|
+ // action
|
|
|
|
+ try {
|
|
|
|
+ MvcResult result = mockMvc.perform(post("/api/v1/runTest")
|
|
|
|
+ .contentType(MediaType.APPLICATION_JSON)
|
|
|
|
+ .content(object.toString()))
|
|
|
|
+ .andDo(print()).andExpect(status().is5xxServerError()).andReturn();
|
|
|
|
+ }catch (NestedServletException e){
|
|
|
|
+ // assert
|
|
|
|
+ Assert.assertEquals("缺少参数:[downloadUrl]", e.getRootCause().getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
public void testGetStatus() throws Exception{
|
|
public void testGetStatus() throws Exception{
|
|
// arrange
|
|
// arrange
|
|
ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
@@ -81,6 +108,22 @@ public class AutoTestControllerTest {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
|
+ public void testGetStatusWithoutParams() throws Exception{
|
|
|
|
+ // arrange
|
|
|
|
+ ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
|
|
+ ts.setDescription(TraceStatus.FINISH.getDescription());
|
|
|
|
+ when(autoTestService.getResult(any())).thenReturn(ts);
|
|
|
|
+ // action
|
|
|
|
+ try {
|
|
|
|
+ MvcResult result = mockMvc.perform(get("/api/v1/result")
|
|
|
|
+ .contentType(MediaType.APPLICATION_JSON))
|
|
|
|
+ .andDo(print()).andExpect(status().is4xxClientError()).andReturn();
|
|
|
|
+ } catch (NestedServletException e){
|
|
|
|
+ // assert
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
public void testStop() throws Exception{
|
|
public void testStop() throws Exception{
|
|
// arrange
|
|
// arrange
|
|
ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
@@ -95,4 +138,20 @@ public class AutoTestControllerTest {
|
|
boolean re = Boolean.parseBoolean(result.getResponse().getContentAsString());
|
|
boolean re = Boolean.parseBoolean(result.getResponse().getContentAsString());
|
|
Assert.assertFalse(re);
|
|
Assert.assertFalse(re);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testStopWithoutParams() throws Exception{
|
|
|
|
+ // arrange
|
|
|
|
+ ts.setStatusCode(TraceStatus.FINISH.getCode());
|
|
|
|
+ ts.setDescription(TraceStatus.FINISH.getDescription());
|
|
|
|
+ when(autoTestService.getResult(any())).thenReturn(ts);
|
|
|
|
+ // action
|
|
|
|
+ try {
|
|
|
|
+ MvcResult result = mockMvc.perform(delete("/api/v1/result")
|
|
|
|
+ .contentType(MediaType.APPLICATION_JSON))
|
|
|
|
+ .andDo(print()).andExpect(status().is4xxClientError()).andReturn();
|
|
|
|
+ } catch (NestedServletException e){
|
|
|
|
+ // assert
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|