From b4d22a57639fdbd4bb2def93cdf3a6aa0094531c Mon Sep 17 00:00:00 2001 From: lijinxing Date: Sat, 9 May 2020 14:48:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?OCT=20REM:=20=E4=BF=AE=E6=94=B9=E8=83=BD?= =?UTF-8?q?=E5=8A=9B=E8=8A=82=E7=82=B9=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=86=92=E7=83=9F=E6=B5=8B=E8=AF=95=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...mokeTest.java => DeviceNodeManagerControlllerSmokeTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/dispose/controller/{DeviceNodeManagerControlllerExceptionSmokeTest.java => DeviceNodeManagerControlllerSmokeTest.java} (98%) diff --git a/src/test/java/com/dispose/controller/DeviceNodeManagerControlllerExceptionSmokeTest.java b/src/test/java/com/dispose/controller/DeviceNodeManagerControlllerSmokeTest.java similarity index 98% rename from src/test/java/com/dispose/controller/DeviceNodeManagerControlllerExceptionSmokeTest.java rename to src/test/java/com/dispose/controller/DeviceNodeManagerControlllerSmokeTest.java index 93723a55..37598dad 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeManagerControlllerExceptionSmokeTest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeManagerControlllerSmokeTest.java @@ -43,7 +43,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @Slf4j -public class DeviceNodeManagerControlllerExceptionSmokeTest extends InitTestEnvironment { +public class DeviceNodeManagerControlllerSmokeTest extends InitTestEnvironment { /** * The Mock mvc. */ From f2a1788eae28916c3736fa961f28bfd5779743ee Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Sat, 9 May 2020 15:16:37 +0800 Subject: [PATCH 2/5] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0askCont?= =?UTF-8?q?roller=20QA=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=202.=20=E6=B7=BB=E5=8A=A0askController=20QA=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E4=B8=AD=E5=81=9C=E6=AD=A2=E6=9F=90?= =?UTF-8?q?=E5=A4=84=E7=BD=AEIP=E7=9A=84=E5=A4=84=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=BC=82=E5=B8=B8=E7=94=A8=E4=BE=8B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81=203.=20=E4=BF=AE=E6=94=B9askControl?= =?UTF-8?q?ler=E5=86=92=E7=83=9F=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=B8=AD=E7=8A=B6=E6=80=81=E7=A0=81=E7=9A=84=E5=88=A4=E6=96=AD?= =?UTF-8?q?=204.=20=E6=B7=BB=E5=8A=A0=E5=81=9C=E6=AD=A2=E6=9F=90IP?= =?UTF-8?q?=E5=A4=84=E7=BD=AEIP=E7=9A=84=E5=A4=84=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3=E4=B8=AD=E5=85=A5=E5=8F=82=E5=88=A4?= =?UTF-8?q?=E6=96=AD=205.=20=E4=BF=AE=E6=94=B9StopTask=E7=B1=BB=E4=B8=ADty?= =?UTF-8?q?pe=E5=AD=97=E6=AE=B5=E7=9A=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisposeTaskController.java | 22 ++ .../dispose/pojo/vo/task/StopTaskData.java | 2 +- .../controller/TaskControllerQATest.java | 270 +++++++++++++++++- 3 files changed, 280 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index 829fd7b6..ab11a04e 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -221,6 +221,7 @@ public class DisposeTaskController { public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr, @RequestHeader HttpHeaders headers) throws JsonProcessingException { + 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"; ErrorCode err = mr.verifyRequest(headers); if (err != ErrorCode.ERR_OK) { @@ -228,6 +229,24 @@ public class DisposeTaskController { } StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class); + List item = reqInfo.getItems(); + for (StopTaskData stopTaskData : item + ) { + if (stopTaskData.getId() == null || stopTaskData.getId().length() == 0) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } + + if (stopTaskData.getDisposeIp() == null || stopTaskData.getDisposeIp().length() == 0) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } else if (!stopTaskData.getDisposeIp().matches(regex)) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } + + if (String.valueOf(stopTaskData.getType()).length() == 0 || stopTaskData.getType() == null) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } + } + TaskInfoRsp rspInfo = new TaskInfoRsp(); reqInfo.getItems().forEach(v -> { @@ -512,7 +531,10 @@ public class DisposeTaskController { unExists.forEach(v -> { TaskInfoData taskData = new TaskInfoData(); rspInfo.getItems().add(taskData); + taskData.setTaskId("-1"); taskData.setId(v); + taskData.setStartTime(0); + taskData.setDisposeTime(0); taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); }); diff --git a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java b/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java index 5bb47e26..7f7f0475 100644 --- a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java +++ b/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java @@ -24,7 +24,7 @@ public class StopTaskData { /** * The Type. */ - private int type; + private Integer type; /** * The Dispose ip. */ diff --git a/src/test/java/com/dispose/controller/TaskControllerQATest.java b/src/test/java/com/dispose/controller/TaskControllerQATest.java index c4f66803..cc17fff5 100644 --- a/src/test/java/com/dispose/controller/TaskControllerQATest.java +++ b/src/test/java/com/dispose/controller/TaskControllerQATest.java @@ -80,10 +80,15 @@ public class TaskControllerQATest extends InitTestEnvironment { } } + /** + * t2 disposeIp empty exception test. + * + * @throws Exception the exception + */ @Test public void t2_startTaskNoDisPoseIpExceptionTest() throws Exception { 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 .post("/task/start") @@ -103,7 +108,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } - + /** + * t3 disposeIp null exception test. + * + * @throws Exception the exception + */ @Test public void t3_startTaskNullDisposeIpExceptionTest() throws Exception { //disposeIp null @@ -128,7 +137,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } - + /** + * t4 disposeIp Integer empty exception test. + * + * @throws Exception the exception + */ @Test public void t4_startTaskIntegerDisposeIpExceptionTest() throws Exception { String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + @@ -156,12 +169,15 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertNotNull(startTaskRsp.getStatus()); Assert.assertNotNull(startTaskRsp.getMessage()); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); -} - + } + /** + * t5 id null exception test. + * + * @throws Exception the exception + */ @Test public void t5_startTaskNullIdExceptionTest() throws Exception { - //Id null String reqDataNullId = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":null," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; @@ -183,9 +199,13 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + /** + * t6 type empty exception test. + * + * @throws Exception the exception + */ @Test public void t6_startTaskNoTypeExceptionTest() throws Exception { - //no type String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; @@ -207,7 +227,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } - + /** + * t7 type null exception test. + * + * @throws Exception the exception + */ @Test public void t7_startTaskNullTypeExceptionTest() throws Exception { //null type String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + @@ -231,6 +255,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + /** + * t8 disposeTime empty exception test. + * + * @throws Exception the exception + */ @Test public void t8_startTaskNoDisposeTimeExceptionTest() throws Exception { //no disposeTime @@ -255,7 +284,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } - + /** + * t9 disposeTime null exception test. + * + * @throws Exception the exception + */ @Test public void t9_startTaskNullDisposeTimeExceptionTest() throws Exception { //null disposeTime @@ -280,6 +313,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + /** + * t10 disposeTime String exception test. + * + * @throws Exception the exception + */ @Test public void t10_startTaskStringDisposeTimeExceptionTest() throws Exception { //string disposeTime @@ -304,11 +342,15 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } - + /** + * t11 taskId empty exception test. + * + * @throws Exception the exception + */ @Test public void t11_stopTaskNoTaskIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":}\"}"; + "\"msgContent\":\"{\\\"taskId\\\":\\\"\\\"}\"}"; String taskStop = mockMvc.perform(MockMvcRequestBuilders .post("/task/stop") @@ -328,6 +370,11 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + /** + * t12 taskId null exception test. + * + * @throws Exception the exception + */ @Test public void t12_stopTaskNullTaskIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + @@ -362,10 +409,13 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } } - } - + /** + * t13 id null exception test. + * + * @throws Exception the exception + */ @Test public void t13_stopTaskByIpNullIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + @@ -389,5 +439,199 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + /** + * t14 id empty exception test. + * + * @throws Exception the exception + */ + @Test + public void t14_stopTaskByIpNoIdExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; + String taskStopByIpNollId = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpNollId), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t15 disposeIp empty exception test. + * + * @throws Exception the exception + */ + @Test + public void t15_stopTaskByIpNoDisposeIpExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"\\\"}]}\"}"; + + String taskStopByIpNoDisposeIp = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpNoDisposeIp), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t16 disposeIp null exception test. + * + * @throws Exception the exception + */ + @Test + public void t16_stopTaskByIpNullDisposeIpExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":null}]}\"}"; + + String taskStopByIpNullDisposeIp = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpNullDisposeIp), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t17 disposeIp "abc" exception test. + * + * @throws Exception the exception + */ + @Test + public void t17_stopTaskByIpErrorDisposeIpExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"abc\\\"}]}\"}"; + + String taskStopByIpErrorDisposeIp = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpErrorDisposeIp), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t18 disposeIp Integer exception test. + * + * @throws Exception the exception + */ + @Test + public void t18_stopTaskByIpIntegerDisposeIpExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":123}]}\"}"; + + String taskStopByIpIntegerDisposeIp = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpIntegerDisposeIp), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t19 type empty exception test. + * + * @throws Exception the exception + */ + @Test + public void t19_stopTaskByIpNoTypeExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; + + String taskStopByIpNoType = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpNoType), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * t20 type null exception test. + * + * @throws Exception the exception + */ + @Test + public void t20_stopTaskByIpNullTypeExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":null,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; + + String taskStopByIpNullType = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .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(taskStopByIpNullType), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } } From e98d71bd2c0f4f7a6fa9ec37cb9918a7ed9ffea3 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Sat, 9 May 2020 15:17:56 +0800 Subject: [PATCH 3/5] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0askCont?= =?UTF-8?q?roller=20QA=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=B8=AD?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E6=9F=90=E5=A4=84=E7=BD=AEIP=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=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 --- .../com/dispose/controller/TaskControllerSmokeTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/dispose/controller/TaskControllerSmokeTest.java b/src/test/java/com/dispose/controller/TaskControllerSmokeTest.java index dfdec119..d187ba24 100644 --- a/src/test/java/com/dispose/controller/TaskControllerSmokeTest.java +++ b/src/test/java/com/dispose/controller/TaskControllerSmokeTest.java @@ -195,7 +195,7 @@ public class TaskControllerSmokeTest extends InitTestEnvironment { List taskInfoList = startTaskRsp.getItems(); for (TaskInfoData task : taskInfoList ) { - Assert.assertNotNull(task.getTaskId()); + Assert.assertNotNull(task.getId()); Assert.assertNotNull(task.getTaskId()); Assert.assertNotNull(task.getStartTime()); Assert.assertNotNull(task.getDisposeTime()); @@ -204,8 +204,8 @@ public class TaskControllerSmokeTest extends InitTestEnvironment { 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())); + } else if (task.getStatus() == 19) { + Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); } } } From 2d646afbe4af2e55d24e05ba92ccc5d371a909d2 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Sat, 9 May 2020 15:49:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E6=8C=87=E5=AE=9A=E8=83=BD=E5=8A=9B=E8=8A=82?= =?UTF-8?q?=E7=82=B9=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=E8=83=BD?= =?UTF-8?q?=E5=8A=9B=E8=8A=82=E7=82=B9=E5=85=A8=E9=83=A8=E5=A4=84=E7=BD=AE?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=AD=A3=E5=B8=B8=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=92=8C=E5=BC=82=E5=B8=B8=E7=94=A8=E4=BE=8B=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisposeTaskController.java | 14 + .../controller/TaskControllerQATest.java | 299 +++++++++++++++--- 2 files changed, 274 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index ab11a04e..45cb0f2f 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -303,6 +303,20 @@ public class DisposeTaskController { } StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class); + + List item = reqInfo.getItems(); + for (StopTaskData stopTaskData : item + ) { + if (stopTaskData.getId() == null || stopTaskData.getId().length() == 0) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } + + if (String.valueOf(stopTaskData.getType()).length() == 0 || stopTaskData.getType() == null) { + return ProtocolRespDTO.result(ErrorCode.ERR_PARAMEXCEPTION); + } + } + + TaskInfoRsp rspInfo = new TaskInfoRsp(); reqInfo.getItems().forEach(v -> { diff --git a/src/test/java/com/dispose/controller/TaskControllerQATest.java b/src/test/java/com/dispose/controller/TaskControllerQATest.java index cc17fff5..db709545 100644 --- a/src/test/java/com/dispose/controller/TaskControllerQATest.java +++ b/src/test/java/com/dispose/controller/TaskControllerQATest.java @@ -47,7 +47,7 @@ public class TaskControllerQATest extends InitTestEnvironment { private ObjectMapper objectMapper; @Test - public void t1_NormalContainsNonEmptyTaskTest() throws Exception { + public void a1_NormalContainsNonEmptyTaskTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.4\\\", " + "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + @@ -81,12 +81,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t2 disposeIp empty exception test. + * a2 disposeIp empty exception test. * * @throws Exception the exception */ @Test - public void t2_startTaskNoDisPoseIpExceptionTest() throws Exception { + public void a2_startTaskNoDisPoseIpExceptionTest() throws Exception { String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}"; @@ -109,12 +109,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t3 disposeIp null exception test. + * a3 disposeIp null exception test. * * @throws Exception the exception */ @Test - public void t3_startTaskNullDisposeIpExceptionTest() throws Exception { + public void a3_startTaskNullDisposeIpExceptionTest() throws Exception { //disposeIp null String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}"; @@ -138,12 +138,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t4 disposeIp Integer empty exception test. + * a4 disposeIp Integer empty exception test. * * @throws Exception the exception */ @Test - public void t4_startTaskIntegerDisposeIpExceptionTest() throws Exception { + public void a4_startTaskIntegerDisposeIpExceptionTest() throws Exception { String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":192345, \\\"disposeTime\\\":120}\"}"; @@ -172,12 +172,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t5 id null exception test. + * a5 id null exception test. * * @throws Exception the exception */ @Test - public void t5_startTaskNullIdExceptionTest() throws Exception { + public void a5_startTaskNullIdExceptionTest() throws Exception { String reqDataNullId = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":null," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; @@ -200,12 +200,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t6 type empty exception test. + * a6 type empty exception test. * * @throws Exception the exception */ @Test - public void t6_startTaskNoTypeExceptionTest() throws Exception { + public void a6_startTaskNoTypeExceptionTest() throws Exception { String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; @@ -228,12 +228,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t7 type null exception test. + * a7 type null exception test. * * @throws Exception the exception */ @Test - public void t7_startTaskNullTypeExceptionTest() throws Exception { //null type + public void a7_startTaskNullTypeExceptionTest() throws Exception { //null type String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; @@ -256,12 +256,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t8 disposeTime empty exception test. + * a8 disposeTime empty exception test. * * @throws Exception the exception */ @Test - public void t8_startTaskNoDisposeTimeExceptionTest() throws Exception { + public void a8_startTaskNoDisposeTimeExceptionTest() throws Exception { //no disposeTime String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":}\"}"; @@ -285,12 +285,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t9 disposeTime null exception test. + * a9 disposeTime null exception test. * * @throws Exception the exception */ @Test - public void t9_startTaskNullDisposeTimeExceptionTest() throws Exception { + public void a9_startTaskNullDisposeTimeExceptionTest() throws Exception { //null disposeTime String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":null}\"}"; @@ -314,12 +314,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t10 disposeTime String exception test. + * a10 disposeTime String exception test. * * @throws Exception the exception */ @Test - public void t10_startTaskStringDisposeTimeExceptionTest() throws Exception { + public void a10_startTaskStringDisposeTimeExceptionTest() throws Exception { //string disposeTime String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":\\\"120\\\"}\"}"; @@ -343,12 +343,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t11 taskId empty exception test. + * b1 taskId empty exception test. * * @throws Exception the exception */ @Test - public void t11_stopTaskNoTaskIdExceptionTest() throws Exception { + public void b1_stopTaskNoTaskIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + "\"msgContent\":\"{\\\"taskId\\\":\\\"\\\"}\"}"; @@ -371,12 +371,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t12 taskId null exception test. + * b2 taskId null exception test. * * @throws Exception the exception */ @Test - public void t12_stopTaskNullTaskIdExceptionTest() throws Exception { + public void b2_stopTaskNullTaskIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + "\"msgContent\":\"{\\\"taskId\\\":null}\"}"; @@ -412,12 +412,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t13 id null exception test. + * c1 id null exception test. * * @throws Exception the exception */ @Test - public void t13_stopTaskByIpNullIdExceptionTest() throws Exception { + public void c1_stopTaskByIpNullIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":null,\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; @@ -440,12 +440,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t14 id empty exception test. + * c2 id empty exception test. * * @throws Exception the exception */ @Test - public void t14_stopTaskByIpNoIdExceptionTest() throws Exception { + public void c2_stopTaskByIpNoIdExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; @@ -468,12 +468,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t15 disposeIp empty exception test. + * c3 disposeIp empty exception test. * * @throws Exception the exception */ @Test - public void t15_stopTaskByIpNoDisposeIpExceptionTest() throws Exception { + public void c3_stopTaskByIpNoDisposeIpExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"\\\"}]}\"}"; @@ -496,12 +496,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t16 disposeIp null exception test. + * c4 disposeIp null exception test. * * @throws Exception the exception */ @Test - public void t16_stopTaskByIpNullDisposeIpExceptionTest() throws Exception { + public void c4_stopTaskByIpNullDisposeIpExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":null}]}\"}"; @@ -524,12 +524,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t17 disposeIp "abc" exception test. + * c5 disposeIp "abc" exception test. * * @throws Exception the exception */ @Test - public void t17_stopTaskByIpErrorDisposeIpExceptionTest() throws Exception { + public void c5_stopTaskByIpErrorDisposeIpExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"abc\\\"}]}\"}"; @@ -552,12 +552,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t18 disposeIp Integer exception test. + * c6 disposeIp Integer exception test. * * @throws Exception the exception */ @Test - public void t18_stopTaskByIpIntegerDisposeIpExceptionTest() throws Exception { + public void c6_stopTaskByIpIntegerDisposeIpExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":0,\\\"disposeIp\\\":123}]}\"}"; @@ -580,12 +580,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t19 type empty exception test. + * c7 type empty exception test. * * @throws Exception the exception */ @Test - public void t19_stopTaskByIpNoTypeExceptionTest() throws Exception { + public void c7_stopTaskByIpNoTypeExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; @@ -608,12 +608,12 @@ public class TaskControllerQATest extends InitTestEnvironment { } /** - * t20 type null exception test. + * c8 type null exception test. * * @throws Exception the exception */ @Test - public void t20_stopTaskByIpNullTypeExceptionTest() throws Exception { + public void c8_stopTaskByIpNullTypeExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + "[{\\\"id\\\":\\\"314\\\",\\\"type\\\":null,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; @@ -634,4 +634,225 @@ public class TaskControllerQATest extends InitTestEnvironment { Assert.assertNotNull(returnStatus.getMessage()); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } + + /** + * d1 stop task by single node test. + * + */ + @Test + public void d1_NormalStopTaskByNodeTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"472\\\",\\\"type\\\":0}]}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), 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); + } + } + } + + /** + * d2 stop task by two nodes test. + * + */ + @Test + public void d2_NormalStopTaskByNodesTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"472\\\",\\\"type\\\":0}, {\\\"id\\\":\\\"471\\\",\\\"type\\\":0}]}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), 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); + } + } + } + + /** + * d3 id empty exception test. + * + * @throws Exception the exception + */ + @Test + public void d3_stopTaskByNodeNoIdExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"\\\",\\\"type\\\":0}}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * d4 id null exception test. + * + * @throws Exception the exception + */ + @Test + public void d4_stopTaskByNodeNullIdExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":null,\\\"type\\\":0}}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * d5 type empty exception test. + * + * @throws Exception the exception + */ + @Test + public void d5_stopTaskByNodeNoTypeExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"472\\\",\\\"type\\\":}}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * d6 type null exception test. + * + * @throws Exception the exception + */ + @Test + public void d6_stopTaskByNodeNullTypeExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + + "[{\\\"id\\\":\\\"472\\\",\\\"type\\\":null}}\"}"; + + String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .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(taskStopByNode), ReturnStatus.class); + + Assert.assertNotNull(returnStatus.getStatus()); + Assert.assertNotNull(returnStatus.getMessage()); + Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + + } From 6212c72887e8ba8b786f002bf0f7f1db851a36cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B7=91=E8=B4=A4?= Date: Sat, 9 May 2020 16:00:42 +0800 Subject: [PATCH 5/5] =?UTF-8?q?OCT=20REM:[=E4=BF=AE=E6=94=B9DeviceNodeInfo?= =?UTF-8?q?ControllerQATest=E7=B1=BB=EF=BC=9A1=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=202=E3=80=81=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=20=203=E3=80=81=E4=BF=AE=E6=94=B9=E9=93=BE=E8=B7=AF?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=8A=B6=E6=80=81=E6=8E=A5=E5=8F=A3i?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80=E6=96=B9=E5=BC=8F]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceNodeInfoControllerQATest.java | 168 ++++++++++-------- 1 file changed, 97 insertions(+), 71 deletions(-) diff --git a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerQATest.java b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerQATest.java index cbca8a29..f5d90a9d 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerQATest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerQATest.java @@ -16,6 +16,7 @@ package com.dispose.controller; import com.dispose.Global.InitTestEnvironment; import com.dispose.common.ErrorCode; import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.po.ReturnStatus; import com.dispose.pojo.vo.information.DeviceInfoData; import com.dispose.pojo.vo.information.DeviceInfoRsp; import com.dispose.pojo.vo.information.LinkStatusRsp; @@ -95,17 +96,19 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(ver); List verList = objectMapper.readValue(msgContent, new TypeReference>() { }); - Assert.assertEquals(1, verList.size()); + Assert.assertEquals(verList.size(), 1); for (VersionRsp versionRsp : verList ) { if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), "0"); - Assert.assertEquals(versionRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); + Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); Assert.assertNotNull(versionRsp.getId()); Assert.assertNotNull(versionRsp.getVersion()); } else { - Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0"); - Assert.assertNotEquals(versionRsp.getMessage(), "成功"); + Assert.assertNotNull(versionRsp.getId()); + Assert.assertNull(versionRsp.getVersion()); + Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); } } } @@ -134,16 +137,19 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(ver); List verList = objectMapper.readValue(msgContent, new TypeReference>() { }); + Assert.assertTrue(verList.size() > 1); for (VersionRsp versionRsp : verList ) { if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), "0"); - Assert.assertEquals(versionRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); + Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); Assert.assertNotNull(versionRsp.getId()); Assert.assertNotNull(versionRsp.getVersion()); } else { - Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0"); - Assert.assertNotEquals(versionRsp.getMessage(), "成功"); + Assert.assertNotNull(versionRsp.getId()); + Assert.assertNull(versionRsp.getVersion()); + Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); } } } @@ -170,10 +176,13 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(ver); List verList = objectMapper.readValue(msgContent, new TypeReference>() { }); + Assert.assertEquals(verList.size(), 1); for (VersionRsp versionRsp : verList ) { - Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0"); - Assert.assertNotEquals(versionRsp.getMessage(), "成功"); + Assert.assertNotNull(versionRsp.getId()); + Assert.assertNull(versionRsp.getVersion()); + Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); } } @@ -309,16 +318,17 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(deviceInfo); DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); List deviceInfoList = deviceInfoRsp.getItems(); + Assert.assertEquals(deviceInfoList.size(), 1); for (DeviceInfoData d : deviceInfoList ) { if (verifyDeviceIdExists(d.getId())) { Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), 0); - Assert.assertEquals(d.getMessage(), "成功"); + Assert.assertEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); } else { Assert.assertNotNull(d.getId()); - Assert.assertNotEquals(d.getStatus(), 0); - Assert.assertNotEquals(d.getMessage(), "成功"); + Assert.assertNotEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); } } } @@ -346,16 +356,17 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(deviceInfo); DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); List deviceInfoList = deviceInfoRsp.getItems(); + Assert.assertTrue(deviceInfoList.size() > 1); for (DeviceInfoData d : deviceInfoList ) { if (verifyDeviceIdExists(d.getId())) { Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), 0); - Assert.assertEquals(d.getMessage(), "成功"); + Assert.assertEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); } else { Assert.assertNotNull(d.getId()); - Assert.assertNotEquals(d.getStatus(), 0); - Assert.assertNotEquals(d.getMessage(), "成功"); + Assert.assertEquals(d.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); + Assert.assertEquals(d.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); } } } @@ -383,17 +394,13 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ String msgContent = verifyResp(deviceInfo); DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); List deviceInfoList = deviceInfoRsp.getItems(); + + Assert.assertEquals(deviceInfoList.size(), 1); for (DeviceInfoData d : deviceInfoList ) { - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), 0); - Assert.assertEquals(d.getMessage(), "成功"); - } else { - Assert.assertNotNull(d.getId()); - Assert.assertNotEquals(d.getStatus(), 0); - Assert.assertNotEquals(d.getMessage(), "成功"); - } + Assert.assertNotNull(d.getId()); + Assert.assertEquals(d.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); + Assert.assertEquals(d.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); } } @@ -416,9 +423,13 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(deviceInfo); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); + } /** @@ -440,9 +451,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(deviceInfo); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -464,9 +478,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(deviceInfo); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -489,9 +506,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(deviceInfo); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -519,17 +539,18 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { }); + Assert.assertEquals(linkStatusList.size(), 1); for (LinkStatusRsp linkStatusRsp : linkStatusList ) { if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertEquals(linkStatusRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); + Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); Assert.assertNotNull(linkStatusRsp.getId()); Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); } else { - Assert.assertNotEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertNotEquals(linkStatusRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); } } @@ -563,14 +584,14 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ for (LinkStatusRsp linkStatusRsp : linkStatusList ) { if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertEquals(linkStatusRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); + Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); Assert.assertNotNull(linkStatusRsp.getId()); Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); } else { - Assert.assertNotEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertNotEquals(linkStatusRsp.getMessage(), "成功"); + Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); } } @@ -601,19 +622,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { }); + Assert.assertEquals(linkStatusList.size(), 1); for (LinkStatusRsp linkStatusRsp : linkStatusList ) { - if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertEquals(linkStatusRsp.getMessage(), "成功"); - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - } else { - Assert.assertNotEquals(String.valueOf(linkStatusRsp.getStatus()), "0"); - Assert.assertNotEquals(linkStatusRsp.getMessage(), "成功"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - } + Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); + Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); + Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); } } @@ -636,9 +650,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(linkstatus); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -660,9 +677,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(linkstatus); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -684,9 +704,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(linkstatus); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /** @@ -709,9 +732,12 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{ .getResponse() .getContentAsString(); - String msgContent = verifyResp(linkstatus); - Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()))); - Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg())); + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class) ; + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); } /**