REM:
1. 添加获取能力节点处置中任务的响应报文内容判断
2. 添加验证响应报文通用字段的方法
This commit is contained in:
chenlinghy 2020-04-28 11:13:09 +08:00
parent cc4c0a010b
commit 90041e41f0
2 changed files with 157 additions and 151 deletions

View File

@ -83,10 +83,9 @@ public class InitTestEnvironment {
/** /**
* Check response body. * Check response body.
*/ */
public EnumMap<ErrorCode, String> verifyRep(String data, Long reqTime) throws JSONException { public String verifyRep(String data, Long reqTime) throws JSONException {
Long verValue = 2L; Long verValue = 2L;
ErrorCode err = ErrorCode.ERR_OK; ErrorCode err = ErrorCode.ERR_OK;
EnumMap<ErrorCode, String> ret = new EnumMap<>(ErrorCode.class);
JSONObject jsonObject = new JSONObject(data); JSONObject jsonObject = new JSONObject(data);
Iterator it = jsonObject.keys(); Iterator it = jsonObject.keys();
@ -102,25 +101,26 @@ public class InitTestEnvironment {
if ((jsonObject.getString("timeStamp").length() == 0) || (repTime - reqTime) > HTTP_CONNECT_TIMEOUT) { if ((jsonObject.getString("timeStamp").length() == 0) || (repTime - reqTime) > HTTP_CONNECT_TIMEOUT) {
err = ErrorCode.ERR_REQTIMEOUT; err = ErrorCode.ERR_REQTIMEOUT;
} }
Assert.assertEquals(err, ErrorCode.ERR_OK);
Long ver = Long.valueOf(jsonObject.getString("ver")); Long ver = Long.valueOf(jsonObject.getString("ver"));
if ((jsonObject.getString("ver").length() == 0) || (!ver.equals(verValue))) { if ((jsonObject.getString("ver").length() == 0) || (!ver.equals(verValue))) {
err = ErrorCode.ERR_VERSION; err = ErrorCode.ERR_VERSION;
} }
Assert.assertEquals(err, ErrorCode.ERR_OK);
long cryptoType = Long.parseLong(jsonObject.getString("cryptoType")); long cryptoType = Long.parseLong(jsonObject.getString("cryptoType"));
if ((String.valueOf(cryptoType).length() == 0) || (cryptoType < 0)) { if ((String.valueOf(cryptoType).length() == 0) || (cryptoType < 0)) {
err = ErrorCode.ERR_INPUTMISS; err = ErrorCode.ERR_INPUTMISS;
} }
Assert.assertEquals(err, ErrorCode.ERR_OK);
if((jsonObject.getString("code").length() == 0) || if((jsonObject.getString("code").length() == 0) ||
Long.parseLong(jsonObject.getString("code")) != 200){ Long.parseLong(jsonObject.getString("code")) != 200){
err = ErrorCode.ERR_UNKNOWNCMD; err = ErrorCode.ERR_UNKNOWNCMD;
} }
Assert.assertEquals(err, ErrorCode.ERR_OK);
String msgContent = jsonObject.getString("msgContent"); return jsonObject.getString("msgContent");
ret.put(err, msgContent);
return ret;
} }
} }

View File

@ -11,6 +11,8 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.DisposeDeviceCapacity; import com.dispose.pojo.po.DisposeDeviceCapacity;
import com.dispose.pojo.vo.common.DisposeCapacity; import com.dispose.pojo.vo.common.DisposeCapacity;
import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import com.dispose.pojo.vo.information.DeviceCapacityData; import com.dispose.pojo.vo.information.DeviceCapacityData;
import com.dispose.pojo.vo.information.DisposeNodeData; import com.dispose.pojo.vo.information.DisposeNodeData;
import com.dispose.service.DisposeNodeManager; import com.dispose.service.DisposeNodeManager;
@ -129,12 +131,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(ver, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
JSONArray json = JSONArray.fromObject(msgContent); JSONArray json = JSONArray.fromObject(msgContent);
@ -193,12 +190,8 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class);
ret = verifyRep(verAll, reqTimeStamp);
ErrorCode err = ret.keySet().iterator().next();
Assert.assertEquals(err, ErrorCode.ERR_OK);
String msgContent = ret.get(err); String msgContent = verifyRep(verAll, reqTimeStamp);
System.out.print("msgContent=" + msgContent); System.out.print("msgContent=" + msgContent);
JSONArray json = JSONArray.fromObject(msgContent); JSONArray json = JSONArray.fromObject(msgContent);
@ -243,12 +236,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(deviceInfo, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent); org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
@ -332,23 +320,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(deviceInfoAll, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.print("items=" + items); System.out.print("items=" + items);
@ -419,23 +394,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(capacity, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.println("items=" + items); System.out.println("items=" + items);
@ -450,12 +412,12 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
) { ) {
String status = Content.getString("status"); String status = Content.getString("status");
String message = Content.getString("message"); String message = Content.getString("message");
//Mysql存在能力节点标识符status"0" message"成功" 有对应的设备型号
if (String.valueOf(v.getId()).equals(id)) { if (String.valueOf(v.getId()).equals(id)) {
Assert.assertEquals(status, "0"); Assert.assertEquals(status, "0");
Assert.assertEquals(message, "成功"); Assert.assertEquals(message, "成功");
String capacity1 = Content.getString("capacity"); String capacity1 = Content.getString("capacity");
//解析capacity 数组 //解析capacityArray
System.out.print("capacity=" + capacity1); System.out.print("capacity=" + capacity1);
JSONArray json1 = JSONArray.fromObject(capacity1); JSONArray json1 = JSONArray.fromObject(capacity1);
for (int j = 0; j < json1.size(); j++) { for (int j = 0; j < json1.size(); j++) {
@ -502,12 +464,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(capacityAll, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent); org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
@ -525,7 +482,6 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
if (decs != null && decs.size() > 0) { if (decs != null && decs.size() > 0) {
for (DisposeDevice v : decs for (DisposeDevice v : decs
) { ) {
//Mysql存在能力节点标识符status"0" message"成功" 有对应的设备型号
if (String.valueOf(v.getId()).equals(id)) { if (String.valueOf(v.getId()).equals(id)) {
Assert.assertEquals(status, "0"); Assert.assertEquals(status, "0");
Assert.assertEquals(message, "成功"); Assert.assertEquals(message, "成功");
@ -546,7 +502,6 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
} }
} }
} }
} }
/** /**
@ -579,12 +534,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(protectedIp, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent); org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
@ -658,12 +608,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(protectedIpAll, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent); org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
@ -737,23 +682,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(nodeList, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.print("items=" + items); System.out.print("items=" + items);
@ -816,23 +748,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(nodeListAll, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.print("items=" + items); System.out.print("items=" + items);
@ -896,23 +815,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
String cap = null; 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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(disposeNodeDetails, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.print("items=" + items); System.out.print("items=" + items);
@ -937,7 +843,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
Assert.assertNotNull(Content.getString("version")); Assert.assertNotNull(Content.getString("version"));
Assert.assertNotNull(Content.getString("readme")); Assert.assertNotNull(Content.getString("readme"));
//解析capacity 数组 //解析capacityArray
if (Content.getString("capacity") != null) { if (Content.getString("capacity") != null) {
cap = Content.getString("capacity"); cap = Content.getString("capacity");
} }
@ -1001,23 +907,10 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
String cap = null; 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"; 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<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(disposeNodeDetailsAll, reqTimeStamp);
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); System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(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"); String items = jsonObject.getString("items");
System.out.print("items=" + items); System.out.print("items=" + items);
@ -1042,7 +935,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
Assert.assertNotNull(Content.getString("version")); Assert.assertNotNull(Content.getString("version"));
Assert.assertNotNull(Content.getString("readme")); Assert.assertNotNull(Content.getString("readme"));
//解析capacity 数组 //解析capacityArray
if (Content.getString("capacity") != null) { if (Content.getString("capacity") != null) {
cap = Content.getString("capacity"); cap = Content.getString("capacity");
} }
@ -1100,11 +993,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class);
ret = verifyRep(linkstatus, reqTimeStamp); String msgContent = 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); System.out.print("msgContent=" + msgContent);
net.sf.json.JSONArray json = JSONArray.fromObject(msgContent); net.sf.json.JSONArray json = JSONArray.fromObject(msgContent);
@ -1157,12 +1046,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
EnumMap<ErrorCode, String> ret = new EnumMap<ErrorCode, String>(ErrorCode.class); String msgContent = verifyRep(linkStatusAll, reqTimeStamp);
ret = verifyRep(linkStatusAll, reqTimeStamp);
ErrorCode err = ret.keySet().iterator().next();
Assert.assertEquals(err, ErrorCode.ERR_OK);
String msgContent = ret.get(err);
System.out.print("msgContent=" + msgContent); System.out.print("msgContent=" + msgContent);
net.sf.json.JSONArray json = JSONArray.fromObject(msgContent); net.sf.json.JSONArray json = JSONArray.fromObject(msgContent);
@ -1191,18 +1075,19 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
} }
@Test @Test
public void t8_getNodeAllRunTaskAll() throws Exception { public void t8_getNodeAllRunTask() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION); reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders String runTask = mockMvc.perform(MockMvcRequestBuilders
.post("/information/run_task") .post("/information/run_task")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -1212,21 +1097,141 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
String taskArray = null;
String msgContent = verifyRep(runTask, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
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<DisposeDevice> decs = disposeNodeManager.getAllDisposeDevice();
if (decs != null && decs.size() > 0) {
for (DisposeDevice v : decs) {
if (String.valueOf(v.getId()).equals(id)) {
//解析taskArray
if (Content.getString("taskArray") != null) {
taskArray = Content.getString("taskArray");
} }
net.sf.json.JSONArray taskInfos = JSONArray.fromObject(taskArray);
List<?> list = JSONArray.toList(taskInfos, new TaskInfoData(), new JsonConfig());
for (Object o : list) {
TaskInfoData taskInfo = (TaskInfoData) o;
Assert.assertNotEquals(taskInfo.getTaskId(), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getType()), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getStartTime()), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getDisposeTime()), -1);
Assert.assertNotEquals(taskInfo.getDisposeIp().length(), 0);
Assert.assertNotNull(taskInfo.getFlowAttack());
Assert.assertNotNull(taskInfo.getFlowClean());
Assert.assertEquals(status, "0");
Assert.assertEquals(message, "成功");
}
} else {
Assert.assertNotEquals(status, "0");
Assert.assertNotEquals(message, "成功");
}
}
}
}
}
@Test
public void t8_getNodeAllRunTaskAll() 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(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
String runTaskAll = 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();
String taskArray = null;
String msgContent = verifyRep(runTaskAll, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
org.json.JSONObject jsonObject = new org.json.JSONObject(msgContent);
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<DisposeDevice> decs = disposeNodeManager.getAllDisposeDevice();
if (decs != null && decs.size() > 0) {
for (DisposeDevice v : decs) {
if (String.valueOf(v.getId()).equals(id)) {
//解析taskArray
if (Content.getString("taskArray") != null) {
taskArray = Content.getString("taskArray");
}
net.sf.json.JSONArray taskInfos = JSONArray.fromObject(taskArray);
List<?> list = JSONArray.toList(taskInfos, new TaskInfoData(), new JsonConfig());
for (Object o : list) {
TaskInfoData taskInfo = (TaskInfoData) o;
Assert.assertNotEquals(taskInfo.getTaskId(), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getType()), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getStartTime()), -1);
Assert.assertNotEquals(String.valueOf(taskInfo.getDisposeTime()), -1);
Assert.assertNotEquals(taskInfo.getDisposeIp().length(), 0);
Assert.assertNotNull(taskInfo.getFlowAttack());
Assert.assertNotNull(taskInfo.getFlowClean());
Assert.assertEquals(status, "0");
Assert.assertEquals(message, "成功");
}
} else {
Assert.assertNotEquals(status, "0");
Assert.assertNotEquals(message, "成功");
}
}
}
}
}
@Test @Test
public void t9_getNodeAllTask() throws Exception { public void t9_getNodeAllTask() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION); reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders String taskAll = mockMvc.perform(MockMvcRequestBuilders
.post("/information/all_task") .post("/information/all_task")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -1238,6 +1243,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
.getContentAsString(); .getContentAsString();
} }
@Test @Test
public void t9_getNodeAllTaskAll() throws Exception { public void t9_getNodeAllTaskAll() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()