REM:
1. 增加浩瀚设备启动清洗任务、停止清洗任务、获取设备状态的单元测试
This commit is contained in:
chenlinghy 2020-08-11 15:52:29 +08:00
parent d79105f084
commit 2d02831d69
1 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,136 @@
package com.dispose.test.haohan;
import com.dispose.ability.DisposeAbility;
import com.dispose.ability.impl.HaoHanAbilityImpl;
import com.dispose.common.*;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.test.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
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.context.junit4.SpringRunner;
/**
* The type Dp tech interface test case.
*/
@RunWith(SpringRunner.class)
@Slf4j
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HAOHanInterfaceTestCast extends InitTestEnvironment {
public static Integer HAOHAN_PLATFORM = 0;
/**
* User login.
*/
@Override
public void userLogin() {
}
/**
* Gets ability map key.
*
* @param ipAddr the ip addr
* @param ipPort the ip port
* @return the ability map key
*/
private String getAbilityMapKey(String ipAddr, String ipPort) {
return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort);
}
/**
* T 1 get all detection object from umc.
*/
@Test
public void t1_runDisposeTest() {
DisposeAbility db;
NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN};
DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION};
DisposeDevice dev = DisposeDevice.builder()
.ipAddr("10.88.77.88")
.ipPort("18080")
.deviceType(DisposeDeviceType.HAOHAN_PLATFORM)
.areaCode(0)
.deviceName("中移杭研实验室浩瀚清洗设备")
.manufacturer("Haohan")
.model("Unknown")
.version("Unknown")
.userName("")
.password("")
.urlPath("DDoSClean/clean")
.urlType(HttpType.HTTP)
.readme("实验室测试设备")
.status(ObjectStatus.NORMAL)
.build();
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath();
if (dev.getDeviceType().getValue().equals(HAOHAN_PLATFORM)) {
db = new HaoHanAbilityImpl();
// 初始化设备
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
MulReturnType<ErrorCode, Long> ret = db.runDispose("192.168.3.5", DisposeCapacityType.CLEANUP,
nfDirection, ddoSAttackType, -1L);
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
}
}
/**
* T 2 stop dispose task.
*/
@Test
public void t2_stopDisposeTest() {
DisposeAbility db;
NetflowDirection[] nfDirection = {NetflowDirection.DIRECTION_IN};
DDoSAttackType[] ddoSAttackType = {DDoSAttackType.ACK_FLOOD, DDoSAttackType.CHARGED_AMPLIFICATION};
DisposeDevice dev = DisposeDevice.builder()
.ipAddr("10.88.77.88")
.ipPort("18080")
.deviceType(DisposeDeviceType.HAOHAN_PLATFORM)
.areaCode(0)
.deviceName("中移杭研实验室浩瀚清洗设备")
.manufacturer("Haohan")
.model("Unknown")
.version("Unknown")
.userName("")
.password("")
.urlPath("DDoSClean/clean")
.urlType(HttpType.HTTP)
.readme("实验室测试设备")
.status(ObjectStatus.NORMAL)
.build();
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath();
if (dev.getDeviceType().getValue().equals(HAOHAN_PLATFORM)) {
db = new HaoHanAbilityImpl();
// 初始化设备
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
Assert.assertTrue(db.getDeviceLinkStatus());
MulReturnType<ErrorCode, Long> ret = db.stopDispose("192.168.3.5", DisposeCapacityType.CLEANUP,
nfDirection, ddoSAttackType, -1L);
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK);
}
}
}