From 684a56d5c827375d35668e7d25bf6bf552ec70ad Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Mon, 7 Sep 2020 18:09:01 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=85=A8=E9=83=A8=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=8D=95=E6=B5=8B=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=90=AF=E5=8A=A8=E5=A4=9AIP=E5=A4=84=E7=BD=AE?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/protocol/task/TaskStartMulRsp.java | 2 + .../controller/DisposeTaskControllerTest.java | 92 +++++++++++++++---- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartMulRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartMulRsp.java index 06c8f2c5..c83861a2 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartMulRsp.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartMulRsp.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.List; @@ -14,6 +15,7 @@ import java.util.List; */ @Data @Builder +@NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) public class TaskStartMulRsp { diff --git a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java index ceffb9c5..85108a09 100644 --- a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java +++ b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java @@ -8,19 +8,21 @@ import com.dispose.common.DisposeTaskStatus; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; import com.dispose.common.ProtoCryptoType; -import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; import com.dispose.pojo.dto.protocol.base.BaseIdResp; import com.dispose.pojo.dto.protocol.base.IdArraysReq; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; -import com.dispose.pojo.dto.protocol.task.TaskStartReq; -import com.dispose.pojo.dto.protocol.task.TaskStartRsp; -import com.dispose.pojo.dto.protocol.task.TaskStopRsp; +import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq; +import com.dispose.pojo.dto.protocol.task.*; import com.dispose.pojo.entity.DisposeTask; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.DisposeDeviceManagerService; +import com.dispose.service.DisposeTaskService; import com.dispose.test.Global.InitTestEnvironment; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.pagehelper.PageInfo; import jodd.net.HttpStatus; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; @@ -71,15 +73,20 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { @Resource private ObjectMapper objectMapper; /** - * The Dispose task manager. + * The Dispose task mapper. */ @Resource - private DisposeTaskMapper disposeTaskManager; + private DisposeTaskMapper disposeTaskMapper; /** - * The Dispose device mapper. + * The Dispose device manager service. */ @Resource - private DisposeDeviceMapper disposeDeviceMapper; + private DisposeDeviceManagerService disposeDeviceManagerService; + /** + * The Dispose task service. + */ + @Resource + private DisposeTaskService disposeTaskService; /** * A 1 start task protocol resp dto. @@ -89,7 +96,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { @Test public void a1_startTask() throws Exception { TaskStartReq req = TaskStartReq.builder() - .id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId())) + .id(String.valueOf(disposeDeviceManagerService.getAllDisposeDevice().get(0).getId())) .type(DisposeCapacityType.CLEANUP.getValue()) .disposeIp("192.168.100.100") .disposeTime(60) @@ -129,7 +136,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { Assert.assertNotNull(rspInfo.getMsgContent().getMessage()); Assert.assertNotNull(rspInfo.getMsgContent().getTaskId()); - disposeTaskManager.selectAll().forEach(v -> { + disposeTaskMapper.selectAll().forEach(v -> { if (v.getDeviceId().equals(Long.valueOf(req.getId())) && v.getDisposeIp().equals(req.getDisposeIp()) && v.getAttackType().equals((long) DDoSAttackType.ACK_FLOOD.getValue())) { @@ -146,7 +153,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { */ @Test public void a2_startTaskExisted() throws Exception { - DisposeTask disposeTask = disposeTaskManager.selectAll().get(0); + DisposeTask disposeTask = disposeTaskMapper.selectAll().get(0); TaskStartReq req = TaskStartReq.builder() .id(String.valueOf(disposeTask.getDeviceId())) @@ -207,9 +214,9 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { List taskIds = new ArrayList<>(); List runTaskIds = new ArrayList<>(); - disposeTaskManager.selectAll().forEach(v -> taskIds.add(String.valueOf(v.getId()))); + disposeTaskMapper.selectAll().forEach(v -> taskIds.add(String.valueOf(v.getId()))); - disposeTaskManager.selectAll().forEach(v -> { + disposeTaskMapper.selectAll().forEach(v -> { if (v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW || v.getCurrentStatus() == DisposeTaskStatus.TASK_STARTING || v.getCurrentStatus() == DisposeTaskStatus.TASK_STARTED) { @@ -276,7 +283,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { String[] mulDisposeIp = {"192.168.5.2", "192.168.5.3"}; TaskStartReq req = TaskStartReq.builder() - .id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId())) + .id(String.valueOf(disposeDeviceManagerService.getAllDisposeDevice().get(0).getId())) .type(DisposeCapacityType.CLEANUP.getValue()) .mulDisposeIp(mulDisposeIp) .disposeTime(60) @@ -303,24 +310,71 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { .getResponse() .getContentAsString(); - ProtocolRespDTO> rspInfo = objectMapper.readValue(ret, - new TypeReference>>() { + + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ret)); + ProtocolRespDTO rspInfo = objectMapper.readValue(ret, + new TypeReference>() { }); verifyRespProtocol(rspInfo); log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); Assert.assertNotNull(rspInfo.getMsgContent()); - rspInfo.getMsgContent().forEach(v->{ + rspInfo.getMsgContent().getItems().forEach(v -> { Assert.assertNotNull(v.getStatus()); Assert.assertNotNull(v.getMessage()); Assert.assertNotNull(v.getDisposeIp()); - if(v.getStatus() == ErrorCode.ERR_OK.getCode() || - v.getStatus() == ErrorCode.ERR_TASKRUNNING.getCode()){ + if (v.getStatus() == ErrorCode.ERR_OK.getCode() || + v.getStatus() == ErrorCode.ERR_TASKRUNNING.getCode()) { Assert.assertNotNull(v.getTaskId()); Assert.assertNotNull(v.getExpireTime()); } }); } + + /** + * A 5 gets all dispose task. + * + * @throws Exception the exception + */ + @Test + public void a5_getAllDisposeTask() throws Exception { + BasePagesGetReq req = BasePagesGetReq.builder() + .startPage(1) + .pageSize(20) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO<>(); + + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode()); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(req); + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/task/taskList") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + getLoginToken()) + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(HttpStatus.ok().status())) + .andReturn() + .getResponse() + .getContentAsString(); + + ProtocolRespDTO rspInfo = objectMapper.readValue(ret, + new TypeReference>() { + }); + + verifyRespProtocol(rspInfo); + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); + + Assert.assertNotNull(rspInfo.getMsgContent()); + Assert.assertTrue(rspInfo.getMsgContent().getCurPageNumber() <= req.getPageSize()); + Assert.assertEquals(rspInfo.getMsgContent().getPageSize(), req.getPageSize()); + + MulReturnType, List> result = disposeTaskService.getPageDisposeTask(req.getStartPage(), req.getPageSize()); + Assert.assertTrue(rspInfo.getMsgContent().getTotalItems() >= result.getSecondParam().size()); + } }