Merge branch 'v2.0.0_dev' of git.komect.net:DDOSAQ/phoenix_ddos_handle into v2.0.0_dev

This commit is contained in:
HuangXin 2020-08-06 17:14:00 +08:00
commit 1b73f87d8e
3 changed files with 326 additions and 10 deletions

View File

@ -56,10 +56,10 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
if (tDev != null) { if (tDev != null) {
// 如果设备是删除状态则更新设备信息 // 如果设备是删除状态则更新设备信息
if (dev.getStatus() == ObjectStatus.DELETED) { if (tDev.getStatus() == ObjectStatus.DELETED) {
// 重置状态 // 重置状态
dev.setStatus(ObjectStatus.NORMAL); tDev.setStatus(ObjectStatus.NORMAL);
return upgradeDisposeDevice(dev); return upgradeDisposeDevice(tDev);
} }
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId()); return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId());
@ -150,10 +150,13 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
// 更新设备数据库 // 更新设备数据库
disposeDeviceMapper.upgradeDisposeDevice(tDev); disposeDeviceMapper.upgradeDisposeDevice(tDev);
// 能力数据库中旧的能力信息 // 能力数据库中旧的能力信息
disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId()); disposeCapacityMapper.delDeviceDisposeCapacity(tDev.getId());
// 新增能力信息完成更新 // 新增能力信息完成更新
if(tDev.getDevCapacity().size() != 0){
disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity()); disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity());
}
return new MulReturnType<>(ErrorCode.ERR_OK, tDev.getId()); return new MulReturnType<>(ErrorCode.ERR_OK, tDev.getId());
} }
@ -195,7 +198,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

@ -1,14 +1,19 @@
package com.dispose.test.manager; package com.dispose.test.manager;
import com.dispose.common.DisposeDeviceType; import com.dispose.common.DisposeDeviceType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType; import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice; 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.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -19,6 +24,7 @@ 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.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
/** /**
@ -45,14 +51,20 @@ public class DisposeDeviceManagerTest {
@Resource @Resource
private DisposeDeviceMapper disposeDeviceMapper; private DisposeDeviceMapper disposeDeviceMapper;
/**
* The Dispose device manager.
*/
@Resource
private DisposeDeviceManager disposeDeviceManager;
/** /**
* A 1 add dispose device. * A 1 add dispose device.
*/ */
@Test @Test
public void a1_addDisposeDevice() { public void a1_addDisposeDevice() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
for(int i = 1; i < 256; i++) { for (int i = 1; i < 3; i++) {
String ipAddr = "192.168.0." + String.valueOf(i); String ipAddr = "192.168.0." + i;
DisposeDevice dev = DisposeDevice.builder() DisposeDevice dev = DisposeDevice.builder()
.ipAddr(ipAddr) .ipAddr(ipAddr)
@ -71,7 +83,20 @@ public class DisposeDeviceManagerTest {
.status(ObjectStatus.NORMAL) .status(ObjectStatus.NORMAL)
.build(); .build();
disposeDeviceMapper.addNewDisposeDevice(dev); MulReturnType<ErrorCode, Long> 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()); 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<ErrorCode, Long> 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<ErrorCode, ObjectStatus> 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);
}
}
});
}
} }

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);
}
});
}
}