From ecbc85c2de78af04fe543356d23b829638ef476d Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 5 Aug 2020 16:16:48 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=94=B9=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=BF=A1=E6=81=AF=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=AE=BE=E5=A4=87=E8=83=BD=E5=8A=9B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=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 --- .../mapper/DisposeCapacityMapperTest.java | 44 +++++++---- .../test/mapper/DisposeDeviceMapperTest.java | 76 ++++++++++--------- 2 files changed, 68 insertions(+), 52 deletions(-) diff --git a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java index ea19d663..183e326c 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java @@ -4,6 +4,7 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeObjectType; import com.dispose.common.IpAddrType; import com.dispose.mapper.DisposeCapacityMapper; +import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.pojo.entity.DisposeCapacity; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -40,6 +41,11 @@ public class DisposeCapacityMapperTest { */ @Resource DisposeCapacityMapper disposeCapacityMapper; + /** + * The Dispose device mapper. + */ + @Resource + DisposeDeviceMapper disposeDeviceMapper; /** * The Object mapper. */ @@ -55,23 +61,28 @@ public class DisposeCapacityMapperTest { public void a1_addNewDisposeCapacity() throws JsonProcessingException { List newCapList = new ArrayList<>(); + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + newCapList.add(DisposeCapacity.builder() - .deviceId(1L) - .ipType(IpAddrType.IPV4_IPV6) + .deviceId(deviceId) .capacityType(DisposeCapacityType.CLEANUP) .objectType(DisposeObjectType.IP) + .ipType(IpAddrType.IPV4_IPV6) .protectIp("") .build()); newCapList.add(DisposeCapacity.builder() - .deviceId(1L) - .ipType(IpAddrType.IPV4_IPV6) + .deviceId(deviceId) .capacityType(DisposeCapacityType.BLOCKING) .objectType(DisposeObjectType.URL) + .ipType(IpAddrType.IPV4_IPV6) .protectIp("") .build()); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList)); + int items = disposeCapacityMapper.addNewDisposeCapacity(newCapList); + log.info("+++++++++++++item {}", items); Assert.assertEquals(items, newCapList.size()); @@ -89,8 +100,10 @@ public class DisposeCapacityMapperTest { public void a2_delDisposeCapacity() throws JsonProcessingException { List newCapList = new ArrayList<>(); + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.CLEANUP) .objectType(DisposeObjectType.IP) @@ -98,7 +111,7 @@ public class DisposeCapacityMapperTest { .build()); newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.BLOCKING) .objectType(DisposeObjectType.IP) @@ -116,7 +129,7 @@ public class DisposeCapacityMapperTest { items = disposeCapacityMapper.delDisposeCapacity(capList.get(0).getDeviceId(), capList.get(0).getCapacityType().getValue()); - Assert.assertEquals(items, 2); + Assert.assertNotEquals(items, 0); List caps = disposeCapacityMapper.selectAll(); @@ -132,8 +145,10 @@ public class DisposeCapacityMapperTest { public void a3_delDeviceDisposeCapacity() { List newCapList = new ArrayList<>(); + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.CLEANUP) .objectType(DisposeObjectType.IP) @@ -141,7 +156,7 @@ public class DisposeCapacityMapperTest { .build()); newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.BLOCKING) .objectType(DisposeObjectType.IP) @@ -150,10 +165,7 @@ public class DisposeCapacityMapperTest { Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size()); - List capList = disposeCapacityMapper.getDeviceDisposeCapacity(1L); - - Assert.assertEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()), - capList.size()); + Assert.assertNotEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()), 0); Assert.assertEquals(0, disposeCapacityMapper.selectAll().size()); } @@ -167,8 +179,10 @@ public class DisposeCapacityMapperTest { public void b1_getDeviceDisposeCapacity() throws JsonProcessingException { List newCapList = new ArrayList<>(); + Long deviceId = disposeDeviceMapper.selectAll().get(0).getId(); + newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.CLEANUP) .objectType(DisposeObjectType.IP) @@ -176,7 +190,7 @@ public class DisposeCapacityMapperTest { .build()); newCapList.add(DisposeCapacity.builder() - .deviceId(1L) + .deviceId(deviceId) .ipType(IpAddrType.IPV4_IPV6) .capacityType(DisposeCapacityType.BLOCKING) .objectType(DisposeObjectType.IP) diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java index 7304697d..8cb892ba 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java @@ -110,40 +110,42 @@ public class DisposeDeviceMapperTest { List devList = disposeDeviceMapper.selectAll(); devList.forEach(v -> { - DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort()); + if(v.getIpPort().length() != 0){ + DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort()); - String beforeVer = dev.getVersion(); - if (dev.getVersion().equals("B5.2.27.7")) { - dev.setVersion("5.7.13"); - } else { - dev.setVersion("B5.2.27.7"); - } + String beforeVer = dev.getVersion(); + if (dev.getVersion().equals("B5.2.27.7")) { + dev.setVersion("5.7.13"); + } else { + dev.setVersion("B5.2.27.7"); + } - DisposeDevice newDev = DisposeDevice.builder() - .id(dev.getId()) - .ipAddr("10.88.77.15") - .ipPort("") - .deviceType(DisposeDeviceType.DPTECH_UMC) - .areaCode(0) - .deviceName("中移杭研实验室迪普清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version(dev.getVersion()) - .userName("admin") - .password("UMCAdministrator") - .urlPath("UMC/service/AbnormalFlowCleaningService") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); + DisposeDevice newDev = DisposeDevice.builder() + .id(dev.getId()) + .ipAddr("10.88.77.15") + .ipPort("") + .deviceType(DisposeDeviceType.DPTECH_UMC) + .areaCode(0) + .deviceName("中移杭研实验室迪普清洗设备") + .manufacturer("DPTech") + .model("UMC") + .version(dev.getVersion()) + .userName("admin") + .password("UMCAdministrator") + .urlPath("UMC/service/AbnormalFlowCleaningService") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); - Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev)); - Assert.assertNotNull(dev.getId()); - Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer); - try { - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); - } catch (JsonProcessingException e) { - e.printStackTrace(); + Assert.assertEquals(1, disposeDeviceMapper.upgradeDisposeDevice(newDev)); + Assert.assertNotNull(dev.getId()); + Assert.assertNotEquals(disposeDeviceMapper.getDeviceById(newDev.getId()).getVersion(), beforeVer); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } }); @@ -152,9 +154,7 @@ public class DisposeDeviceMapperTest { } /** - * D 1 get dispose device by ipAddr and ipPort. - * - * @throws JsonProcessingException the json processing exception + * D 1 get dispose device by ipAddr and ipPort.processing exception */ @Test public void d1_getDeviceByAddress() { @@ -164,10 +164,12 @@ public class DisposeDeviceMapperTest { DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort()); Assert.assertNotNull(dev); - dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), - String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1)); + if(v.getIpPort().length() != 0){ + dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), + String.valueOf(Long.parseLong(Optional.ofNullable(v.getIpPort()).orElse("123")) + 1)); - Assert.assertNull(dev); + Assert.assertNull(dev); + } }); }