OCT
REM: 1. 修正启动处置任务接口、停止指定处置任务接口、停止某处置IP的处置任务接口、停止指定能力节点的全部处置任务接口和停止全部处置任务接口响应报文中taskId不为空的问题 2. 编写动处置任务接口、停止指定处置任务接口、停止某处置IP的处置任务接口、停止指定能力节点的全部处置任务接口和停止全部处置任务接口响应报文中内容字段的检验代码
This commit is contained in:
parent
7253b90b5d
commit
9ab5230d67
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -105,28 +106,49 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t1_startTask() throws Exception {
|
public void t1_startTask() throws Exception {
|
||||||
StartTaskReq reqData = StartTaskReq.builder()
|
StartTaskReq reqData = StartTaskReq.builder()
|
||||||
.id(-1)
|
.id(-1)
|
||||||
.type(DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.disposeIp("192.168.5.2")
|
.disposeIp("192.168.5.2")
|
||||||
.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())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.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(), "成功");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,25 +159,62 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t2_stopTask() throws Exception {
|
public void t2_stopTask() throws Exception {
|
||||||
IDArrayReq reqData = IDArrayReq.builder()
|
IDArrayReq reqData = IDArrayReq.builder()
|
||||||
.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())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,34 +225,72 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t3_stopNodeIpTask() throws Exception {
|
public void t3_stopNodeIpTask() throws Exception {
|
||||||
StopTaskData itemData = StopTaskData.builder()
|
StopTaskData itemData = StopTaskData.builder()
|
||||||
.disposeIp("192.168.1.1")
|
.disposeIp("192.168.1.1")
|
||||||
.type(DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.id("210")
|
.id("210")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
StopTaskReq reqData = new StopTaskReq();
|
StopTaskReq reqData = new StopTaskReq();
|
||||||
|
|
||||||
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())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.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.
|
||||||
*
|
*
|
||||||
|
@ -233,31 +368,68 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
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();
|
||||||
|
|
||||||
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())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.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,22 +443,59 @@ 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())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -297,9 +506,9 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t6_getNodeAllTask() throws Exception {
|
public void t6_getNodeAllTask() throws Exception {
|
||||||
GetTaskReq reqData = GetTaskReq.builder()
|
GetTaskReq reqData = GetTaskReq.builder()
|
||||||
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
|
.id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
|
||||||
.type(0)
|
.type(0)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
@ -308,15 +517,15 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/task/get_node")
|
.post("/task/get_node")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", "Bearer " + getLogToken())
|
.header("Authorization", "Bearer " + getLogToken())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
.getResponse()
|
.getResponse()
|
||||||
.getContentAsString();
|
.getContentAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -327,9 +536,9 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t6_getNodeAllTaskAll() throws Exception {
|
public void t6_getNodeAllTaskAll() throws Exception {
|
||||||
GetTaskReq reqData = GetTaskReq.builder()
|
GetTaskReq reqData = GetTaskReq.builder()
|
||||||
.id(new String[]{})
|
.id(new String[]{})
|
||||||
.type(2)
|
.type(2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
@ -338,15 +547,15 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/task/get_node")
|
.post("/task/get_node")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", "Bearer " + getLogToken())
|
.header("Authorization", "Bearer " + getLogToken())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
.getResponse()
|
.getResponse()
|
||||||
.getContentAsString();
|
.getContentAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,8 +566,8 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t7_getAllTask() throws Exception {
|
public void t7_getAllTask() throws Exception {
|
||||||
IDArrayReq reqData = IDArrayReq.builder()
|
IDArrayReq reqData = IDArrayReq.builder()
|
||||||
.taskId(new String[]{String.valueOf(getExistsTaskId()), "123"})
|
.taskId(new String[]{String.valueOf(getExistsTaskId()), "123"})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
@ -367,15 +576,15 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/task/get")
|
.post("/task/get")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", "Bearer " + getLogToken())
|
.header("Authorization", "Bearer " + getLogToken())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
.getResponse()
|
.getResponse()
|
||||||
.getContentAsString();
|
.getContentAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -386,8 +595,8 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t7_getAllTaskAll() throws Exception {
|
public void t7_getAllTaskAll() throws Exception {
|
||||||
IDArrayReq reqData = IDArrayReq.builder()
|
IDArrayReq reqData = IDArrayReq.builder()
|
||||||
.taskId(new String[]{})
|
.taskId(new String[]{})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
@ -396,14 +605,14 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/task/get")
|
.post("/task/get")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", "Bearer " + getLogToken())
|
.header("Authorization", "Bearer " + getLogToken())
|
||||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(200))
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
.getResponse()
|
.getResponse()
|
||||||
.getContentAsString();
|
.getContentAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue