OCT
REM: 1. 优化service层设备任务管理的单元测试代码 2. 修改service层设备能力的单元测试代码
This commit is contained in:
parent
dac28e2ccf
commit
204de601db
|
@ -1,9 +1,8 @@
|
||||||
package com.dispose.test.service;
|
package com.dispose.test.service;
|
||||||
|
|
||||||
import com.dispose.common.*;
|
import com.dispose.common.*;
|
||||||
import com.dispose.mapper.DisposeDeviceMapper;
|
import com.dispose.manager.DisposeDeviceManager;
|
||||||
import com.dispose.mapper.DisposeTaskMapper;
|
import com.dispose.manager.DisposeTaskManager;
|
||||||
import com.dispose.mapper.UserAccountMapper;
|
|
||||||
import com.dispose.pojo.entity.DisposeTask;
|
import com.dispose.pojo.entity.DisposeTask;
|
||||||
import com.dispose.pojo.po.MulReturnType;
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
import com.dispose.service.DeviceTaskManagerService;
|
import com.dispose.service.DeviceTaskManagerService;
|
||||||
|
@ -57,20 +56,15 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
/**
|
/**
|
||||||
* The user account mapper.
|
* The Dispose device manager.
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private UserAccountMapper userAccountMapper;
|
private DisposeDeviceManager disposeDeviceManager;
|
||||||
/**
|
/**
|
||||||
* The Dispose device mapper.
|
* The Dispose task manager.
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceMapper disposeDeviceMapper;
|
private DisposeTaskManager disposeTaskManager;
|
||||||
/**
|
|
||||||
* The Dispose task mapper.
|
|
||||||
*/
|
|
||||||
@Resource
|
|
||||||
private DisposeTaskMapper disposeTaskMapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User login test.
|
* User login test.
|
||||||
|
@ -92,8 +86,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void a1_scheduleRunnerThread() throws JsonProcessingException {
|
public void a1_scheduleRunnerThread() throws JsonProcessingException {
|
||||||
Long uId = userAccountMapper.selectAll().get(0).getId();
|
Long uId = 1L;
|
||||||
Long dId = disposeDeviceMapper.selectAll().get(0).getId();
|
Long dId = disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId();
|
||||||
|
|
||||||
DisposeTask task = DisposeTask.builder()
|
DisposeTask task = DisposeTask.builder()
|
||||||
.deviceId(dId)
|
.deviceId(dId)
|
||||||
|
@ -106,7 +100,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
||||||
.flowBandWidth(1024)
|
.flowBandWidth(1024)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
disposeTaskMapper.addNewTask(task);
|
disposeTaskManager.addDisposeTask(task);
|
||||||
|
|
||||||
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
|
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
|
||||||
|
|
||||||
deviceTaskManagerService.scheduleRunnerThread();
|
deviceTaskManagerService.scheduleRunnerThread();
|
||||||
|
|
|
@ -2,11 +2,8 @@ package com.dispose.test.service;
|
||||||
|
|
||||||
import com.dispose.common.*;
|
import com.dispose.common.*;
|
||||||
import com.dispose.manager.DisposeDeviceManager;
|
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.DisposeCapacity;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.entity.DisposeTask;
|
|
||||||
import com.dispose.pojo.po.AbilityInfo;
|
import com.dispose.pojo.po.AbilityInfo;
|
||||||
import com.dispose.pojo.po.MulReturnType;
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
import com.dispose.service.DisposeAbilityRouterService;
|
import com.dispose.service.DisposeAbilityRouterService;
|
||||||
|
@ -22,12 +19,14 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,6 +40,7 @@ import java.util.List;
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Rollback
|
@Rollback
|
||||||
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
/**
|
/**
|
||||||
* The constant token.
|
* The constant token.
|
||||||
|
@ -56,28 +56,17 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeAbilityRouterService disposeAbilityRouterService;
|
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||||
/**
|
|
||||||
* The dispose device mapper.
|
|
||||||
*/
|
|
||||||
@Resource
|
|
||||||
private DisposeDeviceMapper disposeDeviceMapper;
|
|
||||||
/**
|
/**
|
||||||
* The dispose device manager.
|
* The dispose device manager.
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceManager disposeDeviceManager;
|
private DisposeDeviceManager disposeDeviceManager;
|
||||||
/**
|
|
||||||
* The dispose device manager.
|
|
||||||
*/
|
|
||||||
@Resource
|
|
||||||
private DisposeTaskMapper disposeTaskMapper;
|
|
||||||
/**
|
/**
|
||||||
* The Object mapper.
|
* The Object mapper.
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
|
||||||
public static Integer VIRTUAL_DISPOSE = 999;
|
public static Integer VIRTUAL_DISPOSE = 999;
|
||||||
public static Integer DPTECH_UMC = 0;
|
public static Integer DPTECH_UMC = 0;
|
||||||
|
|
||||||
|
@ -139,10 +128,10 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
Assert.assertNotNull(v.getDb());
|
Assert.assertNotNull(v.getDb());
|
||||||
Assert.assertNotNull(v.getDev());
|
Assert.assertNotNull(v.getDev());
|
||||||
|
|
||||||
if(v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
if (v.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) {
|
||||||
Assert.assertNull(v.getFirewareInfo());
|
Assert.assertNull(v.getFirewareInfo());
|
||||||
Assert.assertFalse(v.isLinkStatus());
|
Assert.assertFalse(v.isLinkStatus());
|
||||||
}else{
|
} else {
|
||||||
Assert.assertNotNull(v.getFirewareInfo());
|
Assert.assertNotNull(v.getFirewareInfo());
|
||||||
Assert.assertTrue(v.isLinkStatus());
|
Assert.assertTrue(v.isLinkStatus());
|
||||||
}
|
}
|
||||||
|
@ -153,22 +142,39 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
* A 3 Gets ability device by ipAddr and ipPort.
|
* A 3 Gets ability device by ipAddr and ipPort.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void a3_getAbilityDeviceTest() throws JsonProcessingException {
|
public void a3_getAbilityDeviceTest() {
|
||||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
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());
|
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort());
|
||||||
|
|
||||||
Assert.assertNotNull(abilityInfo);
|
Assert.assertNotNull(abilityInfo);
|
||||||
Assert.assertNotNull(abilityInfo.getDb());
|
Assert.assertNotNull(abilityInfo.getDb());
|
||||||
Assert.assertNotNull(abilityInfo.getDev());
|
Assert.assertNotNull(abilityInfo.getDev());
|
||||||
|
|
||||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) {
|
||||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
Assert.assertNull(abilityInfo.getFirewareInfo());
|
||||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
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.assertNotNull(abilityInfo.getFirewareInfo());
|
||||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
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
|
@Test
|
||||||
public void a4_getAbilityDevice() throws JsonProcessingException {
|
public void a4_verifyDisposeCapacityTest() {
|
||||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
List<Integer> devIds = new ArrayList<>();
|
||||||
|
List<String> devIpAddrs = new ArrayList<>();
|
||||||
|
List<DisposeCapacityType> 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 -> {
|
disposeDeviceManager.getAllNormalDisposeDevices().forEach(v -> {
|
||||||
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getId());
|
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);
|
log.info("ret-->{}", ret);
|
||||||
Assert.assertNotNull(abilityInfo.getDb());
|
|
||||||
Assert.assertNotNull(abilityInfo.getDev());
|
|
||||||
|
|
||||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
if (ret == ErrorCode.ERR_OK) {
|
||||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
Assert.assertTrue(devIds.contains(Integer.parseInt(String.valueOf(v.getId()))));
|
||||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
Assert.assertTrue(devIpAddrs.contains(v.getIpAddr()));
|
||||||
}else{
|
Assert.assertTrue(capacityTypes.contains(cap.getCapacityType()));
|
||||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
} else if (ret == ErrorCode.ERR_NOSUCHDEVICE) {
|
||||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
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.
|
* A 5 Add dispose device list.
|
||||||
*/
|
*/
|
||||||
|
@ -222,7 +244,7 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
.status(ObjectStatus.NORMAL)
|
.status(ObjectStatus.NORMAL)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assert.assertEquals(ErrorCode.ERR_OK,disposeAbilityRouterService.addDisposeAbilityDevice(dev));
|
Assert.assertEquals(ErrorCode.ERR_OK, disposeAbilityRouterService.addDisposeAbilityDevice(dev));
|
||||||
Assert.assertEquals(dev.getDeviceType().getValue(), DPTECH_UMC);
|
Assert.assertEquals(dev.getDeviceType().getValue(), DPTECH_UMC);
|
||||||
|
|
||||||
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(dev.getIpAddr(), dev.getIpPort());
|
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
|
@Test
|
||||||
public void a7_getAbilityDeviceTest() throws JsonProcessingException {
|
public void a6_getAbilityDeviceTest() throws JsonProcessingException {
|
||||||
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||||
|
|
||||||
|
@ -244,20 +266,21 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
Assert.assertNotNull(abilityInfo.getDb());
|
Assert.assertNotNull(abilityInfo.getDb());
|
||||||
Assert.assertNotNull(abilityInfo.getDev());
|
Assert.assertNotNull(abilityInfo.getDev());
|
||||||
|
|
||||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE) {
|
||||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
Assert.assertNull(abilityInfo.getFirewareInfo());
|
||||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
Assert.assertFalse(abilityInfo.isLinkStatus());
|
||||||
}else{
|
} else {
|
||||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
||||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
Assert.assertTrue(abilityInfo.isLinkStatus());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 8 Gets ability device by id.
|
* A 7 Gets ability device by id.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void a8_getAbilityDevice() throws JsonProcessingException {
|
public void a7_getAbilityDevice() throws JsonProcessingException {
|
||||||
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||||
|
|
||||||
|
@ -268,36 +291,10 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||||
Assert.assertNotNull(abilityInfo.getDb());
|
Assert.assertNotNull(abilityInfo.getDb());
|
||||||
Assert.assertNotNull(abilityInfo.getDev());
|
Assert.assertNotNull(abilityInfo.getDev());
|
||||||
|
|
||||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.DPTECH_UMC){
|
if (abilityInfo.getDev().getDeviceType() == DisposeDeviceType.DPTECH_UMC) {
|
||||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
||||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue