From c40e1154aefd92f0485bb53999b0cbec5b1533ab Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 2 Sep 2020 16:14:21 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=A4=84=E7=BD=AE=E5=A4=9A=E4=BB=BB=E5=8A=A1=E6=8E=A5?= =?UTF-8?q?=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 --- .../controller/DisposeTaskController.java | 1 - .../controller/DisposeTaskControllerTest.java | 63 ++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index bd943f64..3a906120 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -173,7 +173,6 @@ public class DisposeTaskController { rspInfo.setExpireTime(ret.getSecondParam().getPlanEndTime()); } - rspInfo.setStatus(ret.getFirstParam().getCode()); rspInfo.setMessage(new String[]{ret.getFirstParam().getMsg()}); diff --git a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java index 08f6a3d6..ceffb9c5 100644 --- a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java +++ b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java @@ -15,6 +15,7 @@ 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.entity.DisposeTask; import com.dispose.test.Global.InitTestEnvironment; @@ -90,7 +91,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { TaskStartReq req = TaskStartReq.builder() .id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId())) .type(DisposeCapacityType.CLEANUP.getValue()) - .disposeIp("192.168.5.3") + .disposeIp("192.168.100.100") .disposeTime(60) .flowDirection(NetflowDirection.DIRECTION_IN.getValue()) .attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()}) @@ -148,7 +149,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { DisposeTask disposeTask = disposeTaskManager.selectAll().get(0); TaskStartReq req = TaskStartReq.builder() - .id(String.valueOf(disposeTask.getId())) + .id(String.valueOf(disposeTask.getDeviceId())) .type(disposeTask.getDisposeCapacity().getValue()) .disposeIp(disposeTask.getDisposeIp()) .disposeTime(60) @@ -264,4 +265,62 @@ public class DisposeTaskControllerTest extends InitTestEnvironment { } } } + + /** + * A 4 stop task protocol resp dto. + * + * @throws Exception the exception + */ + @Test + public void a4_startTaskMulIp() throws Exception { + String[] mulDisposeIp = {"192.168.5.2", "192.168.5.3"}; + + TaskStartReq req = TaskStartReq.builder() + .id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId())) + .type(DisposeCapacityType.CLEANUP.getValue()) + .mulDisposeIp(mulDisposeIp) + .disposeTime(60) + .flowDirection(NetflowDirection.DIRECTION_IN.getValue()) + .attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()}) + .flowBandwidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .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/startMulIp") + .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()); + rspInfo.getMsgContent().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()){ + Assert.assertNotNull(v.getTaskId()); + Assert.assertNotNull(v.getExpireTime()); + } + }); + } }