diff --git a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java index 466daea3..74d9a88b 100644 --- a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java +++ b/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java @@ -1,9 +1,8 @@ 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.manager.DisposeDeviceManager; +import com.dispose.manager.DisposeTaskManager; import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DeviceTaskManagerService; @@ -57,20 +56,15 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment { @Resource private ObjectMapper objectMapper; /** - * The user account mapper. + * The Dispose device manager. */ @Resource - private UserAccountMapper userAccountMapper; + private DisposeDeviceManager disposeDeviceManager; /** - * The Dispose device mapper. + * The Dispose task manager. */ @Resource - private DisposeDeviceMapper disposeDeviceMapper; - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; + private DisposeTaskManager disposeTaskManager; /** * User login test. @@ -92,8 +86,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment { */ @Test public void a1_scheduleRunnerThread() throws JsonProcessingException { - Long uId = userAccountMapper.selectAll().get(0).getId(); - Long dId = disposeDeviceMapper.selectAll().get(0).getId(); + Long uId = 1L; + Long dId = disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId(); DisposeTask task = DisposeTask.builder() .deviceId(dId) @@ -106,7 +100,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment { .flowBandWidth(1024) .build(); - disposeTaskMapper.addNewTask(task); + disposeTaskManager.addDisposeTask(task); + log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); deviceTaskManagerService.scheduleRunnerThread(); diff --git a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java index 6c1bd3cc..8139ea09 100644 --- a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java @@ -2,11 +2,8 @@ package com.dispose.test.service; 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; @@ -22,12 +19,14 @@ 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.DirtiesContext; 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; +import java.util.ArrayList; import java.util.List; /** @@ -41,6 +40,7 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @Transactional @Rollback +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { /** * The constant token. @@ -56,28 +56,17 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { */ @Resource private DisposeAbilityRouterService disposeAbilityRouterService; - /** - * The dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; /** * The dispose device manager. */ @Resource private DisposeDeviceManager disposeDeviceManager; - /** - * The dispose device manager. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; /** * The Object mapper. */ @Resource private ObjectMapper objectMapper; - public static Integer VIRTUAL_DISPOSE = 999; public static Integer DPTECH_UMC = 0; @@ -139,10 +128,10 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { Assert.assertNotNull(v.getDb()); Assert.assertNotNull(v.getDev()); - if(v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ + if (v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) { Assert.assertNull(v.getFirewareInfo()); Assert.assertFalse(v.isLinkStatus()); - }else{ + } else { Assert.assertNotNull(v.getFirewareInfo()); Assert.assertTrue(v.isLinkStatus()); } @@ -153,22 +142,39 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { * A 3 Gets ability device by ipAddr and ipPort. */ @Test - public void a3_getAbilityDeviceTest() throws JsonProcessingException { - List deviceList = disposeDeviceMapper.selectAll(); + public void a3_getAbilityDeviceTest() { + disposeDeviceManager.getAllNormalDisposeDevices().forEach(v -> { - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } - 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){ + if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) { Assert.assertNull(abilityInfo.getFirewareInfo()); Assert.assertFalse(abilityInfo.isLinkStatus()); - }else{ + } else { + Assert.assertNotNull(abilityInfo.getFirewareInfo()); + Assert.assertTrue(abilityInfo.isLinkStatus()); + } + + 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()); } @@ -176,30 +182,46 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { } /** - * A 4 Gets ability device by id. + * A 4 verify dispose capacity test. */ @Test - public void a4_getAbilityDevice() throws JsonProcessingException { - List deviceList = disposeDeviceMapper.selectAll(); + public void a4_verifyDisposeCapacityTest() { + List devIds = new ArrayList<>(); + List devIpAddrs = new ArrayList<>(); + List capacityTypes = new ArrayList<>(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); + disposeDeviceManager.getAllNormalDisposeDevices().forEach(v -> { + devIds.add(Integer.parseInt(String.valueOf(v.getId()))); + devIpAddrs.add(v.getIpAddr()); + for (DisposeCapacity disposeCapacity : v.getDevCapacity() + ) { + capacityTypes.add(disposeCapacity.getCapacityType()); + } + }); - deviceList.forEach(v -> { - AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getId()); + disposeDeviceManager.getAllNormalDisposeDevices().forEach(v -> { + for (DisposeCapacity cap : v.getDevCapacity() + ) { + log.info("devId-->{}, ipAddr-->{}, capacityType-->{}", v.getId(), v.getIpAddr(), cap.getCapacityType()); + ErrorCode ret = disposeAbilityRouterService.verifyDisposeCapacity(v.getId(), v.getIpAddr(), cap.getCapacityType()); - Assert.assertNotNull(abilityInfo); - Assert.assertNotNull(abilityInfo.getDb()); - Assert.assertNotNull(abilityInfo.getDev()); + log.info("ret-->{}", ret); - if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ - Assert.assertNull(abilityInfo.getFirewareInfo()); - Assert.assertFalse(abilityInfo.isLinkStatus()); - }else{ - Assert.assertNotNull(abilityInfo.getFirewareInfo()); - Assert.assertTrue(abilityInfo.isLinkStatus()); + if (ret == ErrorCode.ERR_OK) { + Assert.assertTrue(devIds.contains(Integer.parseInt(String.valueOf(v.getId())))); + Assert.assertTrue(devIpAddrs.contains(v.getIpAddr())); + Assert.assertTrue(capacityTypes.contains(cap.getCapacityType())); + } else if (ret == ErrorCode.ERR_NOSUCHDEVICE) { + Assert.assertFalse(devIds.contains(Integer.parseInt(String.valueOf(v.getId())))); + } else if (ret == ErrorCode.ERR_NOSUCHTYPE) { + Assert.assertFalse(devIpAddrs.contains(v.getIpAddr())); + } else if (ret == ErrorCode.ERR_IPNODEVICE) { + Assert.assertFalse(capacityTypes.contains(cap.getCapacityType())); + } } }); } + /** * A 5 Add dispose device list. */ @@ -222,7 +244,7 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { .status(ObjectStatus.NORMAL) .build(); - Assert.assertEquals(ErrorCode.ERR_OK,disposeAbilityRouterService.addDisposeAbilityDevice(dev)); + Assert.assertEquals(ErrorCode.ERR_OK, disposeAbilityRouterService.addDisposeAbilityDevice(dev)); Assert.assertEquals(dev.getDeviceType().getValue(), DPTECH_UMC); AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(dev.getIpAddr(), dev.getIpPort()); @@ -230,10 +252,10 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { } /** - * A 7 Gets ability device by ipAddr and ipPort. + * A 6 Gets ability device by ipAddr and ipPort. */ @Test - public void a7_getAbilityDeviceTest() throws JsonProcessingException { + public void a6_getAbilityDeviceTest() throws JsonProcessingException { List deviceList = disposeDeviceManager.getAllNormalDisposeDevices(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); @@ -244,20 +266,21 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { Assert.assertNotNull(abilityInfo.getDb()); Assert.assertNotNull(abilityInfo.getDev()); - if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){ + if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) { Assert.assertNull(abilityInfo.getFirewareInfo()); Assert.assertFalse(abilityInfo.isLinkStatus()); - }else{ + } else { Assert.assertNotNull(abilityInfo.getFirewareInfo()); Assert.assertTrue(abilityInfo.isLinkStatus()); } }); } + /** - * A 8 Gets ability device by id. + * A 7 Gets ability device by id. */ @Test - public void a8_getAbilityDevice() throws JsonProcessingException { + public void a7_getAbilityDevice() throws JsonProcessingException { List deviceList = disposeDeviceManager.getAllNormalDisposeDevices(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList)); @@ -268,36 +291,10 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment { Assert.assertNotNull(abilityInfo.getDb()); Assert.assertNotNull(abilityInfo.getDev()); - if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.DPTECH_UMC){ + if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.DPTECH_UMC) { Assert.assertNotNull(abilityInfo.getFirewareInfo()); Assert.assertTrue(abilityInfo.isLinkStatus()); } }); } - /** - * 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)); - } - } }