OCT REM:[增加冒烟测试类:1、获得处置设备版本信息接口 2、获得设备链接状态接口 3、获得处置设备信息]
This commit is contained in:
parent
b436510cad
commit
c51ba9b6d7
|
@ -0,0 +1,797 @@
|
|||
/*
|
||||
* Project: phoenix_ddos_handle2
|
||||
*
|
||||
* File Created at 2020/5/8 11:19
|
||||
*
|
||||
* Copyright 2019 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package com.dispose.controller;
|
||||
import com.dispose.Global.InitTestEnvironment;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.vo.information.DeviceInfoData;
|
||||
import com.dispose.pojo.vo.information.DeviceInfoRsp;
|
||||
import com.dispose.pojo.vo.information.LinkStatusRsp;
|
||||
import com.dispose.pojo.vo.information.VersionRsp;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* @author lsx
|
||||
* @Desc
|
||||
* @date 2020-05-08 11:19
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Slf4j
|
||||
public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment{
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose device manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* 正常获取节点版本信息-获取存在的一个节点版本信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a1_getVersionNormalOneExistDeviceTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\"]}\"}";
|
||||
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String msgContent = verifyResp(ver);
|
||||
List<VersionRsp> verList = objectMapper.readValue(msgContent, new TypeReference<List<VersionRsp>>() {
|
||||
});
|
||||
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.assertNotNull(versionRsp.getId());
|
||||
Assert.assertNotNull(versionRsp.getVersion());
|
||||
} else {
|
||||
Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0");
|
||||
Assert.assertNotEquals(versionRsp.getMessage(), "成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常获取节点版本信息-获取多个节点版本信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a2_getVersionNormalSeveralDeviceTest() throws Exception {
|
||||
// 获取多个节点版本信息
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\",\\\"123\\\"]}\"}";
|
||||
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String msgContent = verifyResp(ver);
|
||||
List<VersionRsp> verList = objectMapper.readValue(msgContent, new TypeReference<List<VersionRsp>>() {
|
||||
});
|
||||
for (VersionRsp versionRsp : verList
|
||||
) {
|
||||
if (verifyDeviceIdExists(versionRsp.getId())) {
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()), "0");
|
||||
Assert.assertEquals(versionRsp.getMessage(), "成功");
|
||||
Assert.assertNotNull(versionRsp.getId());
|
||||
Assert.assertNotNull(versionRsp.getVersion());
|
||||
} else {
|
||||
Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0");
|
||||
Assert.assertNotEquals(versionRsp.getMessage(), "成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常获取节点版本信息-获取不存在的一个节点版本信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a3_getVersionNormalOneNotExistDeviceTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String msgContent = verifyResp(ver);
|
||||
List<VersionRsp> verList = objectMapper.readValue(msgContent, new TypeReference<List<VersionRsp>>() {
|
||||
});
|
||||
for (VersionRsp versionRsp : verList
|
||||
) {
|
||||
Assert.assertNotEquals(String.valueOf(versionRsp.getStatus()), "0");
|
||||
Assert.assertNotEquals(versionRsp.getMessage(), "成功");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点版本信息-msgContent为空
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a4_getVersionMsgEmptyExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.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();
|
||||
String msgContent = verifyResp(ver);
|
||||
VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference<VersionRsp>() {
|
||||
});
|
||||
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()),
|
||||
String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点版本信息-msgContent为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a5_getVersionMsgNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.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();
|
||||
String msgContent = verifyResp(ver);
|
||||
VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference<VersionRsp>() {
|
||||
});
|
||||
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()),
|
||||
String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点版本信息-id为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a6_getVersionIdNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.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();
|
||||
String msgContent = verifyResp(ver);
|
||||
VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference<VersionRsp>() {
|
||||
});
|
||||
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()),
|
||||
String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点版本信息-id为"abd"
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a7_getVersionIdCharacterExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.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();
|
||||
String msgContent = verifyResp(ver);
|
||||
VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference<VersionRsp>() {
|
||||
});
|
||||
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()),
|
||||
String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点版本信息-id为整形
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void a8_getVersionIdIntegerExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":123}\"}";
|
||||
String ver = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.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();
|
||||
String msgContent = verifyResp(ver);
|
||||
VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference<VersionRsp>() {
|
||||
});
|
||||
|
||||
Assert.assertEquals(String.valueOf(versionRsp.getStatus()),
|
||||
String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
|
||||
Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息-获取存在的一个节点设备信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b1_getDeviceInfoNormalOneExistDeviceTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\"]}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class);
|
||||
List<DeviceInfoData> deviceInfoList = deviceInfoRsp.getItems();
|
||||
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(), "成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息-获取多个节点设备信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b2_getDeviceInfoNormalSeveralDeviceTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\",\\\"123\\\"]}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class);
|
||||
List<DeviceInfoData> deviceInfoList = deviceInfoRsp.getItems();
|
||||
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(), "成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息-获取不存在的一个节点设备信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b3_getDeviceInfoNormalOneNotExistDeviceTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class);
|
||||
List<DeviceInfoData> deviceInfoList = deviceInfoRsp.getItems();
|
||||
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(), "成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点设备信息-msgContent为空
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b4_getDeviceInfoEmptyMsgExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点设备信息-msgContent为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b5_getDeviceInfoMsgNullExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点设备信息-id为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b6_getDeviceInfoIdNullExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
/**
|
||||
* 获取节点设备信息-id为"abd"
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b7_getDeviceInfoIdCharacterExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点设备信息-id为整型
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void b8_getDeviceInfoIdIntegerExceptionTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":123}\"}";
|
||||
String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/deviceinfo")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(deviceInfo);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态-获取在线的一个节点链接状态
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c1_getLinkStatusNormalOneOnlineDeviceTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\"]}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
|
||||
List<LinkStatusRsp> linkStatusList = objectMapper.readValue(msgContent, new TypeReference<List<LinkStatusRsp>>() {
|
||||
});
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态-获取在线的多个节点链接状态
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c2_getLinkStatusNormalSeveralDeviceTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"242\\\",\\\"123\\\"]}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
|
||||
List<LinkStatusRsp> linkStatusList = objectMapper.readValue(msgContent, new TypeReference<List<LinkStatusRsp>>() {
|
||||
});
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态-获取不在线的一个节点链接状态
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c3_getLinkStatusNormalOneNotOnlineDeviceTest() throws Exception{
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
.content(reqData))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
|
||||
List<LinkStatusRsp> linkStatusList = objectMapper.readValue(msgContent, new TypeReference<List<LinkStatusRsp>>() {
|
||||
});
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态 - msgContent为空
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c4_getLinkStatusMsgEmptyExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态 - msgContent为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c5_getLinkStatusMsgNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态 - id为null
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c6_getLinkStatusIdNullExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态 - id为"abd"
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c7_getLinkStatusIdCharacterExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," +
|
||||
"\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接状态 - id为整型
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void c8_getLinkStatusIdIntegerExceptionTest() throws Exception {
|
||||
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":123}\"}";
|
||||
String linkstatus = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/linkstatus")
|
||||
.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();
|
||||
|
||||
String msgContent = verifyResp(linkstatus);
|
||||
Assert.assertTrue(msgContent.contains(String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())));
|
||||
Assert.assertTrue(msgContent.contains(ErrorCode.ERR_PARAMEXCEPTION.getMsg()));
|
||||
}
|
||||
|
||||
/**
|
||||
* test Determine whether the Id exists..
|
||||
*
|
||||
* @return boolean true-exists
|
||||
*/
|
||||
public boolean verifyDeviceIdExists(String deviceId) {
|
||||
boolean exists = false;
|
||||
List<DisposeDevice> decs = disposeNodeManager.getAllDisposeDevice();
|
||||
|
||||
if (decs != null && decs.size() > 0) {
|
||||
for (DisposeDevice d : decs
|
||||
) {
|
||||
if (String.valueOf(d.getId()).equals(deviceId)) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Revision history
|
||||
* -------------------------------------------------------------------------
|
||||
* <p>
|
||||
* Date Author Note
|
||||
* -------------------------------------------------------------------------
|
||||
* 2020-05-08 lsx creat
|
||||
*/
|
Loading…
Reference in New Issue