REM:
1. 增加入参字段的判断
2. 无可停止的清洗任务时,修改taskId为-1
3. 编写启动指定处置任务正常用例和异常用例的冒烟测试代码
This commit is contained in:
chenlinghy 2020-05-09 09:30:49 +08:00
parent b436510cad
commit feaa46c55f
2 changed files with 148 additions and 22 deletions

View File

@ -104,19 +104,18 @@ public class DisposeTaskController {
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class); StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
if(reqInfo.getDisposeIp().length() == 0 || reqInfo.getDisposeIp().equals("null")){ if (reqInfo.getDisposeIp().length() == 0 || reqInfo.getDisposeIp().equals("null")) {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION);
} }
if(reqInfo.getId() == null || reqInfo.getType() == null || String.valueOf(reqInfo.getType()).length() == 0){ if (reqInfo.getId() == null || reqInfo.getType() == null || String.valueOf(reqInfo.getType()).length() == 0) {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION);
} }
if(reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() < 0 || String.valueOf(reqInfo.getDisposeTime()).length() == 0) { if (reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() < 0 || String.valueOf(reqInfo.getDisposeTime()).length() == 0) {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION);
} }
StartTaskRsp rspInfo = new StartTaskRsp(); StartTaskRsp rspInfo = new StartTaskRsp();
TaskInfoDetail task = TaskInfoDetail.builder() TaskInfoDetail task = TaskInfoDetail.builder()
@ -168,25 +167,20 @@ public class DisposeTaskController {
} }
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
TaskInfoRsp rspInfo = new TaskInfoRsp();
if (reqInfo.getTaskId() == null if (reqInfo.getTaskId() == null || reqInfo.getTaskId().length == 0) {
|| reqInfo.getTaskId().length == 0) { return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION);
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
} }
TaskInfoRsp rspInfo = new TaskInfoRsp();
Arrays.stream(reqInfo.getTaskId()).forEach(v -> { Arrays.stream(reqInfo.getTaskId()).forEach(v -> {
TaskInfoData taskData = TaskInfoData.builder().type(DeviceCapacity.CLEANUP.getCode()).build(); TaskInfoData taskData = TaskInfoData.builder().type(DeviceCapacity.CLEANUP.getCode()).build();
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v)); List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v));
if (ret.size() == 0) { if (ret.size() == 0) {
TaskInfoDetail taskDetail = disposeTaskMapper.getTaskInfoById(Long.valueOf(v)); taskData.setId("-1");
if (taskDetail != null) {
taskData.setId(String.valueOf(taskDetail.getDeviceId()));
} else {
taskData.setId("-1");
}
taskData.setTaskId(v); taskData.setTaskId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());

View File

@ -2,7 +2,9 @@ package com.dispose.controller;
import com.dispose.Global.InitTestEnvironment; import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.task.StartTaskRsp; import com.dispose.pojo.vo.task.StartTaskRsp;
import com.dispose.pojo.vo.task.TaskInfoRsp;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
@ -19,6 +21,8 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -69,16 +73,14 @@ public class TaskControllerExceptionSmokeTest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp.getStatus()); Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage()); Assert.assertNotNull(startTaskRsp.getMessage());
if(startTaskRsp.getStatus() == 0){ if (startTaskRsp.getStatus() == 0) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
}else if(startTaskRsp.getStatus() == 26){ } else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
} }
} }
@Test @Test
public void t2_NormalContainsNonEmptyTaskTest() throws Exception { public void t2_NormalContainsNonEmptyTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
@ -106,9 +108,9 @@ public class TaskControllerExceptionSmokeTest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp.getStatus()); Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage()); Assert.assertNotNull(startTaskRsp.getMessage());
if(startTaskRsp.getStatus() == 0){ if (startTaskRsp.getStatus() == 0) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
}else if(startTaskRsp.getStatus() == 26){ } else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
} }
} }
@ -116,7 +118,7 @@ public class TaskControllerExceptionSmokeTest extends InitTestEnvironment {
@Test @Test
public void t3_startTaskNoDisPoseIpExceptionTest() throws Exception { public void t3_startTaskNoDisPoseIpExceptionTest() throws Exception {
String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":, \\\"disposeTime\\\":120}\"}";
String taskStart = mockMvc.perform(MockMvcRequestBuilders String taskStart = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
@ -142,7 +144,7 @@ public class TaskControllerExceptionSmokeTest extends InitTestEnvironment {
public void t4_startTaskNullDisposeIpExceptionTest() throws Exception { public void t4_startTaskNullDisposeIpExceptionTest() throws Exception {
//disposeIp null //disposeIp null
String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"null\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}";
String taskStart = mockMvc.perform(MockMvcRequestBuilders String taskStart = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
@ -343,4 +345,134 @@ public class TaskControllerExceptionSmokeTest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp.getMessage()); Assert.assertNotNull(startTaskRsp.getMessage());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
} }
@Test
public void t12_NormalStopTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":[\\\"236\\\", \\\"235\\\" ]}\"}";
String taskStop = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z";
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStop), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
} else if (task.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
}
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
}
@Test
public void t13_NormalStopNoTaskIdTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":}\"}";
String taskStop = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStop), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
}
@Test
public void t14_NormalStopNullTaskIdTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":null}\"}";
String taskStop = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStop), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
}
@Test
public void t15_NormalIntegerTaskIdTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":[445, 235]}\"}";
String taskStop = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStop), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
//Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
}
} }