From bcdc2a7020e884f06da0568e23babcc5740dfe91 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 10 Sep 2020 09:21:42 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E9=87=8D=E6=9E=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=202.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0JSON=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qa/test/common/CommonEnvironment.java | 14 - .../P1DeviceManagerControllerTest.java | 90 ------ .../test/common/CommonEnvironment.java | 87 ++++++ .../{qa => }/test/common/CommonRestful.java | 159 +--------- .../test/common/CommonRestfulJson.java | 80 +++++ .../java/com/dispose/test/common/Helper.java | 93 ++++++ .../java/com/dispose/test/debug/demo.java | 247 --------------- .../{ => dev}/Global/InitTestEnvironment.java | 2 +- .../controller/AuthControllerTest.java | 4 +- .../DisposeDeviceManagerControllerTest.java | 4 +- .../controller/DisposeInfoControllerTest.java | 4 +- .../controller/DisposeTaskControllerTest.java | 9 +- .../java/com/dispose/test/dev/debug/demo.java | 281 ++++++++++++++++++ .../dptech/DPTechInterfaceTestCase.java | 4 +- .../haohan/HAOHanInterfaceTestCast.java | 4 +- .../manager/DeviceTaskManagerTest.java | 2 +- .../manager/DisposeDeviceManagerTest.java | 10 +- .../manager/DisposeTaskManagerTest.java | 8 +- .../manager/UserAccountManagerTest.java | 4 +- .../mapper/DeviceTaskMapperTest.java | 2 +- .../mapper/DisposeCapacityMapperTest.java | 18 +- .../mapper/DisposeDeviceMapperTest.java | 2 +- .../mapper/DisposeTaskMapperTest.java | 2 +- .../mapper/UserAccountMapperTest.java | 2 +- .../service/AreaCodeManagerServiceTest.java | 4 +- .../service/DeviceTaskManagerServiceTest.java | 9 +- .../DisposeAbilityRouterServiceTest.java | 10 +- .../DisposeDeviceManagerServiceTest.java | 15 +- .../service/DisposeTaskServiceTest.java | 11 +- .../service/UserAccountServiceTest.java | 4 +- .../qa}/controller/P1AuthControllerTest.java | 4 +- .../P1DeviceManagerControllerTest.java | 176 +++++++++++ 32 files changed, 811 insertions(+), 554 deletions(-) delete mode 100644 src/test/java/com/dispose/qa/test/common/CommonEnvironment.java delete mode 100644 src/test/java/com/dispose/qa/test/controller/P1DeviceManagerControllerTest.java create mode 100644 src/test/java/com/dispose/test/common/CommonEnvironment.java rename src/test/java/com/dispose/{qa => }/test/common/CommonRestful.java (54%) create mode 100644 src/test/java/com/dispose/test/common/CommonRestfulJson.java create mode 100644 src/test/java/com/dispose/test/common/Helper.java delete mode 100644 src/test/java/com/dispose/test/debug/demo.java rename src/test/java/com/dispose/test/{ => dev}/Global/InitTestEnvironment.java (98%) rename src/test/java/com/dispose/test/{ => dev}/controller/AuthControllerTest.java (98%) rename src/test/java/com/dispose/test/{ => dev}/controller/DisposeDeviceManagerControllerTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/controller/DisposeInfoControllerTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/controller/DisposeTaskControllerTest.java (97%) create mode 100644 src/test/java/com/dispose/test/dev/debug/demo.java rename src/test/java/com/dispose/test/{ => dev}/dptech/DPTechInterfaceTestCase.java (98%) rename src/test/java/com/dispose/test/{ => dev}/haohan/HAOHanInterfaceTestCast.java (98%) rename src/test/java/com/dispose/test/{ => dev}/manager/DeviceTaskManagerTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/manager/DisposeDeviceManagerTest.java (96%) rename src/test/java/com/dispose/test/{ => dev}/manager/DisposeTaskManagerTest.java (96%) rename src/test/java/com/dispose/test/{ => dev}/manager/UserAccountManagerTest.java (98%) rename src/test/java/com/dispose/test/{ => dev}/mapper/DeviceTaskMapperTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/mapper/DisposeCapacityMapperTest.java (89%) rename src/test/java/com/dispose/test/{ => dev}/mapper/DisposeDeviceMapperTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/mapper/DisposeTaskMapperTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/mapper/UserAccountMapperTest.java (99%) rename src/test/java/com/dispose/test/{ => dev}/service/AreaCodeManagerServiceTest.java (93%) rename src/test/java/com/dispose/test/{ => dev}/service/DeviceTaskManagerServiceTest.java (92%) rename src/test/java/com/dispose/test/{ => dev}/service/DisposeAbilityRouterServiceTest.java (97%) rename src/test/java/com/dispose/test/{ => dev}/service/DisposeDeviceManagerServiceTest.java (94%) rename src/test/java/com/dispose/test/{ => dev}/service/DisposeTaskServiceTest.java (95%) rename src/test/java/com/dispose/test/{ => dev}/service/UserAccountServiceTest.java (97%) rename src/test/java/com/dispose/{qa/test => test/qa}/controller/P1AuthControllerTest.java (97%) create mode 100644 src/test/java/com/dispose/test/qa/controller/P1DeviceManagerControllerTest.java diff --git a/src/test/java/com/dispose/qa/test/common/CommonEnvironment.java b/src/test/java/com/dispose/qa/test/common/CommonEnvironment.java deleted file mode 100644 index e348e7c6..00000000 --- a/src/test/java/com/dispose/qa/test/common/CommonEnvironment.java +++ /dev/null @@ -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 - */ -@Slf4j -@ActiveProfiles("test,dispose") -public class CommonEnvironment { -} diff --git a/src/test/java/com/dispose/qa/test/controller/P1DeviceManagerControllerTest.java b/src/test/java/com/dispose/qa/test/controller/P1DeviceManagerControllerTest.java deleted file mode 100644 index 1c922918..00000000 --- a/src/test/java/com/dispose/qa/test/controller/P1DeviceManagerControllerTest.java +++ /dev/null @@ -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 - */ -@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 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 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()); - } -} diff --git a/src/test/java/com/dispose/test/common/CommonEnvironment.java b/src/test/java/com/dispose/test/common/CommonEnvironment.java new file mode 100644 index 00000000..77c6f722 --- /dev/null +++ b/src/test/java/com/dispose/test/common/CommonEnvironment.java @@ -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 + */ +@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 = userAccountMapper.selectAll().stream().findFirst(); + + if (userAccount.isPresent()) { + this.userName = userAccount.get().getUsername(); + this.password = userAccount.get().getPassword(); + } + + MulReturnType 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 ""; + } +} diff --git a/src/test/java/com/dispose/qa/test/common/CommonRestful.java b/src/test/java/com/dispose/test/common/CommonRestful.java similarity index 54% rename from src/test/java/com/dispose/qa/test/common/CommonRestful.java rename to src/test/java/com/dispose/test/common/CommonRestful.java index 2727a3cd..6e46790b 100644 --- a/src/test/java/com/dispose/qa/test/common/CommonRestful.java +++ b/src/test/java/com/dispose/test/common/CommonRestful.java @@ -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.ErrorCode; 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.ProtocolRespDTO; -import com.dispose.pojo.entity.UserAccount; -import com.dispose.pojo.po.MulReturnType; import com.dispose.service.ProtocolSecurityService; -import com.dispose.service.UserAccountService; 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.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.annotation.PostConstruct; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; 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. @@ -45,40 +28,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 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. */ @Resource private ProtocolSecurityService protocolSecurityService; - /** - * The User account mapper. - */ - @Resource - private UserAccountMapper userAccountMapper; - /** * The Mock mvc. */ @@ -91,95 +46,6 @@ public class CommonRestful extends CommonEnvironment { @Resource private ObjectMapper objectMapper; - /** - * Init global value. - * - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @PostConstruct - private void initGlobalValue() throws NoSuchAlgorithmException { - Optional userAccount = userAccountMapper.selectAll().stream().findFirst(); - - if (userAccount.isPresent()) { - this.userName = userAccount.get().getUsername(); - this.password = userAccount.get().getPassword(); - } - - MulReturnType ret = userAccountService.loginService(userName, password); - - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - this.loginToken = ret.getSecondParam(); - } - } - - /** - * Create resp type type. - * - * @param the type parameter - * @param c the c - * @return the type - */ - private Type createRespType(Class 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. * @@ -189,9 +55,10 @@ public class CommonRestful extends CommonEnvironment { * @param urlPath the url path * @param subClass the sub class * @param reqCryptoType the req crypto type - * @param errCode the http code + * @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 */ @@ -225,7 +92,7 @@ public class CommonRestful extends CommonEnvironment { sendMsgContent = objectMapper.writeValueAsString(reqInfo); } - rspValue = restfulRun(reqType, urlPath, loginToken, sendMsgContent, errCode); + rspValue = Helper.restfulRun(mockMvc, reqType, urlPath, loginToken, sendMsgContent, errCode); if (autoDecrypt) { rspValue = protocolSecurityService.decryptProtocol(rspValue); @@ -235,7 +102,7 @@ public class CommonRestful extends CommonEnvironment { new TypeReference>() { @Override 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 subClass the sub class * @param loginToken the login token + * @param reqType the req type * @return the protocol resp dto * @throws Exception the exception */ @@ -267,13 +135,14 @@ public class CommonRestful extends CommonEnvironment { /** * Performance restful fail protocol resp dto. * - * @param the type parameter - * @param the type parameter - * @param reqObject the req object - * @param urlPath the url path - * @param subClass the sub class - * @param loginToken the login token - * @param errCode the http err code + * @param the type parameter + * @param the type parameter + * @param reqObject the req object + * @param urlPath the url path + * @param subClass the sub class + * @param loginToken the login token + * @param errCode the err code + * @param reqType the req type * @return the protocol resp dto * @throws Exception the exception */ diff --git a/src/test/java/com/dispose/test/common/CommonRestfulJson.java b/src/test/java/com/dispose/test/common/CommonRestfulJson.java new file mode 100644 index 00000000..e4f0998b --- /dev/null +++ b/src/test/java/com/dispose/test/common/CommonRestfulJson.java @@ -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 + */ +@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 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 ProtocolRespDTO performanceRestful(String reqJson, String urlPath, + Class 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>() { + @Override + public Type getType() { + return Helper.createRespType(subClass); + } + }); + } +} diff --git a/src/test/java/com/dispose/test/common/Helper.java b/src/test/java/com/dispose/test/common/Helper.java new file mode 100644 index 00000000..4c900521 --- /dev/null +++ b/src/test/java/com/dispose/test/common/Helper.java @@ -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 + */ +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 the type parameter + * @param c the c + * @return the type + */ + public static Type createRespType(Class c) { + Type[] types = new Type[1]; + types[0] = c; + return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types, + ProtocolRespDTO.class.getDeclaringClass()); + } +} diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java deleted file mode 100644 index 56ba6450..00000000 --- a/src/test/java/com/dispose/test/debug/demo.java +++ /dev/null @@ -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 - */ -@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 the type parameter - * @param destDev the dest dev - * @param srcDev the src dev - * @return the t - */ - private 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)); - } - -} diff --git a/src/test/java/com/dispose/test/Global/InitTestEnvironment.java b/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java similarity index 98% rename from src/test/java/com/dispose/test/Global/InitTestEnvironment.java rename to src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java index 9e86b76a..5044f020 100644 --- a/src/test/java/com/dispose/test/Global/InitTestEnvironment.java +++ b/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java @@ -1,4 +1,4 @@ -package com.dispose.test.Global; +package com.dispose.test.dev.Global; import com.dispose.common.ConstValue; import com.dispose.common.DisposeConfigValue; diff --git a/src/test/java/com/dispose/test/controller/AuthControllerTest.java b/src/test/java/com/dispose/test/dev/controller/AuthControllerTest.java similarity index 98% rename from src/test/java/com/dispose/test/controller/AuthControllerTest.java rename to src/test/java/com/dispose/test/dev/controller/AuthControllerTest.java index d48e381b..0332fd4c 100644 --- a/src/test/java/com/dispose/test/controller/AuthControllerTest.java +++ b/src/test/java/com/dispose/test/dev/controller/AuthControllerTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.controller; +package com.dispose.test.dev.controller; import com.dispose.common.ConstValue; 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.base.ProtocolReqDTO; 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.databind.ObjectMapper; import jodd.net.HttpStatus; diff --git a/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java b/src/test/java/com/dispose/test/dev/controller/DisposeDeviceManagerControllerTest.java similarity index 99% rename from src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java rename to src/test/java/com/dispose/test/dev/controller/DisposeDeviceManagerControllerTest.java index ce813665..e56d6747 100644 --- a/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java +++ b/src/test/java/com/dispose/test/dev/controller/DisposeDeviceManagerControllerTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.controller; +package com.dispose.test.dev.controller; import com.dispose.common.ConstValue; 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.entity.DisposeDevice; 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.databind.ObjectMapper; import jodd.net.HttpStatus; diff --git a/src/test/java/com/dispose/test/controller/DisposeInfoControllerTest.java b/src/test/java/com/dispose/test/dev/controller/DisposeInfoControllerTest.java similarity index 99% rename from src/test/java/com/dispose/test/controller/DisposeInfoControllerTest.java rename to src/test/java/com/dispose/test/dev/controller/DisposeInfoControllerTest.java index 0bb14ab1..d3009c82 100644 --- a/src/test/java/com/dispose/test/controller/DisposeInfoControllerTest.java +++ b/src/test/java/com/dispose/test/dev/controller/DisposeInfoControllerTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.controller; +package com.dispose.test.dev.controller; import com.dispose.common.ConstValue; 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.GetPlatformVerInfoRsp; 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.databind.ObjectMapper; import jodd.net.HttpStatus; diff --git a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java b/src/test/java/com/dispose/test/dev/controller/DisposeTaskControllerTest.java similarity index 97% rename from src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java rename to src/test/java/com/dispose/test/dev/controller/DisposeTaskControllerTest.java index 85108a09..e118d3b2 100644 --- a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java +++ b/src/test/java/com/dispose/test/dev/controller/DisposeTaskControllerTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.controller; +package com.dispose.test.dev.controller; import com.dispose.common.ConstValue; 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.ProtocolRespDTO; 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.po.MulReturnType; import com.dispose.service.DisposeDeviceManagerService; 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.databind.ObjectMapper; import com.github.pagehelper.PageInfo; diff --git a/src/test/java/com/dispose/test/dev/debug/demo.java b/src/test/java/com/dispose/test/dev/debug/demo.java new file mode 100644 index 00000000..3412f1f4 --- /dev/null +++ b/src/test/java/com/dispose/test/dev/debug/demo.java @@ -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 + */ +@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 the type parameter + * @param destDev the dest dev + * @param srcDev the src dev + * @return the t + */ + private 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 orgList = Arrays.asList(org); + List diffList = Arrays.asList(diff); + + + Map> 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); +// } + } + } + +} diff --git a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/test/dev/dptech/DPTechInterfaceTestCase.java similarity index 98% rename from src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java rename to src/test/java/com/dispose/test/dev/dptech/DPTechInterfaceTestCase.java index 7440d99f..0cbd8a5f 100644 --- a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java +++ b/src/test/java/com/dispose/test/dev/dptech/DPTechInterfaceTestCase.java @@ -1,4 +1,4 @@ -package com.dispose.test.dptech; +package com.dispose.test.dev.dptech; import com.dispose.ability.DisposeAbility; 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.po.MulReturnType; 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 org.junit.Assert; import org.junit.FixMethodOrder; diff --git a/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java b/src/test/java/com/dispose/test/dev/haohan/HAOHanInterfaceTestCast.java similarity index 98% rename from src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java rename to src/test/java/com/dispose/test/dev/haohan/HAOHanInterfaceTestCast.java index d97c9d7e..6f24544c 100644 --- a/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java +++ b/src/test/java/com/dispose/test/dev/haohan/HAOHanInterfaceTestCast.java @@ -1,4 +1,4 @@ -package com.dispose.test.haohan; +package com.dispose.test.dev.haohan; import com.dispose.ability.DisposeAbility; 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.po.MulReturnType; 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 org.junit.Assert; import org.junit.FixMethodOrder; diff --git a/src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java b/src/test/java/com/dispose/test/dev/manager/DeviceTaskManagerTest.java similarity index 99% rename from src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java rename to src/test/java/com/dispose/test/dev/manager/DeviceTaskManagerTest.java index 6a93461a..868facd7 100644 --- a/src/test/java/com/dispose/test/manager/DeviceTaskManagerTest.java +++ b/src/test/java/com/dispose/test/dev/manager/DeviceTaskManagerTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.manager; +package com.dispose.test.dev.manager; import com.dispose.common.DisposeTaskStatus; import com.dispose.common.NetflowDirection; diff --git a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java b/src/test/java/com/dispose/test/dev/manager/DisposeDeviceManagerTest.java similarity index 96% rename from src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java rename to src/test/java/com/dispose/test/dev/manager/DisposeDeviceManagerTest.java index dc33b9c1..1581619a 100644 --- a/src/test/java/com/dispose/test/manager/DisposeDeviceManagerTest.java +++ b/src/test/java/com/dispose/test/dev/manager/DisposeDeviceManagerTest.java @@ -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.mapper.DisposeDeviceMapper; import com.dispose.pojo.entity.DisposeCapacity; diff --git a/src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java b/src/test/java/com/dispose/test/dev/manager/DisposeTaskManagerTest.java similarity index 96% rename from src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java rename to src/test/java/com/dispose/test/dev/manager/DisposeTaskManagerTest.java index 74f22d85..7eea3d85 100644 --- a/src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java +++ b/src/test/java/com/dispose/test/dev/manager/DisposeTaskManagerTest.java @@ -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.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; diff --git a/src/test/java/com/dispose/test/manager/UserAccountManagerTest.java b/src/test/java/com/dispose/test/dev/manager/UserAccountManagerTest.java similarity index 98% rename from src/test/java/com/dispose/test/manager/UserAccountManagerTest.java rename to src/test/java/com/dispose/test/dev/manager/UserAccountManagerTest.java index 2a85cbf5..7fa47d1f 100644 --- a/src/test/java/com/dispose/test/manager/UserAccountManagerTest.java +++ b/src/test/java/com/dispose/test/dev/manager/UserAccountManagerTest.java @@ -1,11 +1,11 @@ -package com.dispose.test.manager; +package com.dispose.test.dev.manager; import com.dispose.common.ErrorCode; import com.dispose.common.ObjectStatus; import com.dispose.manager.UserAccountManager; import com.dispose.mapper.UserAccountMapper; 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.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/dispose/test/mapper/DeviceTaskMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java similarity index 99% rename from src/test/java/com/dispose/test/mapper/DeviceTaskMapperTest.java rename to src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java index a35b8e9e..397a29fa 100644 --- a/src/test/java/com/dispose/test/mapper/DeviceTaskMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.mapper; +package com.dispose.test.dev.mapper; import com.dispose.common.DisposeTaskStatus; import com.dispose.mapper.DeviceTaskMapper; diff --git a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/DisposeCapacityMapperTest.java similarity index 89% rename from src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java rename to src/test/java/com/dispose/test/dev/mapper/DisposeCapacityMapperTest.java index 76f5f283..246c33b5 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/DisposeCapacityMapperTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.mapper; +package com.dispose.test.dev.mapper; import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeObjectType; @@ -61,15 +61,13 @@ public class DisposeCapacityMapperTest { public void a1_addNewDisposeCapacity() throws JsonProcessingException { List newCapList = new ArrayList<>(); - disposeDeviceMapper.selectAll().forEach(v -> { - newCapList.add(DisposeCapacity.builder() - .deviceId(v.getId()) - .capacityType(DisposeCapacityType.CLEANUP) - .objectType(DisposeObjectType.IP) - .ipType(IpAddrType.IPV4_IPV6) - .protectIp("0.0.0.0") - .build()); - }); + disposeDeviceMapper.selectAll().forEach(v -> newCapList.add(DisposeCapacity.builder() + .deviceId(v.getId()) + .capacityType(DisposeCapacityType.CLEANUP) + .objectType(DisposeObjectType.IP) + .ipType(IpAddrType.IPV4_IPV6) + .protectIp("0.0.0.0") + .build())); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newCapList)); diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/DisposeDeviceMapperTest.java similarity index 99% rename from src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java rename to src/test/java/com/dispose/test/dev/mapper/DisposeDeviceMapperTest.java index 8cb892ba..fa7914c1 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/DisposeDeviceMapperTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.mapper; +package com.dispose.test.dev.mapper; import com.dispose.common.DisposeDeviceType; import com.dispose.common.HttpType; diff --git a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/DisposeTaskMapperTest.java similarity index 99% rename from src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java rename to src/test/java/com/dispose/test/dev/mapper/DisposeTaskMapperTest.java index 6ec15e8d..c0375825 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/DisposeTaskMapperTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.mapper; +package com.dispose.test.dev.mapper; import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeCapacityType; diff --git a/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java similarity index 99% rename from src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java rename to src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java index b26a1ccf..6c7ea4d1 100644 --- a/src/test/java/com/dispose/test/mapper/UserAccountMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/UserAccountMapperTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.mapper; +package com.dispose.test.dev.mapper; import com.dispose.common.Helper; import com.dispose.common.ObjectStatus; diff --git a/src/test/java/com/dispose/test/service/AreaCodeManagerServiceTest.java b/src/test/java/com/dispose/test/dev/service/AreaCodeManagerServiceTest.java similarity index 93% rename from src/test/java/com/dispose/test/service/AreaCodeManagerServiceTest.java rename to src/test/java/com/dispose/test/dev/service/AreaCodeManagerServiceTest.java index 2a223c7e..a0edb50c 100644 --- a/src/test/java/com/dispose/test/service/AreaCodeManagerServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/AreaCodeManagerServiceTest.java @@ -1,7 +1,7 @@ -package com.dispose.test.service; +package com.dispose.test.dev.service; import com.dispose.service.AreaCodeManagerService; -import com.dispose.test.Global.InitTestEnvironment; +import com.dispose.test.dev.Global.InitTestEnvironment; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.FixMethodOrder; diff --git a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java b/src/test/java/com/dispose/test/dev/service/DeviceTaskManagerServiceTest.java similarity index 92% rename from src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java rename to src/test/java/com/dispose/test/dev/service/DeviceTaskManagerServiceTest.java index 74d9a88b..82b8608f 100644 --- a/src/test/java/com/dispose/test/service/DeviceTaskManagerServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/DeviceTaskManagerServiceTest.java @@ -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.DisposeTaskManager; import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DeviceTaskManagerService; 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.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java b/src/test/java/com/dispose/test/dev/service/DisposeAbilityRouterServiceTest.java similarity index 97% rename from src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java rename to src/test/java/com/dispose/test/dev/service/DisposeAbilityRouterServiceTest.java index 8139ea09..86d340d1 100644 --- a/src/test/java/com/dispose/test/service/DisposeAbilityRouterServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/DisposeAbilityRouterServiceTest.java @@ -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.pojo.entity.DisposeCapacity; 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.service.DisposeAbilityRouterService; 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.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java b/src/test/java/com/dispose/test/dev/service/DisposeDeviceManagerServiceTest.java similarity index 94% rename from src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java rename to src/test/java/com/dispose/test/dev/service/DisposeDeviceManagerServiceTest.java index 91678024..d8fd21c7 100644 --- a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/DisposeDeviceManagerServiceTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.service; +package com.dispose.test.dev.service; import com.dispose.common.DisposeDeviceType; import com.dispose.common.ErrorCode; @@ -9,7 +9,7 @@ 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.dispose.test.dev.Global.InitTestEnvironment; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageInfo; @@ -190,21 +190,20 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { List devs = disposeDeviceMapper.selectAll(); for (int i = 1; i < 5; i++) { - int startPage = i; int pageSize = i * 2; - MulReturnType, List> ret = disposeDeviceManagerService.getPageDisposeDevice(startPage, pageSize); + MulReturnType, List> ret = disposeDeviceManagerService.getPageDisposeDevice(i, pageSize); PageInfo pageInfo = ret.getFirstParam(); - Assert.assertEquals(pageInfo.getPageNum(), startPage); + Assert.assertEquals(pageInfo.getPageNum(), i); Assert.assertEquals(pageInfo.getPageSize(), pageSize); //数据库设备信息数据量比较大 - if (devs.size() >= (startPage * pageSize)) { + if (devs.size() >= (i * pageSize)) { if (pageInfo.getPageNum() != 1) { Assert.assertFalse(pageInfo.isIsFirstPage()); Assert.assertTrue(pageInfo.isHasPreviousPage()); - Assert.assertEquals(pageInfo.getPrePage(), startPage - 1); + Assert.assertEquals(pageInfo.getPrePage(), i - 1); } else { Assert.assertTrue(pageInfo.isIsFirstPage()); Assert.assertFalse(pageInfo.isHasPreviousPage()); @@ -213,7 +212,7 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment { if (pageInfo.getPageNum() != 1) { Assert.assertFalse(pageInfo.isIsFirstPage()); Assert.assertTrue(pageInfo.isHasPreviousPage()); - Assert.assertEquals(pageInfo.getPrePage(), startPage - 1); + Assert.assertEquals(pageInfo.getPrePage(), i - 1); } else { Assert.assertTrue(pageInfo.isIsFirstPage()); Assert.assertFalse(pageInfo.isHasNextPage()); diff --git a/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java b/src/test/java/com/dispose/test/dev/service/DisposeTaskServiceTest.java similarity index 95% rename from src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java rename to src/test/java/com/dispose/test/dev/service/DisposeTaskServiceTest.java index f0761ca5..4b73b93a 100644 --- a/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/DisposeTaskServiceTest.java @@ -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.DisposeTaskManager; import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DisposeTaskService; 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.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/dispose/test/service/UserAccountServiceTest.java b/src/test/java/com/dispose/test/dev/service/UserAccountServiceTest.java similarity index 97% rename from src/test/java/com/dispose/test/service/UserAccountServiceTest.java rename to src/test/java/com/dispose/test/dev/service/UserAccountServiceTest.java index 3e796a7d..267bfb69 100644 --- a/src/test/java/com/dispose/test/service/UserAccountServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/UserAccountServiceTest.java @@ -1,4 +1,4 @@ -package com.dispose.test.service; +package com.dispose.test.dev.service; import com.dispose.common.AuthConfigValue; import com.dispose.common.ErrorCode; @@ -6,7 +6,7 @@ import com.dispose.config.DisposeConfigure; import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.UserAccountService; -import com.dispose.test.Global.InitTestEnvironment; +import com.dispose.test.dev.Global.InitTestEnvironment; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.Before; diff --git a/src/test/java/com/dispose/qa/test/controller/P1AuthControllerTest.java b/src/test/java/com/dispose/test/qa/controller/P1AuthControllerTest.java similarity index 97% rename from src/test/java/com/dispose/qa/test/controller/P1AuthControllerTest.java rename to src/test/java/com/dispose/test/qa/controller/P1AuthControllerTest.java index 6175f08d..7bf9409d 100644 --- a/src/test/java/com/dispose/qa/test/controller/P1AuthControllerTest.java +++ b/src/test/java/com/dispose/test/qa/controller/P1AuthControllerTest.java @@ -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.ProtoCryptoType; import com.dispose.pojo.dto.protocol.auth.LoginReq; import com.dispose.pojo.dto.protocol.auth.LoginRsp; 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 org.junit.Assert; import org.junit.FixMethodOrder; diff --git a/src/test/java/com/dispose/test/qa/controller/P1DeviceManagerControllerTest.java b/src/test/java/com/dispose/test/qa/controller/P1DeviceManagerControllerTest.java new file mode 100644 index 00000000..1f7f9f23 --- /dev/null +++ b/src/test/java/com/dispose/test/qa/controller/P1DeviceManagerControllerTest.java @@ -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 + */ +@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 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 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 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 rspInfo = performanceRestfulSuccess(addReq, + "/manager/device", + AddDeviceRsp.class, + getLoginToken(), + RequestMethod.PUT); + + Assert.assertNotNull(rspInfo); + Assert.assertNotNull(rspInfo.getMsgContent()); + } +}