Merge remote-tracking branch 'origin/v2.0.0_dev' into v2.0.0_dev

This commit is contained in:
HuangXin 2020-09-04 21:00:10 +08:00
commit c125e5fa43
4 changed files with 125 additions and 97 deletions

View File

@ -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.

View File

@ -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));
}
}
}

View File

@ -135,37 +135,15 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
public void a2_upgradeDisposeDeviceTest() throws JsonProcessingException {
List<DisposeDevice> 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<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.upgradeDisposeDevice(devList);
ret.forEach(v -> {
@ -184,33 +162,9 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
*/
@Test
public void a3_removeDisposeDeviceTest() throws JsonProcessingException {
List<DisposeDevice> devList = new ArrayList<>();
List<Long> removeIds = new ArrayList<>();
List<DisposeDevice> 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<DisposeDevice> 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<PageInfo<DisposeDevice>, List<DisposeDevice>> ret = disposeDeviceManagerService.getPageDisposeDevice(startPage, pageSize);
PageInfo<DisposeDevice> pageInfo = ret.getFirstParam();
List<DisposeDevice> 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());
}
}

View File

@ -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<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(v.getId());
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_TASKNOTRUNNING);
Assert.assertNull(ret.getSecondParam());
});
disposeTaskManager.getNewDisposeTasks().forEach(k->{
MulReturnType<ErrorCode, DisposeTask> 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<ErrorCode, DisposeTask> 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);