From 052f0de95065055877731022fc631f7639556d0a Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 26 Aug 2020 10:40:28 +0800 Subject: [PATCH 1/4] =?UTF-8?q?OCT=20REM:=201.=20=E7=BC=96=E5=86=99manager?= =?UTF-8?q?=E5=B1=82=E8=AE=BE=E5=A4=87=E4=BB=BB=E5=8A=A1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/manager/DeviceTaskManagerTest.java | 262 ++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java diff --git a/src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java b/src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java new file mode 100644 index 00000000..6a93461a --- /dev/null +++ b/src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java @@ -0,0 +1,262 @@ +package com.dispose.test.manager; + +import com.dispose.common.DisposeTaskStatus; +import com.dispose.common.NetflowDirection; +import com.dispose.manager.DeviceTaskManager; +import com.dispose.mapper.DeviceTaskMapper; +import com.dispose.mapper.DisposeTaskMapper; +import com.dispose.pojo.entity.DeviceTask; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +/** + * The type Dispose device manager test. + * + * @author + */ +@RunWith(SpringRunner.class) +@Slf4j +@SpringBootTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Transactional +@Rollback +public class DeviceTaskManagerTest { + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + + /** + * The device task mapper. + */ + @Resource + private DeviceTaskMapper deviceTaskMapper; + /** + * The device task manager. + */ + @Resource + private DeviceTaskManager deviceTaskManager; + /** + * The Dispose task mapper. + */ + @Resource + private DisposeTaskMapper disposeTaskMapper; + + /** + * A 1 add dispose device task info boolean. + */ + @Test + public void a1_addDisposeDeviceTaskInfo() { + Long deviceId = disposeTaskMapper.selectAll().get(0).getDeviceId(); + Long taskId = disposeTaskMapper.selectAll().get(0).getId(); + + // 如果已经存在相同任务,不再添加重复任务 + deviceTaskMapper.selectAll().forEach(v -> { + boolean result = deviceTaskManager.addDisposeDeviceTaskInfo(v.getTaskId(), v.getDeviceId(), v.getTaskAttackType()); + log.info("result-->{}", result); + Assert.assertTrue(result); + }); + + + DeviceTask deviceTask = DeviceTask.builder() + .taskId(taskId) + .deviceId(deviceId) + .taskAttackType(10737508815L) + .build(); + + boolean addResult = deviceTaskManager.addDisposeDeviceTaskInfo(deviceTask.getTaskId(), deviceTask.getDeviceId(), + deviceTask.getTaskAttackType()); + log.info("addResult-->{}", addResult); + Assert.assertTrue(addResult); + } + + /** + * A 2 gets new dispose device task info. + */ + @Test + public void a2_getNewDisposeDeviceTaskInfo() throws JsonProcessingException { + List deviceTaskList = deviceTaskMapper.selectAll(); + + long newNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue()) + || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue())).count(); + log.info("newNumber-->{}", newNumber); + + if (newNumber > 0) { + List newTask = deviceTaskManager.getNewDisposeDeviceTaskInfo(); + log.info("newTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask)); + + Assert.assertNotNull(newTask); + Assert.assertNotEquals(newTask.size(), 0); + } + } + + /** + * A 3 gets started dispose device task info. + */ + @Test + public void a3_getStartedDisposeDeviceTaskInfo() throws JsonProcessingException { + List deviceTaskList = deviceTaskMapper.selectAll(); + + long startedNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue()) + || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue() + || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTED.getValue()))).count(); + log.info("startedNumber-->{}", startedNumber); + + if (startedNumber > 0) { + List startedTask = deviceTaskManager.getStartedDisposeDeviceTaskInfo(); + log.info("startedTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(startedTask)); + + Assert.assertNotNull(startedTask); + Assert.assertNotEquals(startedTask.size(), 0); + } + } + + /** + * A 4 change dispose device task info status. + */ + @Test + public void a4_changeDisposeDeviceTaskInfoStatus() { + DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); + + for (DisposeTaskStatus status : DisposeTaskStatus.values() + ) { + boolean result = deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), status); + Assert.assertTrue(result); + Assert.assertEquals(Long.valueOf(status.getValue()), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getStatus()); + } + } + + /** + * A 5 exec attack type. + */ + @Test + public void a5_execAttackType() { + DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); + + //sets exec attack type + for (NetflowDirection nf : NetflowDirection.values() + ) { + for (long i = 10737508814L; i <= 10737508824L; i++) { + boolean result = deviceTaskManager.setExecAttackType(deviceTask.getId(), nf, i); + Assert.assertTrue(result); + + if (nf == NetflowDirection.DIRECTION_IN) { + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn())); + } else { + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut())); + } + } + } + + //exec attack type clean bits + for (NetflowDirection nf : NetflowDirection.values() + ) { + deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 2); + deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 4); + } + + //exec attack type set bits + for (NetflowDirection nf : NetflowDirection.values() + ) { + deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 2); + deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 4); + } + } + + /** + * A 6 exec attack type status. + */ + @Test + public void a6_attackTypeStatus() { + DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); + + //sets exec attack type + for (NetflowDirection nf : NetflowDirection.values() + ) { + for (long i = 10737508814L; i <= 10737508824L; i++) { + boolean result = deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), nf, i); + Assert.assertTrue(result); + + if (nf == NetflowDirection.DIRECTION_IN) { + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn())); + } else { + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut())); + } + } + } + + //attack type status clean bits + for (NetflowDirection nf : NetflowDirection.values() + ) { + deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 2); + deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 4); + } + + //attack type status set bits + for (NetflowDirection nf : NetflowDirection.values() + ) { + deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 2); + deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 4); + } + } + + /** + * A 7 sets task error retry times. + */ + @Test + public void a7_setTaskErrRetryTimes() { + DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); + + for (int i = 0; i <= 5; i++) { + boolean result = deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), i); + Assert.assertTrue(result); + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getErrRetry())); + } + } + + /** + * A 8 sets task extern id. + */ + @Test + public void a8_setTaskExternId() { + DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); + + for (long i = 223L; i <= 230L; i++) { + boolean result = deviceTaskManager.setTaskExternId(deviceTask.getId(), i); + Assert.assertTrue(result); + Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId())); + } + } + + /** + * A 9 gets task by id. + */ + @Test + public void a9_getTaskById() { + deviceTaskMapper.selectAll().forEach(v -> { + DeviceTask deviceTask = deviceTaskManager.getTaskById(v.getId()); + + try { + log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + Assert.assertNotNull(deviceTask); + }); + } +} From bac7489aa65d2375a1fafe3e95fe4ffd739dc32b Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 26 Aug 2020 11:26:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?OCT=20REM:=201.=20=E7=BC=96=E5=86=99service?= =?UTF-8?q?=E5=B1=82=E8=AE=BE=E5=A4=87=E8=83=BD=E5=8A=9B=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEID=E3=80=81=E6=A0=B9=E6=8D=AEIP=E5=92=8C?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E5=8F=B7=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=202.=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93userAccount?= =?UTF-8?q?=E6=9B=B4=E6=96=B0lastAccess=E5=AD=97=E6=AE=B5=E7=9A=84SQL?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mappers/UserAccount.xml | 4 -- .../DisposeAbilityRouterServiceTest.java | 69 ++++++++++++++++++- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/main/resources/mappers/UserAccount.xml b/src/main/resources/mappers/UserAccount.xml index 0a5ad470..6bf82cfc 100644 --- a/src/main/resources/mappers/UserAccount.xml +++ b/src/main/resources/mappers/UserAccount.xml @@ -54,10 +54,6 @@ user_account SET lastAccess = CURRENT_TIMESTAMP WHERE username = #{username, jdbcType=VARCHAR}; - - SELECT lastAccess - FROM user_account - WHERE username = #{username, jdbcType=VARCHAR} diff --git a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java index 8c74ca63..c80d600b 100644 --- a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java @@ -4,6 +4,7 @@ import com.dispose.common.DisposeDeviceType; import com.dispose.common.ErrorCode; import com.dispose.common.HttpType; import com.dispose.common.ObjectStatus; +import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.MulReturnType; @@ -54,6 +55,11 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { */ @Resource private DisposeAbilityRouterService disposeAbilityRouterService; + /** + * The dispose device mapper. + */ + @Resource + private DisposeDeviceMapper disposeDeviceMapper; /** * The Object mapper. */ @@ -117,10 +123,69 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { List abilityInfoList = disposeAbilityRouterService.getAllAbilityDevices(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(abilityInfoList)); - abilityInfoList.forEach(v->{ + abilityInfoList.forEach(v -> { Assert.assertNotNull(v.getDb()); Assert.assertNotNull(v.getDev()); - Assert.assertFalse(v.isLinkStatus()); + + if(v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ + Assert.assertNull(v.getFirewareInfo()); + Assert.assertFalse(v.isLinkStatus()); + }else{ + Assert.assertNotNull(v.getFirewareInfo()); + Assert.assertTrue(v.isLinkStatus()); + } + }); + } + + /** + * A 3 Gets ability device by ipAddr and ipPort. + */ + @Test + public void a3_getAbilityDeviceTest() throws JsonProcessingException { + List deviceList = disposeDeviceMapper.selectAll(); + + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); + + deviceList.forEach(v -> { + AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort()); + + Assert.assertNotNull(abilityInfo); + Assert.assertNotNull(abilityInfo.getDb()); + Assert.assertNotNull(abilityInfo.getDev()); + + if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ + Assert.assertNull(abilityInfo.getFirewareInfo()); + Assert.assertFalse(abilityInfo.isLinkStatus()); + }else{ + Assert.assertNotNull(abilityInfo.getFirewareInfo()); + Assert.assertTrue(abilityInfo.isLinkStatus()); + } + }); + } + + /** + * A 4 Gets ability device by id. + */ + @Test + public void a4_getAbilityDevice() throws JsonProcessingException { + List deviceList = disposeDeviceMapper.selectAll(); + + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); + + deviceList.forEach(v -> { + AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getId()); + + Assert.assertNotNull(abilityInfo); + Assert.assertNotNull(abilityInfo.getDb()); + Assert.assertNotNull(abilityInfo.getDev()); + + if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ + Assert.assertNull(abilityInfo.getFirewareInfo()); + Assert.assertFalse(abilityInfo.isLinkStatus()); + }else{ + Assert.assertNotNull(abilityInfo.getFirewareInfo()); + Assert.assertTrue(abilityInfo.isLinkStatus()); + } }); } } From 54f51224cad4d02bc5204431b3b3c53f310984c6 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 26 Aug 2020 16:10:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?OCT=20REM:=201.=20=E7=BC=96=E5=86=99service?= =?UTF-8?q?=E5=B1=82=E8=AE=BE=E5=A4=87=E4=BB=BB=E5=8A=A1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DeviceTaskManagerServiceImpl.java | 16 +-- .../service/DeviceTaskManagerServiceTest.java | 114 ++++++++++++++++++ 2 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index b15ca83a..07d06bc6 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -201,7 +201,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 遍历设备攻击类型 for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType())) { - // 入方向 + // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { // 已经启动过的任务不再重复启动 if ((deviceTask.getExecAttackTypeOut() & t.getAttackTypeMask()) != 0) { @@ -239,7 +239,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } } - // 出方向 + // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { // 已经启动过的任务不再重复启动 if ((deviceTask.getExecAttackTypeIn() & t.getAttackTypeMask()) != 0) { @@ -284,7 +284,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 获取处置任务当前在设备上的执行状态 DeviceTask devTask = deviceTaskManager.getTaskById(deviceTask.getId()); - // 入方向 + // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { if (!devTask.getExecAttackTypeOut().equals(devTask.getTaskAttackType()) || !devTask.getExecAttackTypeOut().equals(devTask.getAttackTypeStatusOut())) { @@ -292,7 +292,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } } - // 出方向 + // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { if (!devTask.getExecAttackTypeIn().equals(devTask.getTaskAttackType()) || !devTask.getExecAttackTypeIn().equals(devTask.getAttackTypeStatusIn())) { @@ -322,7 +322,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 遍历处置设备执行成功的攻击类型 for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getAttackTypeStatusIn())) { - // 入方向 + // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { // 调用迪普设备停止处置任务 ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), @@ -348,7 +348,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } } - // 出方向 + // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { // 调用迪普设备启动处置任务 ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), @@ -382,14 +382,14 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 获取处置任务当前在设备上的执行状态 DeviceTask devTask = deviceTaskManager.getTaskById(deviceTask.getId()); - // 入方向 + // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { if (devTask.getAttackTypeStatusOut() != 0) { taskStopSucceed = false; } } - // 出方向 + // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { if (devTask.getAttackTypeStatusIn() != 0) { taskStopSucceed = false; diff --git a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java new file mode 100644 index 00000000..466daea3 --- /dev/null +++ b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java @@ -0,0 +1,114 @@ +package com.dispose.test.service; + +import com.dispose.common.*; +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.DeviceTaskManagerService; +import com.dispose.service.UserAccountService; +import com.dispose.test.Global.InitTestEnvironment; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.security.NoSuchAlgorithmException; + +/** + * The type User account service test. + * + * @author + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Transactional +@Rollback +public class DeviceTaskManagerServiceTest extends InitTestEnvironment { + /** + * The constant token. + */ + private static String token = ""; + /** + * The User account service. + */ + @Resource + private UserAccountService userAccountService; + /** + * The device task manager service. + */ + @Resource + private DeviceTaskManagerService deviceTaskManagerService; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + /** + * The user account mapper. + */ + @Resource + private UserAccountMapper userAccountMapper; + /** + * The Dispose device mapper. + */ + @Resource + private DisposeDeviceMapper disposeDeviceMapper; + /** + * The Dispose task mapper. + */ + @Resource + private DisposeTaskMapper disposeTaskMapper; + + /** + * User login test. + * + * @throws NoSuchAlgorithmException the no such algorithm exception + */ + @Before + public void userLoginTest() throws NoSuchAlgorithmException { + MulReturnType ret = userAccountService.loginService(getUSER_NAME(), + getPASSWORD()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + DeviceTaskManagerServiceTest.token = ret.getSecondParam(); + } + } + + /** + * Schedule runner thread. + */ + @Test + public void a1_scheduleRunnerThread() throws JsonProcessingException { + Long uId = userAccountMapper.selectAll().get(0).getId(); + Long dId = disposeDeviceMapper.selectAll().get(0).getId(); + + DisposeTask task = DisposeTask.builder() + .deviceId(dId) + .accountId(uId) + .disposeCapacity(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.0.1") + .planEndTime("30") + .flowDirection(NetflowDirection.DIRECTION_BI) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) + .flowBandWidth(1024) + .build(); + + disposeTaskMapper.addNewTask(task); + log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); + + deviceTaskManagerService.scheduleRunnerThread(); + } +} \ No newline at end of file From 2c08b1cb394168fbf216d3b1720dc42785cfe6f0 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 26 Aug 2020 17:08:30 +0800 Subject: [PATCH 4/4] =?UTF-8?q?OCT=20REM:=201.=20=E8=A7=A3=E5=86=B3manager?= =?UTF-8?q?=E5=B1=82=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/DisposeDeviceManagerTest.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java index 1a816c73..6c0092ec 100644 --- a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java +++ b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java @@ -1,11 +1,9 @@ package com.dispose.test.manager; -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.pojo.entity.DisposeCapacity; import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.po.MulReturnType; import com.fasterxml.jackson.core.JsonProcessingException; @@ -62,6 +60,16 @@ public class DisposeDeviceManagerTest { */ @Test public void a1_addDisposeDevice() { + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + List devCap = new ArrayList<>(); + + devCap.add(DisposeCapacity.builder() + .deviceId(deviceId) + .ipType(IpAddrType.IPV4_IPV6) + .capacityType(DisposeCapacityType.CLEANUP) + .objectType(DisposeObjectType.IP) + .protectIp("") + .build()); for (int i = 1; i < 3; i++) { String ipAddr = "192.168.0." + i; @@ -81,6 +89,7 @@ public class DisposeDeviceManagerTest { .urlType(HttpType.HTTP) .readme("实验室测试设备") .status(ObjectStatus.NORMAL) + .devCapacity(devCap) .build(); MulReturnType ret = disposeDeviceManager.addDisposeDevice(dev); @@ -122,6 +131,16 @@ public class DisposeDeviceManagerTest { */ @Test public void a2_upgradeDisposeDevice() throws JsonProcessingException { + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + List devCap = new ArrayList<>(); + + devCap.add(DisposeCapacity.builder() + .deviceId(deviceId) + .ipType(IpAddrType.IPV4_IPV6) + .capacityType(DisposeCapacityType.CLEANUP) + .objectType(DisposeObjectType.IP) + .protectIp("") + .build()); for (int i = 1; i < 3; i++) { String ipAddr = "192.168.0." + i; @@ -141,6 +160,7 @@ public class DisposeDeviceManagerTest { .urlType(HttpType.HTTP) .readme("实验室测试设备") .status(ObjectStatus.NORMAL) + .devCapacity(devCap) .build(); disposeDeviceManager.addDisposeDevice(dev);