REM:
1. 修正启动处置任务接口、停止指定处置任务接口、停止某处置IP的处置任务接口、停止指定能力节点的全部处置任务接口和停止全部处置任务接口响应报文中taskId不为空的问题
2. 编写动处置任务接口、停止指定处置任务接口、停止某处置IP的处置任务接口、停止指定能力节点的全部处置任务接口和停止全部处置任务接口响应报文中内容字段的检验代码
This commit is contained in:
chenlinghy 2020-05-07 15:09:06 +08:00
parent 7253b90b5d
commit 9ab5230d67
2 changed files with 350 additions and 122 deletions

View File

@ -5,6 +5,7 @@ import com.dispose.common.ErrorCode;
import com.dispose.common.FlowDirection; import com.dispose.common.FlowDirection;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.manager.TaskCacheManager; import com.dispose.manager.TaskCacheManager;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.dto.ProtocolReqDTO; import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO; import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
@ -75,6 +76,12 @@ public class DisposeTaskController {
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
/**
* The Dispose task manager.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/** /**
* Task start protocol resp dto. * Task start protocol resp dto.
* *
@ -115,6 +122,9 @@ public class DisposeTaskController {
TaskInfoDetail tf = taskCacheManager.getTaskById(ret.getSecondParam()); TaskInfoDetail tf = taskCacheManager.getTaskById(ret.getSecondParam());
rspInfo.setId(String.valueOf(tf.getDeviceId())); rspInfo.setId(String.valueOf(tf.getDeviceId()));
rspInfo.setTaskId(String.valueOf(ret.getSecondParam())); rspInfo.setTaskId(String.valueOf(ret.getSecondParam()));
} else {
rspInfo.setId("-1");
rspInfo.setTaskId("-1");
} }
rspInfo.setStatus(ret.getFirstParam().getCode()); rspInfo.setStatus(ret.getFirstParam().getCode());
@ -157,7 +167,13 @@ public class DisposeTaskController {
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v)); List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v));
if (ret.size() == 0) { if (ret.size() == 0) {
taskData.setId(v); TaskInfoDetail taskDetail = disposeTaskMapper.getTaskInfoById(Long.valueOf(v));
if (taskDetail != null) {
taskData.setId(String.valueOf(taskDetail.getDeviceId()));
} else {
taskData.setId("-1");
}
taskData.setTaskId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
rspInfo.getItems().add(taskData); rspInfo.getItems().add(taskData);
@ -213,6 +229,7 @@ public class DisposeTaskController {
if (ret.size() == 0) { if (ret.size() == 0) {
taskData.setId(v.getId()); taskData.setId(v.getId());
taskData.setTaskId("-1");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
rspInfo.getItems().add(taskData); rspInfo.getItems().add(taskData);
@ -268,6 +285,7 @@ public class DisposeTaskController {
if (ret.size() == 0) { if (ret.size() == 0) {
taskData.setId("-1"); taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
rspInfo.getItems().add(taskData); rspInfo.getItems().add(taskData);
@ -322,6 +340,7 @@ public class DisposeTaskController {
if (ret.size() == 0) { if (ret.size() == 0) {
taskData.setId("-1"); taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
rspInfo.getItems().add(taskData); rspInfo.getItems().add(taskData);

View File

@ -8,16 +8,16 @@ import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.dto.ProtocolReqDTO; import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
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.common.TaskInfoDetail;
import com.dispose.pojo.vo.task.GetTaskReq; import com.dispose.pojo.vo.task.*;
import com.dispose.pojo.vo.task.StartTaskReq;
import com.dispose.pojo.vo.task.StopTaskData;
import com.dispose.pojo.vo.task.StopTaskReq;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -29,6 +29,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 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.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -111,13 +112,14 @@ public class TaskControllerTest extends InitTestEnvironment {
.disposeTime(60) .disposeTime(60)
.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 taskStart = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -127,6 +129,26 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
String msgContent = verifyRep(taskStart, reqTimeStamp);
System.out.println("msgContent=" + msgContent);
//将json字符串转为StartTaskRsp类
StartTaskRsp startTaskRsp = objectMapper.readValue(msgContent, StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotEquals(String.valueOf(startTaskRsp.getExpireTime()), -1);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertEquals(String.valueOf(startTaskRsp.getStatus()), "0");
Assert.assertEquals(startTaskRsp.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(startTaskRsp.getStatus()), "0");
Assert.assertNotEquals(startTaskRsp.getMessage(), "成功");
}
} }
/** /**
@ -140,13 +162,14 @@ public class TaskControllerTest extends InitTestEnvironment {
.taskId(new String[]{String.valueOf(getExistsTaskId()), "2"}) .taskId(new String[]{String.valueOf(getExistsTaskId()), "2"})
.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 taskStop = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop") .post("/task/stop")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -156,6 +179,42 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.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 msgContent = verifyRep(taskStop, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskStopRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
} }
/** /**
@ -176,13 +235,14 @@ public class TaskControllerTest extends InitTestEnvironment {
reqData.setItems(new ArrayList<>()); reqData.setItems(new ArrayList<>());
reqData.getItems().add(itemData); reqData.getItems().add(itemData);
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 taskStopByIp = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_ip") .post("/task/stop_ip")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -192,8 +252,45 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.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 msgContent = verifyRep(taskStopByIp, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
} }
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
}
@Test @Test
public void t3_stopAllNodeIpTask() throws Exception { public void t3_stopAllNodeIpTask() throws Exception {
StopTaskData itemData = StopTaskData.builder() StopTaskData itemData = StopTaskData.builder()
@ -207,13 +304,14 @@ public class TaskControllerTest extends InitTestEnvironment {
reqData.setItems(new ArrayList<>()); reqData.setItems(new ArrayList<>());
reqData.getItems().add(itemData); reqData.getItems().add(itemData);
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 taskStopByIp = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_ip") .post("/task/stop_ip")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -223,8 +321,45 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.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 msgContent = verifyRep(taskStopByIp, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
} }
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
}
/** /**
* T 4 stop node task. * T 4 stop node task.
* *
@ -234,7 +369,7 @@ public class TaskControllerTest extends InitTestEnvironment {
public void t4_stopNodeTask() throws Exception { public void t4_stopNodeTask() throws Exception {
StopTaskData itemData = StopTaskData.builder() StopTaskData itemData = StopTaskData.builder()
.type(DeviceCapacity.CLEANUP.getCode()) .type(DeviceCapacity.CLEANUP.getCode())
.id("210") .id("418")
.build(); .build();
StopTaskReq reqData = new StopTaskReq(); StopTaskReq reqData = new StopTaskReq();
@ -242,13 +377,14 @@ public class TaskControllerTest extends InitTestEnvironment {
reqData.setItems(new ArrayList<>()); reqData.setItems(new ArrayList<>());
reqData.getItems().add(itemData); reqData.getItems().add(itemData);
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 taskStopByNode = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node") .post("/task/stop_node")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -258,6 +394,42 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.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 msgContent = verifyRep(taskStopByNode, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
} }
/** /**
@ -271,13 +443,14 @@ public class TaskControllerTest extends InitTestEnvironment {
.type(DeviceCapacity.CLEANUP.getCode()) .type(DeviceCapacity.CLEANUP.getCode())
.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 taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all") .post("/task/stop_all")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken()) .header("Authorization", "Bearer " + getLogToken())
@ -287,6 +460,42 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn() .andReturn()
.getResponse() .getResponse()
.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 msgContent = verifyRep(taskStopAll, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(String.valueOf(task.getStatus()), "0");
Assert.assertEquals(task.getMessage(), "成功");
} else {
Assert.assertNotEquals(String.valueOf(task.getStatus()), "0");
Assert.assertNotEquals(task.getMessage(), "成功");
}
if (task.getType() != null) {
Assert.assertNotEquals(String.valueOf(task.getType()), -1);
}
if (task.getDisposeIp() != null) {
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
if (task.getDisposeTime() != null) {
Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1);
}
}
} }
/** /**