REM:
1. 修改manager层设备信息改变状态方法的返回信息
2. 编写service层设备信息管理的单元测试
This commit is contained in:
chenlinghy 2020-08-06 16:56:59 +08:00
parent c67a2ab9e9
commit c3205a6ff4
2 changed files with 220 additions and 1 deletions

View File

@ -195,7 +195,7 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
if (ret != 1) { if (ret != 1) {
return new MulReturnType<>(ErrorCode.ERR_DATABASE, dev.getStatus()); return new MulReturnType<>(ErrorCode.ERR_DATABASE, dev.getStatus());
} else { } else {
return new MulReturnType<>(ErrorCode.ERR_OK, dev.getStatus()); return new MulReturnType<>(ErrorCode.ERR_OK, disposeDeviceMapper.getDeviceById(id).getStatus());
} }
} }
} }

View File

@ -0,0 +1,219 @@
package com.dispose.test.service;
import com.dispose.common.*;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService;
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.Assert;
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;
import java.util.ArrayList;
import java.util.List;
/**
* The type User account service test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
/**
* The constant token.
*/
private static String token = "";
/**
* The User account service.
*/
@Resource
private UserAccountService userAccountService;
/**
* The dispose device manager service.
*/
@Resource
private DisposeDeviceManagerService disposeDeviceManagerService;
/**
* The Object mapper.
*/
@Resource
private ObjectMapper objectMapper;
/**
* User login test.
*
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
@Before
public void userLoginTest() throws NoSuchAlgorithmException {
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
getPASSWORD());
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
DisposeDeviceManagerServiceTest.token = ret.getSecondParam();
}
}
/**
* A 1 Add dispose device list.
*/
@Test
public void a1_addDisposeDeviceTest() {
List<DisposeDevice> devList = new ArrayList<>();
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();
devList.add(dev);
}
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.addDisposeDevice(devList);
ret.forEach(v->{
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertNotNull(v.getSecondParam().getId());
} else if (v.getFirstParam() == ErrorCode.ERR_DEVICEEXISTS) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertNotNull(v.getSecondParam().getId());
Assert.assertEquals(v.getSecondParam().getStatus(), ObjectStatus.NORMAL);
} else {
Assert.assertNull(v.getSecondParam());
}
});
}
/**
* A 2 Add dispose device list
*/
@Test
public void a2_upgradeDisposeDeviceTest() throws JsonProcessingException {
List<DisposeDevice> devList = new ArrayList<>();
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();
devList.add(dev);
}
disposeDeviceManagerService.addDisposeDevice(devList);
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
devList.forEach(dev->{
dev.setDeviceName("测试清洗设备");
dev.setManufacturer("Unknown");
});
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.upgradeDisposeDevice(devList);
ret.forEach(v->{
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertEquals(v.getSecondParam().getDeviceName(), "测试清洗设备");
Assert.assertEquals(v.getSecondParam().getManufacturer(), "Unknown");
} else {
Assert.assertNull(v.getSecondParam());
}
});
}
/**
* A 3 remove dispose device test.
*/
@Test
public void a3_removeDisposeDeviceTest() throws JsonProcessingException {
List<DisposeDevice> devList = new ArrayList<>();
List<Long> removeIds = new ArrayList<>();
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();
devList.add(dev);
}
disposeDeviceManagerService.addDisposeDevice(devList);
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
devList.forEach(dev-> removeIds.add(dev.getId()));
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.removeDisposeDevice(removeIds);
ret.forEach(v->{
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertEquals(v.getSecondParam().getStatus(), ObjectStatus.DELETED);
} else {
Assert.assertNotNull(v.getSecondParam());
Assert.assertNotEquals(v.getSecondParam().getStatus(), ObjectStatus.DELETED);
}
});
}
}