diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java index 8b46efef..810b99cf 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java @@ -53,10 +53,10 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { if (tDev != null) { // 如果设备是删除状态,则更新设备信息 - if (dev.getStatus() == ObjectStatus.DELETED) { + if (tDev.getStatus() == ObjectStatus.DELETED) { // 重置状态 - dev.setStatus(ObjectStatus.NORMAL); - return upgradeDisposeDevice(dev); + tDev.setStatus(ObjectStatus.NORMAL); + return upgradeDisposeDevice(tDev); } return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId()); @@ -147,10 +147,13 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { // 更新设备数据库 disposeDeviceMapper.upgradeDisposeDevice(tDev); - // 清楚能力数据库中旧的能力信息 + // 清除能力数据库中旧的能力信息 disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId()); + // 新增能力信息完成更新 - disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity()); + if(tDev.getDevCapacity().size() != 0){ + disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity()); + } return new MulReturnType<>(ErrorCode.ERR_OK, tDev.getId()); } diff --git a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java index 1dbacb12..8cbae645 100644 --- a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java +++ b/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java @@ -1,14 +1,19 @@ 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.manager.DisposeDeviceManager; import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.po.MulReturnType; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,6 +24,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.lang.reflect.InvocationTargetException; import java.util.List; /** @@ -45,14 +51,20 @@ public class DisposeDeviceManagerTest { @Resource private DisposeDeviceMapper disposeDeviceMapper; + /** + * The Dispose device manager. + */ + @Resource + private DisposeDeviceManager disposeDeviceManager; + /** * A 1 add dispose device. */ @Test - public void a1_addDisposeDevice() { + public void a1_addDisposeDevice() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - for(int i = 1; i < 256; i++) { - String ipAddr = "192.168.0." + String.valueOf(i); + for (int i = 1; i < 3; i++) { + String ipAddr = "192.168.0." + i; DisposeDevice dev = DisposeDevice.builder() .ipAddr(ipAddr) @@ -71,7 +83,20 @@ public class DisposeDeviceManagerTest { .status(ObjectStatus.NORMAL) .build(); - disposeDeviceMapper.addNewDisposeDevice(dev); + MulReturnType ret = disposeDeviceManager.addDisposeDevice(dev); + + DisposeDevice device = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + Assert.assertNotNull(device); + Assert.assertNotNull(device.getId()); + } else if (ret.getFirstParam() == ErrorCode.ERR_DEVICEEXISTS) { + Assert.assertNotNull(device); + Assert.assertNotNull(device.getId()); + Assert.assertEquals(device.getStatus(), ObjectStatus.NORMAL); + } else { + Assert.assertNull(device); + } } } @@ -91,4 +116,73 @@ public class DisposeDeviceManagerTest { log.debug("Page Info: total {}, page {}", pageInfo.getTotal(), pageInfo.getPageNum()); } + /** + * A 2 upgrade dispose device. + */ + @Test + public void a2_upgradeDisposeDevice() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, JsonProcessingException { + + 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(); + + disposeDeviceManager.addDisposeDevice(dev); + + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + + dev.setDeviceName("测试清洗设备"); + dev.setManufacturer("Unknown"); + + MulReturnType ret = disposeDeviceManager.upgradeDisposeDevice(dev); + + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); + + DisposeDevice upgradeDev = disposeDeviceMapper.getDeviceByAddress(dev.getIpAddr(), dev.getIpPort()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + Assert.assertNotNull(upgradeDev); + Assert.assertEquals(upgradeDev.getDeviceName(), "测试清洗设备"); + Assert.assertEquals(upgradeDev.getManufacturer(), "Unknown"); + } else { + Assert.assertNull(upgradeDev); + } + } + } + + /** + * A 3 change dispose device status. + */ + @Test + public void a3_changeDisposeDeviceStatus() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, JsonProcessingException { + + disposeDeviceMapper.selectAll().forEach(v -> { + for (ObjectStatus obj : ObjectStatus.values() + ) { + MulReturnType ret = disposeDeviceManager.changeDisposeDeviceStatus(v.getId(), obj); + + DisposeDevice dev = disposeDeviceMapper.getDeviceByAddress(v.getIpAddr(), v.getIpPort()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + Assert.assertNotNull(dev); + Assert.assertEquals(dev.getStatus(), obj); + } + } + }); + } }