diff --git a/pom.xml b/pom.xml
index a6b6e257..61098b5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,13 @@
fastjson
1.2.58
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
+
mysql
diff --git a/src/test/java/com/dispose/Global/InitTestEnvironment.java b/src/test/java/com/dispose/Global/InitTestEnvironment.java
index e9c5b25a..ec65780b 100644
--- a/src/test/java/com/dispose/Global/InitTestEnvironment.java
+++ b/src/test/java/com/dispose/Global/InitTestEnvironment.java
@@ -7,11 +7,16 @@ import com.dispose.service.UserAccountService;
import javax.annotation.Resource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.test.context.ActiveProfiles;
+import java.util.EnumMap;
+import java.util.Iterator;
+
/**
* The type Init test environment.
*/
@@ -31,6 +36,10 @@ public class InitTestEnvironment {
* The Password.
*/
private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58";
+ /**
+ * The connect timeout.
+ */
+ public static final int HTTP_CONNECT_TIMEOUT = 10000;
/**
* The User account service.
*/
@@ -70,4 +79,48 @@ public class InitTestEnvironment {
public String getLogToken() {
return logToken;
}
+
+ /**
+ * Check response body.
+ */
+ public EnumMap verifyRep(String data, Long reqTime) throws JSONException {
+ Long verValue = 2L;
+ ErrorCode err = ErrorCode.ERR_OK;
+ EnumMap ret = new EnumMap<>(ErrorCode.class);
+
+ JSONObject jsonObject = new JSONObject(data);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ // 获得key
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ Long repTime = Long.valueOf(jsonObject.getString("timeStamp"));
+ if ((jsonObject.getString("timeStamp").length() == 0) || (repTime - reqTime) > HTTP_CONNECT_TIMEOUT) {
+ err = ErrorCode.ERR_REQTIMEOUT;
+ }
+
+ Long ver = Long.valueOf(jsonObject.getString("ver"));
+ if ((jsonObject.getString("ver").length() == 0) || (!ver.equals(verValue))) {
+ err = ErrorCode.ERR_VERSION;
+ }
+
+ long cryptoType = Long.parseLong(jsonObject.getString("cryptoType"));
+ if ((String.valueOf(cryptoType).length() == 0) || (cryptoType < 0)) {
+ err = ErrorCode.ERR_INPUTMISS;
+ }
+
+ if((jsonObject.getString("code").length() == 0) ||
+ Long.parseLong(jsonObject.getString("code")) != 200){
+ err = ErrorCode.ERR_UNKNOWNCMD;
+ }
+
+ String msgContent = jsonObject.getString("msgContent");
+
+ ret.put(err, msgContent);
+ return ret;
+ }
}
diff --git a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java
index 459fa4d5..ceeafcb5 100644
--- a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java
+++ b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java
@@ -1,15 +1,33 @@
package com.dispose.controller;
+import com.alibaba.fastjson.JSON;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
+import com.dispose.common.ErrorCode;
+import com.dispose.dispose.po.DeviceInfo;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.entity.DisposeDevice;
+import com.dispose.pojo.po.DisposeDeviceCapacity;
+import com.dispose.pojo.vo.common.DisposeCapacity;
import com.dispose.pojo.vo.common.IDArrayReq;
+import com.dispose.pojo.vo.information.DeviceCapacityData;
+import com.dispose.pojo.vo.information.DisposeNodeData;
+import com.dispose.service.DisposeNodeManager;
import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.EnumMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import net.sf.json.JsonConfig;
+import org.checkerframework.checker.units.qual.C;
+import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -21,9 +39,11 @@ 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 static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
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;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* The type Device node info controller test.
@@ -58,6 +78,12 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Resource
private UserAccountService userAccountService;
+ /**
+ * The Dispose device manager.
+ */
+ @Resource
+ private DisposeNodeManager disposeNodeManager;
+
/**
* Gets exists device id.
@@ -85,13 +111,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String ver = mockMvc.perform(MockMvcRequestBuilders
.post("/information/version")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -101,8 +128,42 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(ver, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ JSONArray json = JSONArray.fromObject(msgContent);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+ //判断是否存在该能力唯一标识符
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertNotNull(Content.getString("version"));
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
+
}
+
/**
* T 1 get version all.
*
@@ -114,13 +175,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String verAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/version")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -130,8 +192,28 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(verAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ JSONArray json = JSONArray.fromObject(msgContent);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertNotNull(Content.getString("version"));
+ }
}
+
/**
* T 2 get device info.
*
@@ -143,13 +225,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String deviceInfo = mockMvc.perform(MockMvcRequestBuilders
.post("/information/deviceinfo")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -159,6 +242,65 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(deviceInfo, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String memory = Content.getString("memory");
+ String freeMemory = Content.getString("freeMemory");
+ String cpuUsed = Content.getString("cpuUsed");
+
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertNotEquals(memory, "0");
+ Assert.assertNotEquals(freeMemory, "0");
+ Assert.assertNotEquals(cpuUsed, "0");
+ Assert.assertNotEquals(Content.getString("vendor"), null);
+ Assert.assertNotEquals(Content.getString("model"), null);
+ Assert.assertNotEquals(Content.getString("firmware"), null);
+ Assert.assertNotEquals(Content.getString("os"), null);
+ Assert.assertNotEquals(Content.getString("kernel"), null);
+ Assert.assertNotEquals(Content.getString("arch"), null);
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertEquals(memory, "0");
+ Assert.assertEquals(freeMemory, "0");
+ Assert.assertEquals(cpuUsed, "0");
+ }
+ }
+ }
+ }
}
/**
@@ -172,13 +314,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String deviceInfoAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/deviceinfo")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -188,8 +331,65 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(deviceInfoAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ //json字符串转成对象 解析设备信息
+ DeviceInfo dis = (DeviceInfo) JSONObject.toBean(Content, DeviceInfo.class);
+ System.out.println(dis);
+ Assert.assertNotEquals(String.valueOf(dis.getVendor()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getModel()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getFirmware()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getOs()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getKernel()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getArch()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getMemory()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getFreeMemory()), null);
+ Assert.assertNotEquals(String.valueOf(dis.getCpuUsed()), null);
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertEquals(Content.getString("memory"), "0");
+ Assert.assertEquals(Content.getString("freeMemory"), "0");
+ Assert.assertEquals(Content.getString("cpuUsed"), "0");
+ }
+ }
+ }
+ }
}
+
/**
* T 3 get device capacity.
*
@@ -201,13 +401,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/capacity")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -217,6 +418,59 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(capacity, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.println("items=" + items);
+
+ JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ String capacity1 = Content.getString("capacity");
+ //解析capacity 数组
+ System.out.print("capacity=" + capacity1);
+ JSONArray json1 = JSONArray.fromObject(capacity1);
+ for (int j = 0; j < json1.size(); j++) {
+ JSONObject capContent = json1.getJSONObject(j);
+ Assert.assertNotEquals(capContent.getString("type") ,"-1");
+ Assert.assertNotEquals(capContent.getString("tolCapacity"), "-1");
+ Assert.assertNotEquals( capContent.getString("usedCapacity"), "-1");
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
}
/**
@@ -230,13 +484,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String capacityAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/capacity")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -246,10 +501,56 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(capacityAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ String items = jsonObject.getString("items");
+ System.out.println("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ String cap = Content.getString("capacity");
+
+ net.sf.json.JSONArray capArray = JSONArray.fromObject(cap);
+ List> list = JSONArray.toList(capArray, new DisposeCapacity(), new JsonConfig());
+ for (Object o : list) {
+ DisposeCapacity dis = (DisposeCapacity) o;
+ Assert.assertNotEquals(String.valueOf(dis.getType()), "-1");
+ Assert.assertNotEquals(String.valueOf(dis.getTolCapacity()), "-1");
+ Assert.assertNotEquals(String.valueOf(dis.getUsedCapacity()), "-1");
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
+
}
/**
- * T 4 get device protected ip.
+ * T 3 get device protected ip.
*
* @throws Exception the exception
*/
@@ -259,13 +560,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String protectedIp = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -275,10 +577,59 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(protectedIp, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ String items = jsonObject.getString("items");
+ System.out.println("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ String cap = Content.getString("capacity");
+
+ net.sf.json.JSONArray capArray = JSONArray.fromObject(cap);
+ List> list = JSONArray.toList(capArray, new DisposeCapacity(), new JsonConfig());
+ for (Object o : list) {
+ DisposeCapacity dis = (DisposeCapacity) o;
+ Assert.assertNotEquals(String.valueOf(dis.getType()), "-1");
+ Assert.assertNotEquals(String.valueOf(dis.getDisposeIp()), null);
+ //String[] disposeIps = dis.getDisposeIp().split(",");
+ //for (String disposeIp : disposeIps) {
+ //Assert.assertTrue(disposeIp.matches(regex));
+ //}
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
}
/**
- * T 4 get device protected ip all.
+ * T 3 get device protected ip all.
*
* @throws Exception the exception
*/
@@ -288,13 +639,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String protectedIpAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -304,25 +656,76 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(protectedIpAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ String items = jsonObject.getString("items");
+ System.out.println("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String id = Content.getString("id");
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs
+ ) {
+ //Mysql存在能力节点标识符,status"0" message"成功" 有对应的设备型号
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ String cap = Content.getString("capacity");
+
+ net.sf.json.JSONArray capArray = JSONArray.fromObject(cap);
+ List> list = JSONArray.toList(capArray, new DisposeCapacity(), new JsonConfig());
+ for (Object o : list) {
+ DisposeCapacity dis = (DisposeCapacity) o;
+ Assert.assertNotEquals(String.valueOf(dis.getType()), "-1");
+ Assert.assertNotEquals(String.valueOf(dis.getDisposeIp()), null);
+ //String[] disposeIps = dis.getDisposeIp().split(",");
+ //for (String disposeIp : disposeIps) {
+ //Assert.assertTrue(disposeIp.matches(regex));
+ //}
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
}
/**
- * T 5 get dispose node list.
+ * T 3 get dispose node list.
*
* @throws Exception the exception
*/
@Test
public void t5_getDisposeNodeList() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
+ .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String nodeList = mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_list")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -332,10 +735,59 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(nodeList, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ //json字符串转成对象 解析设备信息
+ DisposeNodeData dis = (DisposeNodeData) JSONObject.toBean(Content, DisposeNodeData.class);
+ System.out.println(dis);
+ Assert.assertNotEquals(dis.getName(), null);
+ Assert.assertNotEquals(dis.getType(), -1);
+ Assert.assertNotEquals(dis.getIp(), null);
+ Assert.assertTrue(dis.getIp().matches(regex));
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
}
/**
- * T 5 get dispose node list all.
+ * T 3 get dispose node list all.
*
* @throws Exception the exception
*/
@@ -345,13 +797,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String nodeListAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_list")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -361,10 +814,59 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(nodeListAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ //json字符串转成对象 解析设备信息
+ DisposeNodeData dis = (DisposeNodeData) JSONObject.toBean(Content, DisposeNodeData.class);
+ System.out.println(dis);
+ Assert.assertNotEquals(dis.getName(), null);
+ Assert.assertNotEquals(dis.getType(), -1);
+ Assert.assertNotEquals(dis.getIp(), null);
+ Assert.assertTrue(dis.getIp().matches(regex));
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ }
+ }
+ }
+ }
}
/**
- * T 6 get dispose node details.
+ * T 3 get dispose node details.
*
* @throws Exception the exception
*/
@@ -374,13 +876,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String disposeNodeDetails = mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_details")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -390,10 +893,85 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ String cap = null;
+ 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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(disposeNodeDetails, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+ String type = Content.getString("type");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertNotEquals(Content.getString("name"), null);
+ Assert.assertNotEquals(Content.getString("ip"), null);
+ Assert.assertTrue(Content.getString("ip").matches(regex));
+ Assert.assertNotNull(Content.getString("areaCode"));
+ Assert.assertNotNull(Content.getString("manufacturer"));
+ Assert.assertNotNull(Content.getString("model"));
+ Assert.assertNotNull(Content.getString("version"));
+ Assert.assertNotNull(Content.getString("readme"));
+
+ //解析capacity 数组
+ if (Content.getString("capacity") != null) {
+ cap = Content.getString("capacity");
+ }
+
+ net.sf.json.JSONArray capArray = JSONArray.fromObject(cap);
+ List> list = JSONArray.toList(capArray, new DisposeCapacity(), new JsonConfig());
+ for (Object o : list) {
+ DisposeCapacity d = (DisposeCapacity) o;
+ Assert.assertNotEquals(String.valueOf(d.getType()), "-1");
+ Assert.assertNotEquals(String.valueOf(d.getDisposeIp()), null);
+ //String[] disposeIps = dis.getDisposeIp().split(",");
+ //for (String disposeIp : disposeIps) {
+ //Assert.assertTrue(disposeIp.matches(regex));
+ //}
+
+ Assert.assertNotNull(String.valueOf(d.getTolCapacity()));
+ Assert.assertNotNull(String.valueOf(d.getUsedCapacity()));
+ }
+
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertNotEquals(type, "-1");
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertNotEquals(type, "-1");
+ }
+ }
+ }
+ }
}
/**
- * T 6 get dispose node details all.
+ * T 3 get dispose node details all.
*
* @throws Exception the exception
*/
@@ -403,13 +981,14 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String disposeNodeDetailsAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_details")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -419,26 +998,97 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ String cap = null;
+ 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";
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(disposeNodeDetailsAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
+ Iterator it = jsonObject.keys();
+ System.out.println();
+ while (it.hasNext()) {
+ String key = (String) it.next();
+ String value = jsonObject.getString(key);
+ System.out.println("key: " + key + ",value:" + value);
+ }
+
+ String items = jsonObject.getString("items");
+ System.out.print("items=" + items);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(items);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+ String type = Content.getString("type");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertNotEquals(Content.getString("name"), null);
+ Assert.assertNotEquals(Content.getString("ip"), null);
+ Assert.assertTrue(Content.getString("ip").matches(regex));
+ Assert.assertNotNull(Content.getString("areaCode"));
+ Assert.assertNotNull(Content.getString("manufacturer"));
+ Assert.assertNotNull(Content.getString("model"));
+ Assert.assertNotNull(Content.getString("version"));
+ Assert.assertNotNull(Content.getString("readme"));
+
+ //解析capacity 数组
+ if (Content.getString("capacity") != null) {
+ cap = Content.getString("capacity");
+ }
+
+ net.sf.json.JSONArray capArray = JSONArray.fromObject(cap);
+ List> list = JSONArray.toList(capArray, new DisposeCapacity(), new JsonConfig());
+ for (Object o : list) {
+ DisposeCapacity d = (DisposeCapacity) o;
+ Assert.assertNotEquals(String.valueOf(d.getType()), "-1");
+ Assert.assertNotEquals(String.valueOf(d.getDisposeIp()), null);
+ //String[] disposeIps = dis.getDisposeIp().split(",");
+ //for (String disposeIp : disposeIps) {
+ //Assert.assertTrue(disposeIp.matches(regex));
+ //}
+
+ Assert.assertNotNull(String.valueOf(d.getTolCapacity()));
+ Assert.assertNotNull(String.valueOf(d.getUsedCapacity()));
+ }
+
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertNotEquals(type, "-1");
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertNotEquals(type, "-1");
+ }
+ }
+ }
+ }
}
- /**
- * T 7 get link status.
- *
- * @throws Exception the exception
- */
@Test
public void t7_getLinkStatus() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String linkstatus = mockMvc.perform(MockMvcRequestBuilders
.post("/information/linkstatus")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -448,26 +1098,55 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
+
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(linkstatus, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
+
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
+
+ net.sf.json.JSONArray json = JSONArray.fromObject(msgContent);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+ String online = Content.getString("online");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertEquals(online, "1");
+ }
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertEquals(online, "0");
+ }
+ }
}
- /**
- * T 7 get link status all.
- *
- * @throws Exception the exception
- */
+
@Test
public void t7_getLinkStatusAll() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{})
.build();
+ Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
+ reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
- mockMvc.perform(MockMvcRequestBuilders
+ String linkStatusAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/linkstatus")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
@@ -477,30 +1156,38 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
- }
- @Test
- public void t8_getNodeAllRunTask() throws Exception {
- IDArrayReq reqData = IDArrayReq.builder()
- .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
- .build();
+ EnumMap ret = new EnumMap(ErrorCode.class);
+ ret = verifyRep(linkStatusAll, reqTimeStamp);
+ ErrorCode err = ret.keySet().iterator().next();
+ Assert.assertEquals(err, ErrorCode.ERR_OK);
- ProtocolReqDTO reqInfo = new ProtocolReqDTO();
- reqInfo.setVer(ConstValue.Protocol.VERSION);
- reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
- reqInfo.setTimeStamp(System.currentTimeMillis());
- reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
+ String msgContent = ret.get(err);
+ System.out.print("msgContent=" + msgContent);
- mockMvc.perform(MockMvcRequestBuilders
- .post("/information/run_task")
- .contentType(MediaType.APPLICATION_JSON)
- .header("Authorization", "Bearer " + getLogToken())
- .content(objectMapper.writeValueAsString(reqInfo)))
- .andDo(print()).andExpect(status().isOk())
- .andExpect(jsonPath("$.code").value(200))
- .andReturn()
- .getResponse()
- .getContentAsString();
+ net.sf.json.JSONArray json = JSONArray.fromObject(msgContent);
+ for (int i = 0; i < json.size(); i++) {
+ JSONObject Content = json.getJSONObject(i);
+ String status = Content.getString("status");
+ String message = Content.getString("message");
+ String id = Content.getString("id");
+ String online = Content.getString("online");
+
+ List decs = disposeNodeManager.getAllDisposeDevice();
+ if (decs != null && decs.size() > 0) {
+ for (DisposeDevice v : decs) {
+ if (String.valueOf(v.getId()).equals(id)) {
+ Assert.assertEquals(status, "0");
+ Assert.assertEquals(message, "成功");
+ Assert.assertEquals(online, "1");
+ }
+ }
+ } else {
+ Assert.assertNotEquals(status, "0");
+ Assert.assertNotEquals(message, "成功");
+ Assert.assertEquals(online, "0");
+ }
+ }
}
@Test