From f8d0554f64787c54158da7921664130fbf3009f8 Mon Sep 17 00:00:00 2001 From: lijinxing Date: Wed, 20 May 2020 19:22:05 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=E6=B7=BB=E5=8A=A0=E8=83=BD=E5=8A=9B?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3P2?= =?UTF-8?q?=E7=BA=A7=E6=B5=8B=E8=AF=95DeviceNodeManagerControllerQATest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceNodeManagerControllerQATest.java | 263 +++++++++++++++++- 1 file changed, 255 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java b/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java index 6eaccab9..15dbebc8 100644 --- a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java +++ b/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java @@ -1,5 +1,6 @@ package com.dispose.test.controller; +import com.dispose.pojo.vo.device.AddNodeRsp; import com.dispose.test.Global.InitTestEnvironment; import com.dispose.common.ErrorCode; import com.dispose.pojo.vo.device.AddNodeRetData; @@ -23,6 +24,8 @@ import org.springframework.transaction.annotation.Transactional; 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.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -54,12 +57,12 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment { @Resource private DisposeNodeManager disposeNodeManager; /** - * A 2 items json exception test. + * A 2 add device node msgContent empty exception test. * * @throws Exception the exception */ @Test - public void a2_itemsJsonExceptionTest() throws Exception { + public void a2_addDeviceNodeMsgEmptyExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908,\"msgContent\":\"\"}"; String ret = mockMvc.perform(MockMvcRequestBuilders @@ -77,17 +80,16 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment { Assert.assertNotNull(rspInfo.getMessage()); Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } /** - * A 3 items null exception test. + * A 3 add device node msg null exception test. * * @throws Exception the exception */ @Test - public void a3_itemsNullExceptionTest() throws Exception { + public void a3_addDeviceNodeMsgNullExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908,\"msgContent\":\"null\"}"; String ret = mockMvc.perform(MockMvcRequestBuilders @@ -105,17 +107,16 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment { Assert.assertNotNull(rspInfo.getMessage()); Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } /** - * A 4 type json exception test. + * A 4 add device node type empty exception test. * * @throws Exception the exception */ @Test - public void a4_typeJsonExceptionTest() throws Exception { + public void a4_addDeviceNodeTypeEmptyExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + @@ -137,7 +138,253 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment { Assert.assertNotNull(rspInfo.getMessage()); Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + /** + * A 5 add device node type string exception test. + * + * @throws Exception the exception + */ + @Test + public void a5_addDeviceNodeTypeStringExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + + "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + + "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + + "\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," + + "\\\"type\\\":\\\"abcd\\\",\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * A 6 add device node type null exception test. + * + * @throws Exception the exception + */ + @Test + public void a6_addDeviceNodeTypeNullExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + + "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + + "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + + "\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," + + "\\\"type\\\":\\\"null\\\",\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRsp retStatus = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); + List r = retStatus.getItems(); + for (AddNodeRetData v : r + ) { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getIpAddr()); + Assert.assertNotNull(v.getDevId()); + Assert.assertNotNull(v.getMessage()); + Assert.assertNotNull(v.getStatus()); + + if (v.getStatus() == 0) { + Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); + } else if (v.getStatus() == 20) { + Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_DEVICEEXISTS.getCode())); + } + } + } + + /** + * A 7 add device node ipAddr empty exception test. + * + * @throws Exception the exception + */ + @Test + public void a7_addDeviceNodeIpAddrEmptyExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + + "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"\"," + + "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + + "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * A 8 add device node ipAddr null exception test. + * + * @throws Exception the exception + */ + @Test + public void a8_addDeviceNodeIpAddrNullExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + + "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":null," + + "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + + "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRsp rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); + List r = rspInfo.getItems(); + + for (AddNodeRetData addNodeRetData:r + ) { + Assert.assertNotNull(addNodeRetData.getMessage()); + Assert.assertNotNull(addNodeRetData.getStatus()); + Assert.assertEquals(Long.valueOf(addNodeRetData.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + + } + + /** + * B 2 del device node Msg Empty exception test. + * + * @throws Exception the exception + */ + @Test + public void b2_delDeviceNodeMsgEmptyExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * B 3 del device node msg null exception test. + * + * @throws Exception the exception + */ + @Test + public void b3_delDeviceNodeMsgNullExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * B 4 del device node id null exception test. + * + * @throws Exception the exception + */ + @Test + public void b4_delDeviceNodeIdNullExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + } + + /** + * B 5 del device node id int exception test. + * + * @throws Exception the exception + */ + @Test + public void b5_delDeviceNodeIdIntExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":123}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .put("/manager/device") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); + + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); } }