diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java index b87a7950..f1495ae7 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java @@ -47,6 +47,8 @@ public class DisposeDeviceMapperTest { /** * A 1 add new dispose device. + * + * @throws JsonProcessingException the json processing exception */ @Test public void a1_addNewDisposeDevice() throws JsonProcessingException { @@ -97,16 +99,148 @@ public class DisposeDeviceMapperTest { log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); } + /** + * B 1 upgrade dispose device. + * + * @throws JsonProcessingException the json processing exception + */ + @Test + public void b1_addNewDisposeDevice() throws JsonProcessingException { + DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", ""); + 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(); + + 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(); + } + + List devList = disposeDeviceMapper.selectAll(); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); + } + + /** + * D 1 get dispose device by ipAddr and ipPort. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void d1_getDeviceByAddress() throws JsonProcessingException { DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", ""); Assert.assertNotNull(dev); - log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + + dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.88", "18080"); + Assert.assertNotNull(dev); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); dev = disposeDeviceMapper.getDeviceByAddress("10.88.77.15", "80"); Assert.assertNull(dev); - log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(null)); } + /** + * D 2 get dispose device by id. + */ + @Test + public void d2_getDeviceById() { + List devList = disposeDeviceMapper.selectAll(); + + devList.forEach(v -> { + DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); + Assert.assertNotNull(dev); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + }); + } + + /** + * D 3 delete dispose device. + */ + @Test + public void d3_delDisposeDevice() { + List devList = disposeDeviceMapper.selectAll(); + + devList.forEach(v -> { + disposeDeviceMapper.delDisposeDevice(v.getId()); + DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); + Assert.assertNotNull(dev); + Assert.assertEquals(dev.getStatus(), ObjectStatus.DELETED); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + }); + } + + /** + * D 4 disable dispose device. + */ + @Test + public void d4_disableDisposeDevice() { + List devList = disposeDeviceMapper.selectAll(); + + devList.forEach(v -> { + disposeDeviceMapper.disableDisposeDevice(v.getId()); + DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); + Assert.assertNotNull(dev); + Assert.assertEquals(dev.getStatus(), ObjectStatus.DISABLED); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + }); + } + + /** + * D 5 available dispose device. + */ + @Test + public void d5_availableDisposeDevice() { + List devList = disposeDeviceMapper.selectAll(); + + devList.forEach(v -> { + disposeDeviceMapper.availableDisposeDevice(v.getId()); + DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); + Assert.assertNotNull(dev); + Assert.assertEquals(dev.getStatus(), ObjectStatus.NORMAL); + try { + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + }); + } }