REM:
1. 重构测试代码结构
2. 增加JSON字符串测试接口
This commit is contained in:
HuangXin 2020-09-10 09:21:42 +08:00
parent 3ac91b3def
commit bcdc2a7020
32 changed files with 811 additions and 554 deletions

View File

@ -1,14 +0,0 @@
package com.dispose.qa.test.common;
import lombok.extern.slf4j.Slf4j;
import org.springframework.test.context.ActiveProfiles;
/**
* The type Common environment.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
@ActiveProfiles("test,dispose")
public class CommonEnvironment {
}

View File

@ -1,90 +0,0 @@
package com.dispose.qa.test.controller;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.dto.protocol.device.manager.AddCapacityInfo;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceInfo;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceReq;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp;
import com.dispose.qa.test.common.CommonRestful;
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.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.ArrayList;
import java.util.List;
/**
* The type P 1 device manager controller test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Slf4j
@Transactional
@Rollback
public class P1DeviceManagerControllerTest extends CommonRestful {
/**
* A 1 un login request.
*
* @throws Exception the exception
*/
@Test
public void a1_unLoginRequest() throws Exception {
AddDeviceReq addReq = AddDeviceReq.builder()
.items(new ArrayList<>())
.build();
List<AddCapacityInfo> newCapList = new ArrayList<>();
newCapList.add(AddCapacityInfo.builder()
.capacityType(DisposeCapacityType.CLEANUP.getValue())
.objectType(DisposeObjectType.IP.getValue())
.ipType(IpAddrType.IPV4_IPV6.getValue())
.protectIp("")
.build());
addReq.getItems().add(AddDeviceInfo.builder()
.ipAddr("127.0.0.1")
.ipPort("1000")
.deviceType(DisposeDeviceType.VIRTUAL_DISPOSE.getValue())
.areaCode(0)
.deviceName("实验室虚拟清洗设备")
.manufacturer("CMCC")
.model("Virtual")
.version("v0.0.1")
.userName("admin")
.password("admin")
.urlPath("")
.urlType(HttpType.HTTP.getValue())
.readme("实验室虚拟测试设备")
.capacity(newCapList)
.build());
ProtocolRespDTO<AddDeviceRsp> rspInfo = performanceRestfulFail(addReq,
"/manager/device",
AddDeviceRsp.class,
"123245125123532",
ErrorCode.ERR_LOGOUT,
RequestMethod.PUT);
Assert.assertNotNull(rspInfo);
Assert.assertNotNull(rspInfo.getMsgContent());
Assert.assertEquals((long)rspInfo.getMsgContent().getStatus(), ErrorCode.ERR_LOGOUT.getCode());
}
}

View File

@ -0,0 +1,87 @@
package com.dispose.test.common;
import com.dispose.common.AuthConfigValue;
import com.dispose.common.ErrorCode;
import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.entity.UserAccount;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.UserAccountService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.test.context.ActiveProfiles;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
/**
* The type Common environment.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Slf4j
@ActiveProfiles("test,dispose")
public class CommonEnvironment {
/**
* The User account mapper.
*/
@Resource
private UserAccountMapper userAccountMapper;
/**
* The User account service.
*/
@Resource
private UserAccountService userAccountService;
/**
* The Login token.
*/
private String loginToken;
/**
* The User name.
*/
private String userName;
/**
* The Password.
*/
private String password;
/**
* Init global value.
*
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
@PostConstruct
private void initGlobalValue() throws NoSuchAlgorithmException {
Optional<UserAccount> userAccount = userAccountMapper.selectAll().stream().findFirst();
if (userAccount.isPresent()) {
this.userName = userAccount.get().getUsername();
this.password = userAccount.get().getPassword();
}
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(userName, password);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
this.loginToken = ret.getSecondParam();
}
}
/**
* Gets white list token.
*
* @return the white list token
*/
public String getWhiteListToken() {
for (String v : AuthConfigValue.TRUST_TOKEN_CACHE.keySet()) {
return v;
}
return "";
}
}

View File

@ -1,39 +1,22 @@
package com.dispose.qa.test.common; package com.dispose.test.common;
import com.dispose.common.AuthConfigValue;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.ProtoCryptoType; import com.dispose.common.ProtoCryptoType;
import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.entity.UserAccount;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.ProtocolSecurityService; import com.dispose.service.ProtocolSecurityService;
import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/** /**
* The type Common restful. * The type Common restful.
@ -45,40 +28,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@AutoConfigureMockMvc @AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CommonRestful extends CommonEnvironment { public class CommonRestful extends CommonEnvironment {
/**
* The Login token.
*/
private String loginToken;
/**
* The User name.
*/
private String userName;
/**
* The Password.
*/
private String password;
/**
* The User account service.
*/
@Resource
private UserAccountService userAccountService;
/** /**
* The Protocol security service. * The Protocol security service.
*/ */
@Resource @Resource
private ProtocolSecurityService protocolSecurityService; private ProtocolSecurityService protocolSecurityService;
/**
* The User account mapper.
*/
@Resource
private UserAccountMapper userAccountMapper;
/** /**
* The Mock mvc. * The Mock mvc.
*/ */
@ -91,95 +46,6 @@ public class CommonRestful extends CommonEnvironment {
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
/**
* Init global value.
*
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
@PostConstruct
private void initGlobalValue() throws NoSuchAlgorithmException {
Optional<UserAccount> userAccount = userAccountMapper.selectAll().stream().findFirst();
if (userAccount.isPresent()) {
this.userName = userAccount.get().getUsername();
this.password = userAccount.get().getPassword();
}
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(userName, password);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
this.loginToken = ret.getSecondParam();
}
}
/**
* Create resp type type.
*
* @param <T> the type parameter
* @param c the c
* @return the type
*/
private <T> Type createRespType(Class<T> c) {
Type[] types = new Type[1];
types[0] = c;
return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types,
ProtocolRespDTO.class.getDeclaringClass());
}
/**
* Gets white list token.
*
* @return the white list token
*/
public String getWhiteListToken() {
for (String v : AuthConfigValue.TRUST_TOKEN_CACHE.keySet()) {
return v;
}
return "";
}
private String restfulRun(RequestMethod reqType, String urlPath, String loginToken, String sendMsgContent,
ErrorCode errCode) throws Exception {
MockHttpServletRequestBuilder build;
int httpCode = (errCode == ErrorCode.ERR_OK) ? HttpServletResponse.SC_OK : HttpServletResponse.SC_BAD_REQUEST;
switch (reqType) {
case PUT:
build = MockMvcRequestBuilders.put(urlPath);
break;
case GET:
build = MockMvcRequestBuilders.get(urlPath);
break;
case DELETE:
build = MockMvcRequestBuilders.delete(urlPath);
break;
case POST:
default:
build = MockMvcRequestBuilders.post(urlPath);
break;
}
if (loginToken != null && loginToken.length() > 0) {
build.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + loginToken)
.content(sendMsgContent);
} else {
build.contentType(MediaType.APPLICATION_JSON)
.content(sendMsgContent);
}
return mockMvc.perform(build)
.andDo(print()).andExpect(status().is(httpCode))
.andExpect(jsonPath("$.code").value(errCode.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
}
/** /**
* Performance restful protocol resp dto. * Performance restful protocol resp dto.
* *
@ -189,9 +55,10 @@ public class CommonRestful extends CommonEnvironment {
* @param urlPath the url path * @param urlPath the url path
* @param subClass the sub class * @param subClass the sub class
* @param reqCryptoType the req crypto type * @param reqCryptoType the req crypto type
* @param errCode the http code * @param errCode the err code
* @param loginToken the login token * @param loginToken the login token
* @param autoDecrypt the auto decrypt * @param autoDecrypt the auto decrypt
* @param reqType the req type
* @return the protocol resp dto * @return the protocol resp dto
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -225,7 +92,7 @@ public class CommonRestful extends CommonEnvironment {
sendMsgContent = objectMapper.writeValueAsString(reqInfo); sendMsgContent = objectMapper.writeValueAsString(reqInfo);
} }
rspValue = restfulRun(reqType, urlPath, loginToken, sendMsgContent, errCode); rspValue = Helper.restfulRun(mockMvc, reqType, urlPath, loginToken, sendMsgContent, errCode);
if (autoDecrypt) { if (autoDecrypt) {
rspValue = protocolSecurityService.decryptProtocol(rspValue); rspValue = protocolSecurityService.decryptProtocol(rspValue);
@ -235,7 +102,7 @@ public class CommonRestful extends CommonEnvironment {
new TypeReference<ProtocolRespDTO<K>>() { new TypeReference<ProtocolRespDTO<K>>() {
@Override @Override
public Type getType() { public Type getType() {
return createRespType(subClass); return Helper.createRespType(subClass);
} }
}); });
} }
@ -249,6 +116,7 @@ public class CommonRestful extends CommonEnvironment {
* @param urlPath the url path * @param urlPath the url path
* @param subClass the sub class * @param subClass the sub class
* @param loginToken the login token * @param loginToken the login token
* @param reqType the req type
* @return the protocol resp dto * @return the protocol resp dto
* @throws Exception the exception * @throws Exception the exception
*/ */
@ -273,7 +141,8 @@ public class CommonRestful extends CommonEnvironment {
* @param urlPath the url path * @param urlPath the url path
* @param subClass the sub class * @param subClass the sub class
* @param loginToken the login token * @param loginToken the login token
* @param errCode the http err code * @param errCode the err code
* @param reqType the req type
* @return the protocol resp dto * @return the protocol resp dto
* @throws Exception the exception * @throws Exception the exception
*/ */

View File

@ -0,0 +1,80 @@
package com.dispose.test.common;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.service.ProtocolSecurityService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import java.lang.reflect.Type;
/**
* The type Common restful json.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CommonRestfulJson extends CommonEnvironment {
/**
* The Protocol security service.
*/
@Resource
private ProtocolSecurityService protocolSecurityService;
/**
* The Mock mvc.
*/
@Resource
private MockMvc mockMvc;
/**
* The Object mapper.
*/
@Resource
private ObjectMapper objectMapper;
/**
* Performance restful protocol resp dto.
*
* @param <T> the type parameter
* @param reqJson the req json
* @param urlPath the url path
* @param subClass the sub class
* @param errCode the err code
* @param loginToken the login token
* @param autoDecrypt the auto decrypt
* @param reqType the req type
* @return the protocol resp dto
* @throws Exception the exception
*/
public <T> ProtocolRespDTO<T> performanceRestful(String reqJson, String urlPath,
Class<T> subClass,
ErrorCode errCode,
String loginToken,
boolean autoDecrypt,
RequestMethod reqType) throws Exception {
String rspValue = Helper.restfulRun(mockMvc, reqType, urlPath, loginToken, reqJson, errCode);
if (autoDecrypt) {
rspValue = protocolSecurityService.decryptProtocol(rspValue);
}
return objectMapper.readValue(rspValue,
new TypeReference<ProtocolRespDTO<T>>() {
@Override
public Type getType() {
return Helper.createRespType(subClass);
}
});
}
}

View File

@ -0,0 +1,93 @@
package com.dispose.test.common;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.bind.annotation.RequestMethod;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Type;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* The type Helper.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public class Helper {
/**
* Restful run string.
*
* @param mockMvc the mock mvc
* @param reqType the req type
* @param urlPath the url path
* @param loginToken the login token
* @param sendMsgContent the send msg content
* @param errCode the err code
* @return the string
* @throws Exception the exception
*/
public static String restfulRun(MockMvc mockMvc, RequestMethod reqType,
String urlPath, String loginToken,
String sendMsgContent, ErrorCode errCode) throws Exception {
MockHttpServletRequestBuilder build;
int httpCode = (errCode == ErrorCode.ERR_OK) ? HttpServletResponse.SC_OK : HttpServletResponse.SC_BAD_REQUEST;
switch (reqType) {
case PUT:
build = MockMvcRequestBuilders.put(urlPath);
break;
case GET:
build = MockMvcRequestBuilders.get(urlPath);
break;
case DELETE:
build = MockMvcRequestBuilders.delete(urlPath);
break;
case POST:
default:
build = MockMvcRequestBuilders.post(urlPath);
break;
}
if (loginToken != null && loginToken.length() > 0) {
build.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + loginToken)
.content(sendMsgContent);
} else {
build.contentType(MediaType.APPLICATION_JSON)
.content(sendMsgContent);
}
return mockMvc.perform(build)
.andDo(print()).andExpect(status().is(httpCode))
.andExpect(jsonPath("$.code").value(errCode.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
}
/**
* Create resp type type.
*
* @param <T> the type parameter
* @param c the c
* @return the type
*/
public static <T> Type createRespType(Class<T> c) {
Type[] types = new Type[1];
types[0] = c;
return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types,
ProtocolRespDTO.class.getDeclaringClass());
}
}

View File

@ -1,247 +0,0 @@
package com.dispose.test.debug;
import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
import com.dispose.common.PrivacyHelper;
import com.dispose.common.SecurityConfigValue;
import com.dispose.pojo.entity.DisposeDevice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.security.arithmetic.CryptoHelper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
/**
* The type Demo.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class demo {
// /**
// * A 1 idid array req test.
// *
// * @throws JsonProcessingException the json processing exception
// */
// @Test
// public void a1_IDIDArrayReqTest() throws JsonProcessingException {
// String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}";
// String json2 = "{\"id\":[\"1\", \"123\", \"1234\"]}";
// String json3 = "{\"id\":[\"\", \"1\", \"123\", \"1234\"]}";
// //String json4 = "{\"id\":[\"1\", \"123\", \"1234\", null]}";
//
//
// IDArrayReq id = new ObjectMapper().readValue(json3, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 1);
//
// id = new ObjectMapper().readValue(json2, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 3);
//
// id = new ObjectMapper().readValue(json, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 3);
//
// //id = new ObjectMapper().readValue(json4, IDArrayReq.class);
// }
//
// /**
// * A 2 ip range test.
// *
// * @throws AddressStringException the address string exception
// */
// @Test
// public void a2_ipRangeTest() throws AddressStringException {
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.1-192.168.0.100", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40"));
// Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("", "192.168.0.30"));
// }
/**
* Date time debug.
*/
@Test
public void dateTimeDebug() {
Integer v1 = null;
Integer v2 = 1;
log.info("Current Datetime: {}",
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//log.info("Current Datetime: {}", new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss").format(LocalDateTime.now()));
log.info("v1: {}", Optional.ofNullable(v1).orElse(0));
log.info("v2: {}", Optional.ofNullable(v2).orElse(0));
}
/**
* Upgrade dispose device properties t.
*
* @param <T> the type parameter
* @param destDev the dest dev
* @param srcDev the src dev
* @return the t
*/
private <T> T upgradeDisposeDeviceProperties(T destDev, T srcDev) {
Field[] field = srcDev.getClass().getDeclaredFields();
for (Field fdSrc : field) {
if (Modifier.toString(fdSrc.getModifiers()).indexOf("static") > 0) {
continue;
}
fdSrc.setAccessible(true);
try {
if(fdSrc.get(srcDev) != null) {
Field fdDest = destDev.getClass().getDeclaredField(fdSrc.getName());
fdDest.setAccessible(true);
fdDest.set(destDev, fdSrc.get(srcDev));
fdDest.setAccessible(false);
}
} catch (IllegalAccessException | NoSuchFieldException e) {
log.warn("Copy field maybe occurs some errors: ", e);
}
fdSrc.setAccessible(false);
}
return destDev;
}
/**
* Class enum value.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void classEnumValue() throws JsonProcessingException {
DisposeDevice dev = DisposeDevice.builder()
.ipAddr("10.88.77.15")
.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();
DisposeDevice dev2 = DisposeDevice.builder()
.version("5.7.135")
.build();
log.debug(new ObjectMapper()
.writerWithDefaultPrettyPrinter()
.writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2)));
}
/**
* Privacy helper.
*/
@Test
public void privacyHelper() {
log.info(PrivacyHelper.ipAddressPrivacy("192.168.0.123"));
log.info(PrivacyHelper.ipAddressPrivacy("2001:0000:4136:e378:8000:63bf:3fff:fdd2"));
log.info(PrivacyHelper.ipAddressPrivacy("3fde::fde2"));
}
/**
* Gets type mask from attack type.
*/
@Test
public void getTypeMaskFromAttackType() {
Long ret = DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[] {DDoSAttackType.ALL_ATTACKS});
log.debug("Ret: 0x{}", Long.toHexString(ret).toUpperCase());
}
/**
* Ip belong.
*/
@Test
public void ipBelong() {
// for(int i = 1; i <= 255; i++) {
// log.info("112.13.117.{} : {}", i,
// HttpRequest.get("http://172.28.72.32:8888/ip/112.13.117." + i).execute().body());
// log.info("112.13.119.{} : {}", i,
// HttpRequest.get("http://172.28.72.32:8888/ip/112.13.119." + i).execute().body());
// }
}
/**
* Aes 256 encrypt.
*/
@Test
public void aes256Encrypt() {
byte[] aesMsg;
byte[] deAesMsg;
String srcMsg = "{\n" +
" \"password\": \"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\",\n" +
" \"userName\": \"admin\"\n" +
"}";
try {
aesMsg = CryptoHelper.aes256Encryption(srcMsg.getBytes(StandardCharsets.UTF_8), SecurityConfigValue.AES_KEY);
deAesMsg = CryptoHelper.aes256Decryption(aesMsg, SecurityConfigValue.AES_KEY);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | BadPaddingException | InvalidKeyException | IllegalBlockSizeException e) {
e.printStackTrace();
aesMsg = new byte[] {0};
deAesMsg = new byte[] {0};
}
log.info("src: {}", srcMsg);
log.info("src AES256: {}", CryptoHelper.base64Encryption(aesMsg));
log.info("src DeAES256: {}", new String(deAesMsg, StandardCharsets.UTF_8));
}
/**
* Aes 256 decrypt.
*/
@Test
public void aes256Decrypt() {
byte[] deAesMsg;
String aesBase64Msg = "QCjaAU4xNNViBsfTMZ2NmXd18kER1raiW1F7R2lzrlxbsL98s4LKiL35xZKXV/" +
"MIrs8+K4NH79sfDoDuaB1rg1y9vglijIvOvk1l8epLxQdlpHz4S2X8MHqKkX8P2P3ZycqzIXwJOXM6XTm" +
"59vBbzg2cfld/3TtPWVRBiGmY4JaWB29zxmuaV+wUjLKMzIXg1CWMQ2vYR2ZIp7ZvVp1KDjWVxsqkc6y" +
"/Qn9JGR0Nb1vMeNbJ/gfPH3UW+rCl5OMf";
byte[] base64Decode = CryptoHelper.base64Decryption(aesBase64Msg);
try {
deAesMsg = CryptoHelper.aes256Decryption(base64Decode, SecurityConfigValue.AES_KEY);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | BadPaddingException | InvalidKeyException | IllegalBlockSizeException e) {
e.printStackTrace();
deAesMsg = new byte[] {0};
}
log.info("src: {}", aesBase64Msg);
log.info("src DeAES256: {}", new String(deAesMsg, StandardCharsets.UTF_8));
}
}

View File

@ -1,4 +1,4 @@
package com.dispose.test.Global; package com.dispose.test.dev.Global;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeConfigValue;

View File

@ -1,4 +1,4 @@
package com.dispose.test.controller; package com.dispose.test.dev.controller;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
@ -7,7 +7,7 @@ import com.dispose.pojo.dto.protocol.auth.LoginReq;
import com.dispose.pojo.dto.protocol.auth.LoginRsp; import com.dispose.pojo.dto.protocol.auth.LoginRsp;
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jodd.net.HttpStatus; import jodd.net.HttpStatus;

View File

@ -1,4 +1,4 @@
package com.dispose.test.controller; package com.dispose.test.dev.controller;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
@ -23,7 +23,7 @@ import com.dispose.pojo.dto.protocol.device.manager.DeviceInfoRsp;
import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp; import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jodd.net.HttpStatus; import jodd.net.HttpStatus;

View File

@ -1,4 +1,4 @@
package com.dispose.test.controller; package com.dispose.test.dev.controller;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
@ -10,7 +10,7 @@ import com.dispose.pojo.dto.protocol.device.info.GetAreaInfoRsp;
import com.dispose.pojo.dto.protocol.device.info.GetDeviceInfoRsp; import com.dispose.pojo.dto.protocol.device.info.GetDeviceInfoRsp;
import com.dispose.pojo.dto.protocol.device.info.GetPlatformVerInfoRsp; import com.dispose.pojo.dto.protocol.device.info.GetPlatformVerInfoRsp;
import com.dispose.service.DisposeDeviceManagerService; import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jodd.net.HttpStatus; import jodd.net.HttpStatus;

View File

@ -1,4 +1,4 @@
package com.dispose.test.controller; package com.dispose.test.dev.controller;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.DDoSAttackType; import com.dispose.common.DDoSAttackType;
@ -14,12 +14,15 @@ import com.dispose.pojo.dto.protocol.base.IdArraysReq;
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq; import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq;
import com.dispose.pojo.dto.protocol.task.*; import com.dispose.pojo.dto.protocol.task.GetTaskRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartReq;
import com.dispose.pojo.dto.protocol.task.TaskStopRsp;
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.DisposeDeviceManagerService; import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.service.DisposeTaskService; import com.dispose.service.DisposeTaskService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;

View File

@ -0,0 +1,281 @@
package com.dispose.test.dev.debug;
import com.dispose.common.ConstValue;
import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
import com.dispose.common.PrivacyHelper;
import com.dispose.pojo.entity.DisposeDevice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* The type Demo.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
public class demo {
// /**
// * A 1 idid array req test.
// *
// * @throws JsonProcessingException the json processing exception
// */
// @Test
// public void a1_IDIDArrayReqTest() throws JsonProcessingException {
// String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}";
// String json2 = "{\"id\":[\"1\", \"123\", \"1234\"]}";
// String json3 = "{\"id\":[\"\", \"1\", \"123\", \"1234\"]}";
// //String json4 = "{\"id\":[\"1\", \"123\", \"1234\", null]}";
//
//
// IDArrayReq id = new ObjectMapper().readValue(json3, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 1);
//
// id = new ObjectMapper().readValue(json2, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 3);
//
// id = new ObjectMapper().readValue(json, IDArrayReq.class);
// Assert.assertEquals(id.getId().length, 3);
//
// //id = new ObjectMapper().readValue(json4, IDArrayReq.class);
// }
//
// /**
// * A 2 ip range test.
// *
// * @throws AddressStringException the address string exception
// */
// @Test
// public void a2_ipRangeTest() throws AddressStringException {
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.1-192.168.0.100", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40"));
// Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30"));
// Assert.assertTrue(IPAddrType.ipInRange("", "192.168.0.30"));
// }
/**
* Date time debug.
*/
@Test
public void dateTimeDebug() {
Integer v1 = null;
Integer v2 = 1;
log.info("Current Datetime: {}",
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//log.info("Current Datetime: {}", new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss").format(LocalDateTime.now()));
//log.info("v1: {}", Optional.ofNullable(v1).orElse(0));
//log.info("v2: {}", Optional.ofNullable(v2).orElse(0));
}
/**
* Upgrade dispose device properties t.
*
* @param <T> the type parameter
* @param destDev the dest dev
* @param srcDev the src dev
* @return the t
*/
private <T> T upgradeDisposeDeviceProperties(T destDev, T srcDev) {
Field[] field = srcDev.getClass().getDeclaredFields();
for (Field fdSrc : field) {
if (Modifier.toString(fdSrc.getModifiers()).indexOf("static") > 0) {
continue;
}
fdSrc.setAccessible(true);
try {
if (fdSrc.get(srcDev) != null) {
Field fdDest = destDev.getClass().getDeclaredField(fdSrc.getName());
fdDest.setAccessible(true);
fdDest.set(destDev, fdSrc.get(srcDev));
fdDest.setAccessible(false);
}
} catch (IllegalAccessException | NoSuchFieldException e) {
log.warn("Copy field maybe occurs some errors: ", e);
}
fdSrc.setAccessible(false);
}
return destDev;
}
/**
* Class enum value.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void classEnumValue() throws JsonProcessingException {
DisposeDevice dev = DisposeDevice.builder()
.ipAddr("10.88.77.15")
.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();
DisposeDevice dev2 = DisposeDevice.builder()
.version("5.7.135")
.build();
log.debug(new ObjectMapper()
.writerWithDefaultPrettyPrinter()
.writeValueAsString(upgradeDisposeDeviceProperties(dev, dev2)));
}
/**
* Privacy helper.
*/
@Test
public void privacyHelper() {
log.info(PrivacyHelper.ipAddressPrivacy("192.168.0.123"));
log.info(PrivacyHelper.ipAddressPrivacy("2001:0000:4136:e378:8000:63bf:3fff:fdd2"));
log.info(PrivacyHelper.ipAddressPrivacy("3fde::fde2"));
}
/**
* Gets type mask from attack type.
*/
@Test
public void getTypeMaskFromAttackType() {
Long ret = DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS});
log.debug("Ret: 0x{}", Long.toHexString(ret).toUpperCase());
}
/**
* Ip belong.
*/
@Test
public void ipBelong() {
// for(int i = 1; i <= 255; i++) {
// log.info("112.13.117.{} : {}", i,
// HttpRequest.get("http://172.28.72.32:8888/ip/112.13.117." + i).execute().body());
// log.info("112.13.119.{} : {}", i,
// HttpRequest.get("http://172.28.72.32:8888/ip/112.13.119." + i).execute().body());
// }
}
@Test
public void haohanStartError() {
String errMsg = "[{ip=192.168.50.2, 任务名称=三方接口任务467}, {ip=192.168.50.2, 任务名称=三方接口任务468}, {ip=192.168" +
".50.2, 任务名称=三方接口任务470}, {ip=192.168.50.2, 任务名称=三方接口任务469}]";
String reg = "(\\[(.*?)])";
Pattern k = Pattern.compile("\\{(.*?)}");
Matcher n = k.matcher(errMsg);
while (n.find()) {
log.info("\tsub items: {}", n.group(1)
.substring(n.group(1).lastIndexOf("=") + 1)
.replaceAll("\\D", ""));
}
}
@Test
public void ipaddrVariety() {
String[] ipAddrs = new String[]{
"ffff::8fff:ffff:0:ffff",
"::1",
"192.168.0.1",
"192.168.00.1",
"023.0.2.1"
};
for (String s : ipAddrs) {
IPAddress addr = new IPAddressString(s).getAddress();
log.info("Src Ip: {}", s);
log.info("fullString: {}", addr.toFullString().toUpperCase());
log.info("normalString: {}", addr.toNormalizedString().toUpperCase());
}
}
@Test
public void groupArray() {
Integer[] org = new Integer[]{1, 2, 3, 4, 5};
Integer[] diff = new Integer[]{1, 3, 5, 6, 7, 8, 9};
List<Integer> orgList = Arrays.asList(org);
List<Integer> diffList = Arrays.asList(diff);
Map<Boolean, List<Integer>> groupMap = orgList.stream()
.collect(Collectors.groupingBy(diffList::contains));
log.info("Result: {}", groupMap);
}
@Test
public void ipSegment() {
String str = "192.168.1.1/23, 192.168.1.2-192.168.1.80, ::1-::255, 192.168.1, 01.012.012.01, " +
"123.123.123-";
String fIpAddr = "";
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
log.info("process string: {}", s);
String normalString = s.replace(" ", "");
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, normalString)) {
log.error("Step1: {} not match", normalString);
}
// if (normalString.indexOf("-") == normalString.lastIndexOf("-")) {
// if(normalString.contains("-")) {
// String[] ipArray = normalString.split("-");
// if(ipArray.length == 2) {
// fIpAddr = Helper.ipAddressNormalize(ipArray[0]) + "-" + Helper.ipAddressNormalize(ipArray[1]);
// } else {
// log.error("Bad ip segment: {}", normalString);
// }
// } else {
// fIpAddr = Helper.ipAddressNormalize(normalString);
// }
// } else {
// log.error("bad format string: {}", normalString);
// }
// log.info("Verify ipaddr string: {}", fIpAddr);
// if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, fIpAddr)) {
// log.error("Step2: {} not match", fIpAddr);
// }
}
}
}

View File

@ -1,4 +1,4 @@
package com.dispose.test.dptech; package com.dispose.test.dev.dptech;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.ability.impl.DpTechAbilityImpl; import com.dispose.ability.impl.DpTechAbilityImpl;
@ -12,7 +12,7 @@ import com.dispose.common.ObjectStatus;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo; import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;

View File

@ -1,4 +1,4 @@
package com.dispose.test.haohan; package com.dispose.test.dev.haohan;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.ability.impl.HaoHanAbilityImpl; import com.dispose.ability.impl.HaoHanAbilityImpl;
@ -10,7 +10,7 @@ import com.dispose.common.ObjectStatus;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo; import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;

View File

@ -1,4 +1,4 @@
package com.dispose.test.manager; package com.dispose.test.dev.manager;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;

View File

@ -1,6 +1,12 @@
package com.dispose.test.manager; package com.dispose.test.dev.manager;
import com.dispose.common.*; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType;
import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeCapacity; import com.dispose.pojo.entity.DisposeCapacity;

View File

@ -1,6 +1,10 @@
package com.dispose.test.manager; package com.dispose.test.dev.manager;
import com.dispose.common.*; import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.manager.DisposeTaskManager; import com.dispose.manager.DisposeTaskManager;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.mapper.DisposeTaskMapper; import com.dispose.mapper.DisposeTaskMapper;

View File

@ -1,11 +1,11 @@
package com.dispose.test.manager; package com.dispose.test.dev.manager;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.manager.UserAccountManager; import com.dispose.manager.UserAccountManager;
import com.dispose.mapper.UserAccountMapper; import com.dispose.mapper.UserAccountMapper;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.dispose.test.mapper; package com.dispose.test.dev.mapper;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.mapper.DeviceTaskMapper; import com.dispose.mapper.DeviceTaskMapper;

View File

@ -1,4 +1,4 @@
package com.dispose.test.mapper; package com.dispose.test.dev.mapper;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType; import com.dispose.common.DisposeObjectType;
@ -61,15 +61,13 @@ public class DisposeCapacityMapperTest {
public void a1_addNewDisposeCapacity() throws JsonProcessingException { public void a1_addNewDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>(); List<DisposeCapacity> newCapList = new ArrayList<>();
disposeDeviceMapper.selectAll().forEach(v -> { disposeDeviceMapper.selectAll().forEach(v -> newCapList.add(DisposeCapacity.builder()
newCapList.add(DisposeCapacity.builder()
.deviceId(v.getId()) .deviceId(v.getId())
.capacityType(DisposeCapacityType.CLEANUP) .capacityType(DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP) .objectType(DisposeObjectType.IP)
.ipType(IpAddrType.IPV4_IPV6) .ipType(IpAddrType.IPV4_IPV6)
.protectIp("0.0.0.0") .protectIp("0.0.0.0")
.build()); .build()));
});
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList));

View File

@ -1,4 +1,4 @@
package com.dispose.test.mapper; package com.dispose.test.dev.mapper;
import com.dispose.common.DisposeDeviceType; import com.dispose.common.DisposeDeviceType;
import com.dispose.common.HttpType; import com.dispose.common.HttpType;

View File

@ -1,4 +1,4 @@
package com.dispose.test.mapper; package com.dispose.test.dev.mapper;
import com.dispose.common.DDoSAttackType; import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;

View File

@ -1,4 +1,4 @@
package com.dispose.test.mapper; package com.dispose.test.dev.mapper;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;

View File

@ -1,7 +1,7 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.service.AreaCodeManagerService; import com.dispose.service.AreaCodeManagerService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;

View File

@ -1,13 +1,16 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.common.*; import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
import com.dispose.manager.DisposeTaskManager; import com.dispose.manager.DisposeTaskManager;
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;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -1,6 +1,10 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.common.*; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
import com.dispose.pojo.entity.DisposeCapacity; import com.dispose.pojo.entity.DisposeCapacity;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
@ -8,7 +12,7 @@ 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;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.common.DisposeDeviceType; import com.dispose.common.DisposeDeviceType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
@ -9,7 +9,7 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService; import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -190,21 +190,20 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
List<DisposeDevice> devs = disposeDeviceMapper.selectAll(); List<DisposeDevice> devs = disposeDeviceMapper.selectAll();
for (int i = 1; i < 5; i++) { for (int i = 1; i < 5; i++) {
int startPage = i;
int pageSize = i * 2; int pageSize = i * 2;
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret = disposeDeviceManagerService.getPageDisposeDevice(startPage, pageSize); MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret = disposeDeviceManagerService.getPageDisposeDevice(i, pageSize);
PageInfo<DisposeDevice> pageInfo = ret.getFirstParam(); PageInfo<DisposeDevice> pageInfo = ret.getFirstParam();
Assert.assertEquals(pageInfo.getPageNum(), startPage); Assert.assertEquals(pageInfo.getPageNum(), i);
Assert.assertEquals(pageInfo.getPageSize(), pageSize); Assert.assertEquals(pageInfo.getPageSize(), pageSize);
//数据库设备信息数据量比较大 //数据库设备信息数据量比较大
if (devs.size() >= (startPage * pageSize)) { if (devs.size() >= (i * pageSize)) {
if (pageInfo.getPageNum() != 1) { if (pageInfo.getPageNum() != 1) {
Assert.assertFalse(pageInfo.isIsFirstPage()); Assert.assertFalse(pageInfo.isIsFirstPage());
Assert.assertTrue(pageInfo.isHasPreviousPage()); Assert.assertTrue(pageInfo.isHasPreviousPage());
Assert.assertEquals(pageInfo.getPrePage(), startPage - 1); Assert.assertEquals(pageInfo.getPrePage(), i - 1);
} else { } else {
Assert.assertTrue(pageInfo.isIsFirstPage()); Assert.assertTrue(pageInfo.isIsFirstPage());
Assert.assertFalse(pageInfo.isHasPreviousPage()); Assert.assertFalse(pageInfo.isHasPreviousPage());
@ -213,7 +212,7 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
if (pageInfo.getPageNum() != 1) { if (pageInfo.getPageNum() != 1) {
Assert.assertFalse(pageInfo.isIsFirstPage()); Assert.assertFalse(pageInfo.isIsFirstPage());
Assert.assertTrue(pageInfo.isHasPreviousPage()); Assert.assertTrue(pageInfo.isHasPreviousPage());
Assert.assertEquals(pageInfo.getPrePage(), startPage - 1); Assert.assertEquals(pageInfo.getPrePage(), i - 1);
} else { } else {
Assert.assertTrue(pageInfo.isIsFirstPage()); Assert.assertTrue(pageInfo.isIsFirstPage());
Assert.assertFalse(pageInfo.isHasNextPage()); Assert.assertFalse(pageInfo.isHasNextPage());

View File

@ -1,13 +1,18 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.common.*; import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.manager.DisposeDeviceManager; import com.dispose.manager.DisposeDeviceManager;
import com.dispose.manager.DisposeTaskManager; import com.dispose.manager.DisposeTaskManager;
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.DisposeTaskService; import com.dispose.service.DisposeTaskService;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.dispose.test.service; package com.dispose.test.dev.service;
import com.dispose.common.AuthConfigValue; import com.dispose.common.AuthConfigValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
@ -6,7 +6,7 @@ import com.dispose.config.DisposeConfigure;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -1,11 +1,11 @@
package com.dispose.qa.test.controller; package com.dispose.test.qa.controller;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.ProtoCryptoType; import com.dispose.common.ProtoCryptoType;
import com.dispose.pojo.dto.protocol.auth.LoginReq; import com.dispose.pojo.dto.protocol.auth.LoginReq;
import com.dispose.pojo.dto.protocol.auth.LoginRsp; import com.dispose.pojo.dto.protocol.auth.LoginRsp;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.qa.test.common.CommonRestful; import com.dispose.test.common.CommonRestful;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;

View File

@ -0,0 +1,176 @@
package com.dispose.test.qa.controller;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.Helper;
import com.dispose.common.HttpType;
import com.dispose.common.IpAddrType;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.dto.protocol.device.manager.AddCapacityInfo;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceInfo;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceReq;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp;
import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.test.common.CommonRestful;
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.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The type P 1 device manager controller test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Slf4j
@Transactional
@Rollback
public class P1DeviceManagerControllerTest extends CommonRestful {
/**
* The Dispose device manager service.
*/
@Resource
private DisposeDeviceManagerService disposeDeviceManagerService;
/**
* Gets unused device port.
*
* @param beginPort the begin port
* @return the unused device port
*/
private String getUnusedDevicePort(Integer beginPort) {
AtomicInteger aPort = new AtomicInteger();
aPort.set(beginPort);
while (disposeDeviceManagerService.getAllDisposeDevice()
.stream()
.anyMatch(k -> String.valueOf(aPort.getAndIncrement())
.equals(Helper.ipPortNormalize(k.getIpPort(),
k.getUrlType())))
) {
beginPort = aPort.get();
}
return beginPort.toString();
}
/**
* A 1 un login request add device.
*
* @throws Exception the exception
*/
@Test
public void a1_unLoginRequestAddDevice() throws Exception {
AddDeviceReq addReq = AddDeviceReq.builder()
.items(new ArrayList<>())
.build();
List<AddCapacityInfo> newCapList = new ArrayList<>();
newCapList.add(AddCapacityInfo.builder()
.capacityType(DisposeCapacityType.CLEANUP.getValue())
.objectType(DisposeObjectType.IP.getValue())
.ipType(IpAddrType.IPV4_IPV6.getValue())
.protectIp("")
.build());
addReq.getItems().add(AddDeviceInfo.builder()
.ipAddr("127.0.0.1")
.ipPort("1000")
.deviceType(DisposeDeviceType.VIRTUAL_DISPOSE.getValue())
.areaCode(0)
.deviceName("实验室虚拟清洗设备")
.manufacturer("CMCC")
.model("Virtual")
.version("v0.0.1")
.userName("admin")
.password("admin")
.urlPath("")
.urlType(HttpType.HTTP.getValue())
.readme("实验室虚拟测试设备")
.capacity(newCapList)
.build());
ProtocolRespDTO<AddDeviceRsp> rspInfo = performanceRestfulFail(addReq,
"/manager/device",
AddDeviceRsp.class,
"123245125123532",
ErrorCode.ERR_LOGOUT,
RequestMethod.PUT);
Assert.assertNotNull(rspInfo);
Assert.assertNotNull(rspInfo.getMsgContent());
Assert.assertEquals((long) rspInfo.getMsgContent().getStatus(), ErrorCode.ERR_LOGOUT.getCode());
}
/**
* A 2 add new device.
*/
@Test
public void a2_addNewDevice() throws Exception {
AddDeviceReq addReq = AddDeviceReq.builder()
.items(new ArrayList<>())
.build();
List<AddCapacityInfo> newCapList = new ArrayList<>();
newCapList.add(AddCapacityInfo.builder()
.capacityType(DisposeCapacityType.CLEANUP.getValue())
.objectType(DisposeObjectType.IP.getValue())
.ipType(IpAddrType.IPV4.getValue())
.protectIp("192.168.20.1/24")
.reserveNetflow(10)
.build());
newCapList.add(AddCapacityInfo.builder()
.capacityType(DisposeCapacityType.BLACKHOOL.getValue())
.objectType(DisposeObjectType.URL.getValue())
.ipType(IpAddrType.IPV6.getValue())
.build());
addReq.getItems().add(AddDeviceInfo.builder()
.ipAddr("127.0.0.1")
.ipPort(getUnusedDevicePort(1000))
.deviceType(DisposeDeviceType.VIRTUAL_DISPOSE.getValue())
.areaCode(0)
.deviceName("实验室虚拟清洗设备")
.manufacturer("CMCC")
.model("Virtual")
.version("v0.0.1")
.userName("admin")
.password("admin")
.urlPath("")
.urlType(HttpType.HTTP.getValue())
.readme("实验室虚拟测试设备")
.capacity(newCapList)
.build());
ProtocolRespDTO<AddDeviceRsp> rspInfo = performanceRestfulSuccess(addReq,
"/manager/device",
AddDeviceRsp.class,
getLoginToken(),
RequestMethod.PUT);
Assert.assertNotNull(rspInfo);
Assert.assertNotNull(rspInfo.getMsgContent());
}
}