OCT
REM: 1. 优化service层设备任务管理的单元测试代码 2. 修改service层设备能力的单元测试代码
This commit is contained in:
parent
dac28e2ccf
commit
204de601db
|
@ -1,9 +1,8 @@
|
|||
package com.dispose.test.service;
|
||||
|
||||
import com.dispose.common.*;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.mapper.UserAccountMapper;
|
||||
import com.dispose.manager.DisposeDeviceManager;
|
||||
import com.dispose.manager.DisposeTaskManager;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DeviceTaskManagerService;
|
||||
|
@ -57,20 +56,15 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
|||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
/**
|
||||
* The user account mapper.
|
||||
* The Dispose device manager.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountMapper userAccountMapper;
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
* The Dispose task manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
private DisposeTaskManager disposeTaskManager;
|
||||
|
||||
/**
|
||||
* User login test.
|
||||
|
@ -92,8 +86,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void a1_scheduleRunnerThread() throws JsonProcessingException {
|
||||
Long uId = userAccountMapper.selectAll().get(0).getId();
|
||||
Long dId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||
Long uId = 1L;
|
||||
Long dId = disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId();
|
||||
|
||||
DisposeTask task = DisposeTask.builder()
|
||||
.deviceId(dId)
|
||||
|
@ -106,7 +100,8 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
|
|||
.flowBandWidth(1024)
|
||||
.build();
|
||||
|
||||
disposeTaskMapper.addNewTask(task);
|
||||
disposeTaskManager.addDisposeTask(task);
|
||||
|
||||
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
|
||||
|
||||
deviceTaskManagerService.scheduleRunnerThread();
|
||||
|
|
|
@ -2,11 +2,8 @@ package com.dispose.test.service;
|
|||
|
||||
import com.dispose.common.*;
|
||||
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.DisposeDevice;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.po.AbilityInfo;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DisposeAbilityRouterService;
|
||||
|
@ -22,12 +19,14 @@ 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.DirtiesContext;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -41,6 +40,7 @@ import java.util.List;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The constant token.
|
||||
|
@ -56,28 +56,17 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Resource
|
||||
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||
/**
|
||||
* The dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The dispose device manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
/**
|
||||
* The dispose device manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
public static Integer VIRTUAL_DISPOSE = 999;
|
||||
public static Integer DPTECH_UMC = 0;
|
||||
|
||||
|
@ -153,12 +142,15 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
* A 3 Gets ability device by ipAddr and ipPort.
|
||||
*/
|
||||
@Test
|
||||
public void a3_getAbilityDeviceTest() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
||||
public void a3_getAbilityDeviceTest() {
|
||||
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());
|
||||
|
||||
Assert.assertNotNull(abilityInfo);
|
||||
|
@ -172,34 +164,64 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
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.assertTrue(abilityInfo.isLinkStatus());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4 Gets ability device by id.
|
||||
* A 4 verify dispose capacity test.
|
||||
*/
|
||||
@Test
|
||||
public void a4_getAbilityDevice() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
|
||||
public void a4_verifyDisposeCapacityTest() {
|
||||
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 -> {
|
||||
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getId());
|
||||
disposeDeviceManager.getAllNormalDisposeDevices().forEach(v -> {
|
||||
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);
|
||||
Assert.assertNotNull(abilityInfo.getDb());
|
||||
Assert.assertNotNull(abilityInfo.getDev());
|
||||
log.info("ret-->{}", ret);
|
||||
|
||||
if(abilityInfo.getDev().getDeviceType() == DisposeDeviceType.VIRTUAL_DISPOSE){
|
||||
Assert.assertNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertFalse(abilityInfo.isLinkStatus());
|
||||
}else{
|
||||
Assert.assertNotNull(abilityInfo.getFirewareInfo());
|
||||
Assert.assertTrue(abilityInfo.isLinkStatus());
|
||||
if (ret == ErrorCode.ERR_OK) {
|
||||
Assert.assertTrue(devIds.contains(Integer.parseInt(String.valueOf(v.getId()))));
|
||||
Assert.assertTrue(devIpAddrs.contains(v.getIpAddr()));
|
||||
Assert.assertTrue(capacityTypes.contains(cap.getCapacityType()));
|
||||
} else if (ret == ErrorCode.ERR_NOSUCHDEVICE) {
|
||||
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.
|
||||
*/
|
||||
|
@ -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
|
||||
public void a7_getAbilityDeviceTest() throws JsonProcessingException {
|
||||
public void a6_getAbilityDeviceTest() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||
|
||||
|
@ -253,11 +275,12 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A 8 Gets ability device by id.
|
||||
* A 7 Gets ability device by id.
|
||||
*/
|
||||
@Test
|
||||
public void a8_getAbilityDevice() throws JsonProcessingException {
|
||||
public void a7_getAbilityDevice() throws JsonProcessingException {
|
||||
List<DisposeDevice> deviceList = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
|
||||
|
||||
|
@ -274,30 +297,4 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
|
|||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 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