From c30e609eb477d24476cde8b8d504852189c87897 Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Fri, 4 Sep 2020 10:48:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E8=83=BD=E5=8A=9B=E9=AA=8C=E8=AF=81=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DisposeAbilityRouterServiceTest.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java index 22f5b76e..6c1bd3cc 100644 --- a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java @@ -1,12 +1,12 @@ package com.dispose.test.service; -import com.dispose.common.DisposeDeviceType; -import com.dispose.common.ErrorCode; -import com.dispose.common.HttpType; -import com.dispose.common.ObjectStatus; +import com.dispose.common.*; import com.dispose.manager.DisposeDeviceManager; import com.dispose.mapper.DisposeDeviceMapper; +import com.dispose.mapper.DisposeTaskMapper; +import com.dispose.pojo.entity.DisposeCapacity; import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DisposeAbilityRouterService; @@ -66,6 +66,11 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { */ @Resource private DisposeDeviceManager disposeDeviceManager; + /** + * The dispose device manager. + */ + @Resource + private DisposeTaskMapper disposeTaskMapper; /** * The Object mapper. */ @@ -269,4 +274,30 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { } }); } + /** + * A 9 verify dispose capacity test. + */ + @Test + public void a9_verifyDisposeCapacityTest(){ + long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + DisposeCapacityType capacityType = DisposeCapacityType.CLEANUP; + String disposeIp = disposeTaskMapper.selectAll().get(0).getDisposeIp(); + + ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity(deviceId,disposeIp,capacityType); + if(err == ErrorCode.ERR_NOSUCHDEVICE){ + Assert.assertNotEquals(deviceId,-1L); + for (DisposeDevice d : disposeDeviceMapper.selectAll()) { + Assert.assertNotEquals(java.util.Optional.ofNullable(d.getId()),deviceId); + } + }else if(err == ErrorCode.ERR_NOSUCHTYPE){ + Assert.assertNotEquals((int) capacityType.getValue(), 0); + Assert.assertNotEquals((int) capacityType.getValue(), 1); + Assert.assertNotEquals((int) capacityType.getValue(), 2); + Assert.assertNotEquals((int) capacityType.getValue(), 3); + } + else if(err == ErrorCode.ERR_IPNODEVICE) + { + disposeTaskMapper.selectAll().forEach(i -> Assert.assertNotEquals(i.getDisposeIp(), disposeIp)); + } + } } From 11e017a018af3621e919183ced55a8659f0da5f4 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Fri, 4 Sep 2020 15:21:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?OCT=20REM:=201.=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E6=A0=A1=E9=AA=8C=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/pojo/dto/protocol/task/TaskStartReq.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartReq.java b/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartReq.java index de752470..416e863f 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartReq.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/task/TaskStartReq.java @@ -58,7 +58,6 @@ public class TaskStartReq { * The Dispose time. */ @NotNull(message = "disposeTime 处置时间不能为空", groups = ValidGroups.TaskStartReqCommonValid.class) - @ValidSplitPageSize(groups = ValidGroups.TaskStartReqCommonValid.class) private Integer disposeTime; /** * The Flow direction. From beb94d2195e5dc4e4bd3315573aac3ebb2d12c4d Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Fri, 4 Sep 2020 18:14:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?OCT=20REM:=201.=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/device/info/GetAreaInfoRsp.java | 2 +- .../DisposeDeviceManagerServiceTest.java | 84 +++------------- .../test/service/DisposeTaskServiceTest.java | 98 +++++++++++++++---- 3 files changed, 91 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/info/GetAreaInfoRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/info/GetAreaInfoRsp.java index aa7aaa99..f0130b63 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/device/info/GetAreaInfoRsp.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/info/GetAreaInfoRsp.java @@ -20,7 +20,7 @@ import java.util.List; @Data @Builder @AllArgsConstructor -@JsonPropertyOrder({"taskId", "disposeIp", "expireTime", "status", "message"}) +@JsonPropertyOrder({"items", "status", "message"}) @JsonInclude(JsonInclude.Include.NON_NULL) public class GetAreaInfoRsp extends BaseRespStatus { /** diff --git a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java b/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java index 788ac450..f9e523e3 100644 --- a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java @@ -135,37 +135,15 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { public void a2_upgradeDisposeDeviceTest() throws JsonProcessingException { List devList = new ArrayList<>(); - for (int i = 1; i < 3; i++) { - String ipAddr = "192.168.0." + i; + disposeDeviceManagerService.getAllDisposeDevice().forEach(v -> { + v.setDeviceName("测试清洗设备"); + v.setManufacturer("Unknown"); - DisposeDevice dev = DisposeDevice.builder() - .ipAddr(ipAddr) - .ipPort("") - .deviceType(DisposeDeviceType.DPTECH_UMC) - .areaCode(0) - .deviceName("中移杭研实验室迪普清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .userName("admin") - .password("UMCAdministrator") - .urlPath("UMC/service/AbnormalFlowCleaningService") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); - - devList.add(dev); - } - - disposeDeviceManagerService.addDisposeDevice(devList); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); - - devList.forEach(dev -> { - dev.setDeviceName("测试清洗设备"); - dev.setManufacturer("Unknown"); + devList.add(v); }); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); + List> ret = disposeDeviceManagerService.upgradeDisposeDevice(devList); ret.forEach(v -> { @@ -184,33 +162,9 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { */ @Test public void a3_removeDisposeDeviceTest() throws JsonProcessingException { - List devList = new ArrayList<>(); List removeIds = new ArrayList<>(); + List devList = disposeDeviceManagerService.getAllDisposeDevice(); - for (int i = 1; i < 3; i++) { - String ipAddr = "192.168.0." + i; - - DisposeDevice dev = DisposeDevice.builder() - .ipAddr(ipAddr) - .ipPort("") - .deviceType(DisposeDeviceType.DPTECH_UMC) - .areaCode(0) - .deviceName("中移杭研实验室迪普清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .userName("admin") - .password("UMCAdministrator") - .urlPath("UMC/service/AbnormalFlowCleaningService") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); - - devList.add(dev); - } - - disposeDeviceManagerService.addDisposeDevice(devList); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); devList.forEach(dev -> removeIds.add(dev.getId())); @@ -232,19 +186,18 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { * A 4 get all dispose device test. */ @Test - public void a4_getAllDisposeDeviceTest(){ + public void a4_getPageDisposeDeviceTest() { List devs = disposeDeviceMapper.selectAll(); for (int i = 1; i < 5; i++) { - Integer startPage = i; - Integer pageSize = i * 2; + int startPage = i; + int pageSize = i * 2; MulReturnType, List> ret = disposeDeviceManagerService.getPageDisposeDevice(startPage, pageSize); PageInfo pageInfo = ret.getFirstParam(); - List deviceList = ret.getSecondParam(); - Assert.assertEquals(pageInfo.getPageNum(), (long) startPage); - Assert.assertEquals(pageInfo.getPageSize(), (long) pageSize); + Assert.assertEquals(pageInfo.getPageNum(), startPage); + Assert.assertEquals(pageInfo.getPageSize(), pageSize); //数据库设备信息数据量比较大 if (devs.size() >= (startPage * pageSize)) { @@ -256,13 +209,6 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { Assert.assertTrue(pageInfo.isIsFirstPage()); Assert.assertFalse(pageInfo.isHasPreviousPage()); } - - if ((deviceList.size() - startPage * pageSize) / pageSize >= 0) { - Assert.assertNotEquals(deviceList.size(), 0); - } else { - Assert.assertEquals(deviceList.size(), 0); - } - } else { if (pageInfo.getPageNum() != 1) { Assert.assertFalse(pageInfo.isIsFirstPage()); @@ -273,12 +219,6 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { Assert.assertFalse(pageInfo.isHasNextPage()); } - if ((deviceList.size() - startPage * pageSize) / pageSize >= 0) { - Assert.assertNotEquals(deviceList.size(), 0); - } else { - Assert.assertEquals(deviceList.size(), 0); - } - Assert.assertFalse(pageInfo.isHasNextPage()); } } diff --git a/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java b/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java index aefb8a7d..f0761ca5 100644 --- a/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java @@ -1,10 +1,8 @@ package com.dispose.test.service; import com.dispose.common.*; +import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeTaskManager; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.mapper.UserAccountMapper; import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DisposeTaskService; @@ -54,15 +52,10 @@ public class DisposeTaskServiceTest extends InitTestEnvironment { @Resource private ObjectMapper objectMapper; /** - * The user account mapper. + * The Dispose device manager. */ @Resource - private UserAccountMapper userAccountMapper; - /** - * The Dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; + private DisposeDeviceManager disposeDeviceManager; /** * The Dispose task manager. */ @@ -73,11 +66,6 @@ public class DisposeTaskServiceTest extends InitTestEnvironment { */ @Resource private DisposeTaskService disposeTaskService; - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; /** * User login test. @@ -101,8 +89,8 @@ public class DisposeTaskServiceTest extends InitTestEnvironment { public void a1_createTask() throws JsonProcessingException { // 构成处置任务参数 DisposeTask newTask = DisposeTask.builder() - .deviceId(disposeDeviceMapper.selectAll().get(0).getId()) - .accountId(userAccountMapper.selectAll().get(0).getId()) + .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) + .accountId(1L) .disposeCapacity(DisposeCapacityType.CLEANUP) .disposeIp("192.168.5.2") .planEndTime("30") @@ -130,12 +118,81 @@ public class DisposeTaskServiceTest extends InitTestEnvironment { newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); } + + /** + * creat task mul return type. + */ + @Test + public void a2_stopTask(){ + DisposeTask newTask = DisposeTask.builder() + .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) + .accountId(1L) + .disposeCapacity(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.5.2") + .planEndTime("30") + .flowDirection(NetflowDirection.DIRECTION_IN) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) + .flowBandWidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .build(); + + disposeTaskService.createTask(newTask); + + disposeTaskManager.getExpiredTasks().forEach(v->{ + MulReturnType ret = disposeTaskService.stopTask(v.getId()); + + Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_TASKNOTRUNNING); + Assert.assertNull(ret.getSecondParam()); + }); + + + disposeTaskManager.getNewDisposeTasks().forEach(k->{ + MulReturnType ret = disposeTaskService.stopTask(k.getId()); + + if(ret.getFirstParam() == ErrorCode.ERR_OK){ + Assert.assertNotNull(ret.getSecondParam()); + Assert.assertEquals(disposeTaskManager.getDisposeTaskById(k.getId()).getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED); + }else{ + Assert.assertNull(ret.getSecondParam()); + } + }); + } + + /** + * get dispose task. + */ + @Test + public void a3_getDisposeTask(){ + DisposeTask newTask = DisposeTask.builder() + .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) + .accountId(1L) + .disposeCapacity(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.10.2") + .planEndTime("60") + .flowDirection(NetflowDirection.DIRECTION_IN) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) + .flowBandWidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .build(); + + disposeTaskService.createTask(newTask); + + disposeTaskManager.getNewDisposeTasks().forEach(v->{ + DisposeTask task = disposeTaskService.getDisposeTask(v.getId()); + Assert.assertNotNull(task); + Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_NEW); + }); + } + + /** * stop task test mul return type. */ @Test - public void a2_stopTaskTest() { - Long taskId = disposeTaskMapper.selectAll().get(0).getId(); + public void a4_stopTaskTest() { + if(disposeTaskManager.getNewDisposeTasks().size() == 0){ + return; + } + + Long taskId = disposeTaskManager.getNewDisposeTasks().get(0).getId(); MulReturnType ret = disposeTaskService.stopTask(taskId-1); if (ret.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) { @@ -143,7 +200,8 @@ public class DisposeTaskServiceTest extends InitTestEnvironment { } ret = disposeTaskService.stopTask(taskId); - DisposeTask task = disposeTaskMapper.getDisposeTaskById(taskId); + + DisposeTask task = disposeTaskManager.getDisposeTaskById(taskId); if (ret.getFirstParam() == ErrorCode.ERR_TASKNOTRUNNING) { Assert.assertNotNull(task);