From 187a0163647bbd60c0fbfcdfc3a1a5568bc713e9 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Sat, 9 May 2020 16:41:38 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=85=A8=E9=83=A8=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=85=A5=E5=8F=82=E5=88=A4=E6=96=AD?= =?UTF-8?q?=201.=20=E6=B7=BB=E5=8A=A0askController=20QA=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=B8=AD=E6=AD=A2=E6=8C=87=E5=AE=9A=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=85=A8=E9=83=A8=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E5=B8=B8=E7=94=A8=E4=BE=8B=E5=92=8C=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=94=A8=E4=BE=8B=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisposeTaskController.java | 10 +- .../controller/TaskControllerQATest.java | 241 +++++++++++++++++- 2 files changed, 247 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index 45cb0f2f..4c069d78 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -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> 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())); diff --git a/src/test/java/com/dispose/controller/TaskControllerQATest.java b/src/test/java/com/dispose/controller/TaskControllerQATest.java index db709545..f44ab448 100644 --- a/src/test/java/com/dispose/controller/TaskControllerQATest.java +++ b/src/test/java/com/dispose/controller/TaskControllerQATest.java @@ -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 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 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 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())); + } }