REM:
1. 添加停止全部处置任务接口的入参判断
1. 添加askController QA测试用例中止指定停止全部处置任务的正常用例和异常用例测试代码
This commit is contained in:
chenlinghy 2020-05-09 16:41:38 +08:00
parent 3923682245
commit 187a016364
2 changed files with 247 additions and 4 deletions

View File

@ -316,7 +316,6 @@ public class DisposeTaskController {
}
}
TaskInfoRsp rspInfo = new TaskInfoRsp();
reqInfo.getItems().forEach(v -> {
@ -374,12 +373,18 @@ public class DisposeTaskController {
}
StopTaskData reqInfo = mr.getRequestObject(StopTaskData.class);
if(reqInfo.getType() ==null || String.valueOf(reqInfo.getType()).length() == 0){
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION);
}
TaskInfoRsp rspInfo = new TaskInfoRsp();
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByType(reqInfo.getType());
if (ret.size() == 0) {
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
@ -387,6 +392,7 @@ public class DisposeTaskController {
rspInfo.getItems().add(taskData);
} else {
ret.forEach(k -> {
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));

View File

@ -637,7 +637,6 @@ public class TaskControllerQATest extends InitTestEnvironment {
/**
* d1 stop task by single node test.
*
*/
@Test
public void d1_NormalStopTaskByNodeTest() throws Exception {
@ -690,7 +689,6 @@ public class TaskControllerQATest extends InitTestEnvironment {
/**
* d2 stop task by two nodes test.
*
*/
@Test
public void d2_NormalStopTaskByNodesTest() throws Exception {
@ -853,6 +851,245 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e1 stop task all test.
*/
@Test
public void e1_NormalStopAllTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":0}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.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 taskStopByIpRsp = objectMapper.readValue(verifyResp(taskStopAll), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.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(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
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);
}
}
}
/**
* e2 stop task all test.
*/
@Test
public void e2_NormalStopAllTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":1}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.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 taskStopByIpRsp = objectMapper.readValue(verifyResp(taskStopAll), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.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(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
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);
}
}
}
/**
* e3 stop task all test.
*/
@Test
public void e3_NormalStopAllTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":-1}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.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 taskStopByIpRsp = objectMapper.readValue(verifyResp(taskStopAll), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.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(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
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);
}
}
}
/**
* e4 type empty exception test.
*
* @throws Exception the exception
*/
@Test
public void e4_stopTaskAllNoTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"472\\\",\\\"type\\\":}}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopAll), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e5 type null exception test.
*
* @throws Exception the exception
*/
@Test
public void e5_stopTaskAllNullTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"472\\\",\\\"type\\\":null}}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopAll), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e6 type String exception test.
*
* @throws Exception the exception
*/
@Test
public void e6_stopTaskAllStringTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"472\\\",\\\"type\\\":\\\"0\\\"}}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopAll), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
}