diff --git a/src/main/java/com/dispose/PhoenixBootApplication.java b/src/main/java/com/dispose/PhoenixBootApplication.java index ff1908c5..5ed1e628 100644 --- a/src/main/java/com/dispose/PhoenixBootApplication.java +++ b/src/main/java/com/dispose/PhoenixBootApplication.java @@ -30,7 +30,8 @@ public class PhoenixBootApplication { SpringApplication.run(PhoenixBootApplication.class, args); log.info("\n----------------------------------------------------------\n\t" + "Phoenix Application is running! Access URLs:\n\t" - + "swagger-ui: \thttp://ip:port/${context-path}/swagger-ui.html\n\t" + "If you set the api switch true! \n\t" + + "swagger-ui: \thttp://ip:port/${context-path}/swagger-ui.html\n\t" + "If you set the api switch " + + "true! \n\t" + "----------------------------------------------------------"); } diff --git a/src/main/java/com/dispose/annotation/validator/UserIdValidator.java b/src/main/java/com/dispose/annotation/validator/UserIdValidator.java index 3db09565..1f24e451 100644 --- a/src/main/java/com/dispose/annotation/validator/UserIdValidator.java +++ b/src/main/java/com/dispose/annotation/validator/UserIdValidator.java @@ -12,6 +12,8 @@ import javax.validation.ConstraintValidatorContext; */ public class UserIdValidator implements ConstraintValidator { + private final Set idSet = Sets.newHashSet(1L, 2L); + /** * 快速失败模式下,这里无法注入依赖 参数校验的数据源相关校验放到controller里 方法抽象到下层service中 */ @@ -24,8 +26,6 @@ public class UserIdValidator implements ConstraintValidator { return existsById(aLong); } - private final Set idSet = Sets.newHashSet(1L, 2L); - private boolean existsById(long aId) { return idSet.contains(aId); } diff --git a/src/main/java/com/dispose/aop/cache/MyCacheInterceptor.java b/src/main/java/com/dispose/aop/cache/MyCacheInterceptor.java index 5398df96..9dc31f71 100644 --- a/src/main/java/com/dispose/aop/cache/MyCacheInterceptor.java +++ b/src/main/java/com/dispose/aop/cache/MyCacheInterceptor.java @@ -43,10 +43,9 @@ public class MyCacheInterceptor { * 系统统一缓存key前缀 */ public static final String CACHE_PREFIX = "PHOENIX_IC" + SPILIT; - private static final ExpressionParser parser = new SpelExpressionParser(); // SpelExpressionParser spelExpressionParser = new SpelExpressionParser(); public static final String CACHE_NULL = "NULL"; - + private static final ExpressionParser parser = new SpelExpressionParser(); @Resource private RedisClient redisClient; diff --git a/src/main/java/com/dispose/common/ConstValue.java b/src/main/java/com/dispose/common/ConstValue.java index de53093d..fb8d55c2 100644 --- a/src/main/java/com/dispose/common/ConstValue.java +++ b/src/main/java/com/dispose/common/ConstValue.java @@ -4,77 +4,6 @@ package com.dispose.common; * The type Const value. */ public class ConstValue { - /** - * The type Global configure. - */ - public static class GlobalConfigure { - /** - * The constant TOKEN_TIMEOUT_MS. - */ - public static final int TOKEN_TIMEOUT_MS = 30 * 60 * 1000; - /** - * The constant ALLOW_PWD_ERR_TIMES. - */ - public static final int ALLOW_PWD_ERR_TIMES = 5; - /** - * The constant IS_SKIP_TIMEOUT_CHECK. - */ - public static final boolean IS_SKIP_TIMEOUT_CHECK = true; - /** - * The constant IS_VERIFY_TOKEN. - */ - public static final boolean IS_VERIFY_TOKEN = false; - /** - * The constant TOKEN_EXPIRED_TIME_MS. - */ - public static final long TOKEN_EXPIRED_TIME_MS = 1000 * 60 * 60; - } - - /** - * The type Soap wrapper const. - */ - public static class SOAPWrapperConst { - /** - * The constant NAMESPACE_URI. - */ - public static final String NAMESPACE_URI = "http://%s/UMC/service/AbnormalFlowCleaningService"; - /** - * The constant USER_NAME. - */ -//public static final String SERVICE_ADDRESS = "http://10.88.77.15/UMC/service/AbnormalFlowCleaningService?wsdl"; - public static final String USER_NAME = "admin"; - /** - * The constant PASSWORD. - */ - public static final String PASSWORD = "UMCAdministrator"; - } - - /** - * The type Protocol. - */ - public static class Protocol { - /** - * The constant RESP_CMD_BASE. - */ - public static final int RESP_CMD_BASE = 10000; - /** - * The constant VERSION. - */ - public static final int VERSION = 2; - /** - * The constant CRYPTO_NONE. - */ - public static final int CRYPTO_NONE = 0; - /** - * The constant CRYPTO_BASE64. - */ - public static final int CRYPTO_BASE64 = 1; - /** - * The constant CRYPTO_AES256. - */ - public static final int CRYPTO_AES256 = 2; - } - /** * The enum Dispose device type. */ @@ -120,20 +49,6 @@ public class ConstValue { } } - /** - * The type User account status. - */ - public static class UserAccountStatus { - /** - * The constant NORMAL. - */ - public static final int NORMAL = 0; - /** - * The constant LOCKED. - */ - public static final int LOCKED = 1; - } - /** * The enum Device capacity. */ @@ -209,4 +124,89 @@ public class ConstValue { } } } + + /** + * The type Global configure. + */ + public static class GlobalConfigure { + /** + * The constant TOKEN_TIMEOUT_MS. + */ + public static final int TOKEN_TIMEOUT_MS = 30 * 60 * 1000; + /** + * The constant ALLOW_PWD_ERR_TIMES. + */ + public static final int ALLOW_PWD_ERR_TIMES = 5; + /** + * The constant IS_SKIP_TIMEOUT_CHECK. + */ + public static final boolean IS_SKIP_TIMEOUT_CHECK = true; + /** + * The constant IS_VERIFY_TOKEN. + */ + public static final boolean IS_VERIFY_TOKEN = false; + /** + * The constant TOKEN_EXPIRED_TIME_MS. + */ + public static final long TOKEN_EXPIRED_TIME_MS = 1000 * 60 * 60; + } + + /** + * The type Soap wrapper const. + */ + public static class SOAPWrapperConst { + /** + * The constant NAMESPACE_URI. + */ + public static final String NAMESPACE_URI = "http://%s/UMC/service/AbnormalFlowCleaningService"; + /** + * The constant USER_NAME. + */ +//public static final String SERVICE_ADDRESS = "http://10.88.77.15/UMC/service/AbnormalFlowCleaningService?wsdl"; + public static final String USER_NAME = "admin"; + /** + * The constant PASSWORD. + */ + public static final String PASSWORD = "UMCAdministrator"; + } + + /** + * The type Protocol. + */ + public static class Protocol { + /** + * The constant RESP_CMD_BASE. + */ + public static final int RESP_CMD_BASE = 10000; + /** + * The constant VERSION. + */ + public static final int VERSION = 2; + /** + * The constant CRYPTO_NONE. + */ + public static final int CRYPTO_NONE = 0; + /** + * The constant CRYPTO_BASE64. + */ + public static final int CRYPTO_BASE64 = 1; + /** + * The constant CRYPTO_AES256. + */ + public static final int CRYPTO_AES256 = 2; + } + + /** + * The type User account status. + */ + public static class UserAccountStatus { + /** + * The constant NORMAL. + */ + public static final int NORMAL = 0; + /** + * The constant LOCKED. + */ + public static final int LOCKED = 1; + } } diff --git a/src/main/java/com/dispose/common/PatternUtil.java b/src/main/java/com/dispose/common/PatternUtil.java index 632ea209..9bf1fa6c 100644 --- a/src/main/java/com/dispose/common/PatternUtil.java +++ b/src/main/java/com/dispose/common/PatternUtil.java @@ -64,11 +64,14 @@ public class PatternUtil { // ip ipPattern = compiler.compile( - "^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" - + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)$"); + "^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1," + + "2}|[1-9]{1,2}|[1-9][0-9]|0)" + + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)$"); // 内网IP internalIpPattern = compiler.compile( - "((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(172" + "\\.(1[6-9]|2[0-9]|3[0-1])\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(192" @@ -76,15 +79,19 @@ public class PatternUtil { + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)))"); // 端口 port 1024-65535 portPattern = compiler.compile( - "^(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"); + "^(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655" + + "[0-2][0-9]|6553[0-5])$"); // ip port ipPortPattern = compiler.compile( - "^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" - + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1," + + "2}|[1-9]{1,2}|[1-9][0-9]|0)" + + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + ":([0-9]{1,4}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"); // 内网 ip port internalIpPortPattern = compiler.compile( - "^((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "^((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(172" + "\\.(1[6-9]|2[0-9]|3[0-1])\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)" + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(192" diff --git a/src/main/java/com/dispose/controller/AuthController.java b/src/main/java/com/dispose/controller/AuthController.java index 7e69fcc4..646aabc8 100644 --- a/src/main/java/com/dispose/controller/AuthController.java +++ b/src/main/java/com/dispose/controller/AuthController.java @@ -62,7 +62,8 @@ public class AuthController { LoginReq reqInfo = mr.getRequestObject(LoginReq.class); - MReturnType ret = userAccountService.loginService(reqInfo.getUserName(), reqInfo.getPassword()); + MReturnType ret = userAccountService.loginService(reqInfo.getUserName(), + reqInfo.getPassword()); if (ret.getFirstParam() != ErrorCode.ERR_OK) { return ProtocolRespDTO.result(ret.getFirstParam()); diff --git a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java b/src/main/java/com/dispose/controller/DisposeNodeInfoController.java index 7b8ccea7..df6ae778 100644 --- a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java +++ b/src/main/java/com/dispose/controller/DisposeNodeInfoController.java @@ -303,7 +303,8 @@ public class DisposeNodeInfoController { } } - String rspMessage = new ObjectMapper().writerWithView(DisposeCapacity.CapacityView.class).writeValueAsString(rspInfo); + String rspMessage = + new ObjectMapper().writerWithView(DisposeCapacity.CapacityView.class).writeValueAsString(rspInfo); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE); } @@ -365,7 +366,8 @@ public class DisposeNodeInfoController { } } - String rspMessage = new ObjectMapper().writerWithView(DisposeCapacity.DependIpView.class).writeValueAsString(rspInfo); + String rspMessage = + new ObjectMapper().writerWithView(DisposeCapacity.DependIpView.class).writeValueAsString(rspInfo); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE); } diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index e5affc44..e2311c0d 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -7,8 +7,8 @@ import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.task.StartTaskReq; import com.dispose.pojo.vo.task.StartTaskRsp; import com.dispose.pojo.vo.task.StopTaskReq; -import com.dispose.pojo.vo.task.TaskInfoRsp; import com.dispose.pojo.vo.task.TaskInfoData; +import com.dispose.pojo.vo.task.TaskInfoRsp; import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -43,7 +43,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO taskStart(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { ErrorCode err = mr.verifyRequest(headers); @@ -73,7 +73,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { ErrorCode err = mr.verifyRequest(headers); @@ -84,12 +84,12 @@ public class DisposeTaskController { IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); TaskInfoRsp rspInfo = new TaskInfoRsp(); - if(reqInfo.getTaskId() == null + if (reqInfo.getTaskId() == null || reqInfo.getTaskId().length == 0) { return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS); } - for(String v : reqInfo.getTaskId()) { + for (String v : reqInfo.getTaskId()) { TaskInfoData taskData = TaskInfoData.builder() .taskId(v) .build(); @@ -115,7 +115,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { ErrorCode err = mr.verifyRequest(headers); @@ -153,7 +153,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { return taskStopByIp(mr, headers); } @@ -170,7 +170,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { return taskStopByIp(mr, headers); } @@ -202,7 +202,7 @@ public class DisposeTaskController { @ResponseBody @ApiOperation("启动处置任务") public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) + @RequestHeader HttpHeaders headers) throws JsonProcessingException { ErrorCode err = mr.verifyRequest(headers); @@ -213,12 +213,12 @@ public class DisposeTaskController { IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); TaskInfoRsp rspInfo = new TaskInfoRsp(); - if(reqInfo.getTaskId() == null + if (reqInfo.getTaskId() == null || reqInfo.getTaskId().length == 0) { return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS); } - for(String v : reqInfo.getTaskId()) { + for (String v : reqInfo.getTaskId()) { TaskInfoData taskData = TaskInfoData.builder() .taskId(v) .build(); diff --git a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java index 267b5d54..27d498d1 100644 --- a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java +++ b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java @@ -26,6 +26,58 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants; */ @Slf4j public class DPTechImpl implements DisposeEntryManager { + /** + * The Clean type port. + */ + AbnormalFlowCleaningServicePortType cleanTypePort; + + /** + * Instantiates a new Dp tech. + * + * @param ipAddr the ip addr + */ + public DPTechImpl(String ipAddr) { + JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); + jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); + jaxWsProxyFactoryBean.setAddress(String.format(ConstValue.SOAPWrapperConst.NAMESPACE_URI, ipAddr)); + + //WS-Security Head + Map outProps = new HashMap<>(); + outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); + + outProps.put(WSHandlerConstants.USER, "admin"); + outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); + outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, SoapPasswordCallbackHandler.class.getName()); + + jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); + + this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); + } + + /** + * Instantiates a new Dp tech. + * + * @param ipAddr the ip addr + * @param type the type + */ + public DPTechImpl(String ipAddr, ConstValue.IPAddrType type) { + JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); + jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); + jaxWsProxyFactoryBean.setAddress(String.format(ConstValue.SOAPWrapperConst.NAMESPACE_URI, ipAddr)); + + //WS-Security Head + Map outProps = new HashMap<>(); + outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); + + outProps.put(WSHandlerConstants.USER, "admin"); + outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); + outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, SoapPasswordCallbackHandler.class.getName()); + + jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); + + this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); + } + /** * Gets version. * @@ -179,7 +231,7 @@ public class DPTechImpl implements DisposeEntryManager { * @return the detection object device json * @throws JsonProcessingException the json processing exception */ - public String getDetectionObjectDeviceJson(){ + public String getDetectionObjectDeviceJson() { try { ArrayOfDetectionObjectDataForService typePort = cleanTypePort.getAllDetectionObjectFromUMC(); ObjectMapper mapper = new ObjectMapper(); @@ -222,57 +274,5 @@ public class DPTechImpl implements DisposeEntryManager { return ""; } } - - /** - * The Clean type port. - */ - AbnormalFlowCleaningServicePortType cleanTypePort; - - /** - * Instantiates a new Dp tech. - * - * @param ipAddr the ip addr - */ - public DPTechImpl(String ipAddr) { - JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); - jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); - jaxWsProxyFactoryBean.setAddress(String.format(ConstValue.SOAPWrapperConst.NAMESPACE_URI, ipAddr)); - - //WS-Security Head - Map outProps = new HashMap<>(); - outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); - - outProps.put(WSHandlerConstants.USER, "admin"); - outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); - outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, SoapPasswordCallbackHandler.class.getName()); - - jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); - - this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); - } - - /** - * Instantiates a new Dp tech. - * - * @param ipAddr the ip addr - * @param type the type - */ - public DPTechImpl(String ipAddr, ConstValue.IPAddrType type) { - JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); - jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); - jaxWsProxyFactoryBean.setAddress(String.format(ConstValue.SOAPWrapperConst.NAMESPACE_URI, ipAddr)); - - //WS-Security Head - Map outProps = new HashMap<>(); - outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); - - outProps.put(WSHandlerConstants.USER, "admin"); - outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); - outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, SoapPasswordCallbackHandler.class.getName()); - - jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); - - this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); - } } diff --git a/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java b/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java index bcc9f467..f1bf9646 100644 --- a/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java +++ b/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java @@ -11,6 +11,14 @@ import java.util.List; * The type Virtual device. */ public class VirtualDeviceImpl implements DisposeEntryManager { + public VirtualDeviceImpl(String ipAddr) { + + } + + public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) { + + } + /** * Run dispose int. * @@ -63,14 +71,14 @@ public class VirtualDeviceImpl implements DisposeEntryManager { capList.add(DisposeDeviceCapacity.builder() .capacity(ConstValue.DeviceCapacity.CLEANUP.getCode()) - .protectIpV4(new String[] {"192.168.1.1", "192.168.1.2"}) + .protectIpV4(new String[]{"192.168.1.1", "192.168.1.2"}) .protectIpV6(new String[]{}) .tolFlowCapacity(1024) .build()); capList.add(DisposeDeviceCapacity.builder() .capacity(ConstValue.DeviceCapacity.DETECIVE.getCode()) - .protectIpV4(new String[] {"192.168.2.1", "192.168.2.2"}) + .protectIpV4(new String[]{"192.168.2.1", "192.168.2.2"}) .protectIpV6(new String[]{}) .tolFlowCapacity(0) .build()); @@ -136,12 +144,4 @@ public class VirtualDeviceImpl implements DisposeEntryManager { public String getProtectDevices() { return "192.168.10.10"; } - - public VirtualDeviceImpl(String ipAddr) { - - } - - public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) { - - } } diff --git a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java index c2df07d2..29e892dd 100644 --- a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java @@ -24,16 +24,13 @@ import org.springframework.stereotype.Component; @Component @Slf4j public class UserAccountCacheManagerImpl implements UserAccountCacheManager { + private static final Random randomGen = new Random(System.currentTimeMillis()); + private final ConcurrentHashMap userAccountCache = new ConcurrentHashMap<>(); @Resource private DisposeConfigure disposeConfigure; - @Resource private ObjectMapper objectMapper; - private static final Random randomGen = new Random(System.currentTimeMillis()); - - private final ConcurrentHashMap userAccountCache = new ConcurrentHashMap<>(); - /** * Verify permission error code. * diff --git a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java b/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java index 910a88c2..e3abe062 100644 --- a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java +++ b/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java @@ -18,24 +18,6 @@ import lombok.Setter; @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) public class DisposeCapacity { - /** - * The interface Base view. - */ - public interface BaseView { - } - - /** - * The interface Capacity view. - */ - public interface CapacityView extends BaseView { - } - - /** - * The interface Depend ip view. - */ - public interface DependIpView extends BaseView { - } - @JsonView(BaseView.class) private int type; @JsonView(DependIpView.class) @@ -44,4 +26,19 @@ public class DisposeCapacity { private int tolCapacity; @JsonView(CapacityView.class) private int usedCapacity; + /** + * The interface Base view. + */ + public interface BaseView { + } + /** + * The interface Capacity view. + */ + public interface CapacityView extends BaseView { + } + /** + * The interface Depend ip view. + */ + public interface DependIpView extends BaseView { + } } diff --git a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java b/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java index 9792de00..ce0bcd4c 100644 --- a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java +++ b/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java @@ -40,9 +40,9 @@ public class DeviceCapacityData extends IDReturnStatus { cpList.forEach(v -> { String ipAddrs = String.join(",", - Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[] {})) + Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[]{})) + "," + String.join(",", - Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[] {}) + Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[]{}) ); if (ipAddrs.endsWith(",")) { diff --git a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java b/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java index 6fdafe33..aa448444 100644 --- a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java +++ b/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java @@ -19,7 +19,8 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status", "message"}) +@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status", + "message"}) public class DisposeNodeData extends DeviceCapacityData { private int type; private String name; diff --git a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java b/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java index 99db9637..4faac6bf 100644 --- a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java +++ b/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java @@ -1,16 +1,21 @@ package com.dispose.pojo.vo.task; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +/** + * The type Stop task data. + */ @Data @Builder @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"id", "type", "disposeIp"}) public class StopTaskData { private String id; private int type; diff --git a/src/main/java/com/dispose/redis/MyRedisConfiguration.java b/src/main/java/com/dispose/redis/MyRedisConfiguration.java index 88afb2a5..6365937c 100644 --- a/src/main/java/com/dispose/redis/MyRedisConfiguration.java +++ b/src/main/java/com/dispose/redis/MyRedisConfiguration.java @@ -59,7 +59,8 @@ public class MyRedisConfiguration { /** * @return * @Description: Redisson哨兵模式实例 具体API操作参照Redisson Github对照表 - * https://github.com/redisson/redisson/wiki/11.-Redis%E5%91%BD%E4%BB%A4%E5%92%8CRedisson%E5%AF%B9%E8%B1%A1%E5%8C%B9%E9%85%8D%E5%88%97%E8%A1%A8 + * https://github.com/redisson/redisson/wiki/11 + * .-Redis%E5%91%BD%E4%BB%A4%E5%92%8CRedisson%E5%AF%B9%E8%B1%A1%E5%8C%B9%E9%85%8D%E5%88%97%E8%A1%A8 * @blog https://blog.csdn.net/unclecoco/article/details/99412915 */ @ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "redisson-sentinel") diff --git a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java b/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java index 2cb6b817..0ab9b0fe 100644 --- a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java @@ -21,14 +21,12 @@ import org.springframework.stereotype.Service; */ @Service public class DisposeNodeManagerImpl implements DisposeNodeManager { + private final ConcurrentHashMap disposeDevMap = new ConcurrentHashMap<>(); @Resource private DisposeDeviceMapper disposeDeviceMapper; - @Resource private UserAccountService userAccountService; - private final ConcurrentHashMap disposeDevMap = new ConcurrentHashMap<>(); - /** * Load dispose node from db. */ diff --git a/src/test/java/com/dispose/Global/InitTestEnvironment.java b/src/test/java/com/dispose/Global/InitTestEnvironment.java index 95d3bc0c..b6757dc3 100644 --- a/src/test/java/com/dispose/Global/InitTestEnvironment.java +++ b/src/test/java/com/dispose/Global/InitTestEnvironment.java @@ -5,14 +5,20 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.junit.BeforeClass; +/** + * The type Init test environment. + */ @Slf4j @Getter public class InitTestEnvironment { private final String USER_NAME = "admin"; private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58"; + /** + * Init virtual device. + */ @BeforeClass - public static void initVirtualDevice(){ + public static void initVirtualDevice() { GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true; log.warn("Current Used Virtual Dispose Device"); } diff --git a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java index 91235711..aaad1f29 100644 --- a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java +++ b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java @@ -4,6 +4,7 @@ package com.dispose.TestSuit; import com.dispose.controller.AuthControllerTest; import com.dispose.controller.DeviceNodeInfoControllerTest; import com.dispose.controller.DeviceNodeManagerControllerTest; +import com.dispose.controller.TaskControllerTest; import com.dispose.dptech.DPTechInterfaceTestCase; import com.dispose.manager.UserAccountManagerTest; import com.dispose.mapper.DisposeDeviceMapperTest; @@ -24,7 +25,8 @@ import org.junit.runners.Suite; AuthControllerTest.class, DeviceNodeManagerControllerTest.class, DeviceNodeInfoControllerTest.class, - UserAccountServiceTest.class + UserAccountServiceTest.class, + TaskControllerTest.class }) public class AllDisposePlatformTest { } diff --git a/src/test/java/com/dispose/controller/AuthControllerTest.java b/src/test/java/com/dispose/controller/AuthControllerTest.java index 50e05123..ccdbdf03 100644 --- a/src/test/java/com/dispose/controller/AuthControllerTest.java +++ b/src/test/java/com/dispose/controller/AuthControllerTest.java @@ -9,8 +9,8 @@ import com.dispose.pojo.po.MReturnType; import com.dispose.pojo.vo.auth.LoginReq; import com.dispose.pojo.vo.auth.LoginRsp; import com.dispose.service.UserAccountService; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.Before; @@ -23,9 +23,6 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -import javax.annotation.Resource; - 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; @@ -39,17 +36,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @Slf4j public class AuthControllerTest extends InitTestEnvironment { + private static String logToken = ""; @Resource private MockMvc mockMvc; - @Resource private ObjectMapper objectMapper; - @Resource private UserAccountService userAccountService; - private static String logToken = ""; - @Before public void userLogin() throws Exception { MReturnType ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); diff --git a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java index d28adba6..cad96653 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java @@ -9,7 +9,6 @@ import com.dispose.pojo.vo.common.IDArrayReq; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import javax.annotation.Resource; -import lombok.extern.slf4j.Slf4j; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,7 +31,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@Slf4j @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Resource @@ -48,7 +46,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { private Long getExistsDeviceId() { List dp = disposeDeviceMapper.selectAll(); - if(dp != null && dp.size() > 0) { + if (dp != null && dp.size() > 0) { return dp.get(0).getId(); } @@ -63,7 +61,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t1_getVersion() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -72,7 +70,51 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/version") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + + reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/information/version") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 1 get version all. + * + * @throws Exception the exception + */ + @Test + public void t1_getVersionAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/version") @@ -94,7 +136,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t2_getDeviceInfo() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -103,7 +145,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/deviceinfo") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 2 get device info all. + * + * @throws Exception the exception + */ + @Test + public void t2_getDeviceInfoAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/deviceinfo") @@ -125,7 +194,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t3_getDeviceCapacity() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -134,7 +203,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/capacity") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 3 get device capacity all. + * + * @throws Exception the exception + */ + @Test + public void t3_getDeviceCapacityAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/capacity") @@ -156,7 +252,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t3_getDeviceProtectedIp() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -165,7 +261,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/protected_ip") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 3 get device protected ip all. + * + * @throws Exception the exception + */ + @Test + public void t3_getDeviceProtectedIpAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/protected_ip") @@ -187,7 +310,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t3_getDisposeNodeList() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -196,7 +319,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/node_list") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 3 get dispose node list all. + * + * @throws Exception the exception + */ + @Test + public void t3_getDisposeNodeListAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/node_list") @@ -218,7 +368,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { @Test public void t3_getDisposeNodeDetails() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) + .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); @@ -227,7 +377,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); + mockMvc.perform(MockMvcRequestBuilders + .post("/information/node_details") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 3 get dispose node details all. + * + * @throws Exception the exception + */ + @Test + public void t3_getDisposeNodeDetailsAll() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .id(new String[]{}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); mockMvc.perform(MockMvcRequestBuilders .post("/information/node_details") diff --git a/src/test/java/com/dispose/controller/DeviceNodeManagerControllerTest.java b/src/test/java/com/dispose/controller/DeviceNodeManagerControllerTest.java index 99c19e39..c21474d1 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeManagerControllerTest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeManagerControllerTest.java @@ -7,6 +7,8 @@ import com.dispose.pojo.po.NewNodeInfo; import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.device.AddNodeReq; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,11 +19,6 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -import javax.annotation.Resource; - -import java.util.ArrayList; - 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; @@ -102,7 +99,7 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment { @Test public void t2_delDevice() throws Exception { IDArrayReq reqData = IDArrayReq.builder() - .id(new String[] {"0"}) + .id(new String[]{"0"}) .build(); ProtocolReqDTO reqInfo = new ProtocolReqDTO(); diff --git a/src/test/java/com/dispose/controller/TaskControllerTest.java b/src/test/java/com/dispose/controller/TaskControllerTest.java index 90167193..b1f34163 100644 --- a/src/test/java/com/dispose/controller/TaskControllerTest.java +++ b/src/test/java/com/dispose/controller/TaskControllerTest.java @@ -5,9 +5,11 @@ import com.dispose.common.ConstValue; import com.dispose.pojo.dto.ProtocolReqDTO; import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.task.StartTaskReq; +import com.dispose.pojo.vo.task.StopTaskData; +import com.dispose.pojo.vo.task.StopTaskReq; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; import javax.annotation.Resource; -import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -28,7 +30,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@Slf4j public class TaskControllerTest extends InitTestEnvironment { @Resource private MockMvc mockMvc; @@ -55,8 +56,6 @@ public class TaskControllerTest extends InitTestEnvironment { reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); - mockMvc.perform(MockMvcRequestBuilders .post("/task/start") .contentType(MediaType.APPLICATION_JSON) @@ -68,4 +67,196 @@ public class TaskControllerTest extends InitTestEnvironment { .getResponse() .getContentAsString(); } + + /** + * T 2 stop task. + * + * @throws Exception the exception + */ + @Test + public void t2_stopTask() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .taskId(new String[]{"1", "2"}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 3 stop node ip task. + * + * @throws Exception the exception + */ + @Test + public void t3_stopNodeIpTask() throws Exception { + StopTaskData itemData = StopTaskData.builder() + .disposeIp("192.168.1.1") + .type(ConstValue.DeviceCapacity.CLEANUP.getCode()) + .id("210") + .build(); + + StopTaskReq reqData = new StopTaskReq(); + + reqData.setItems(new ArrayList<>()); + reqData.getItems().add(itemData); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 4 stop node task. + * + * @throws Exception the exception + */ + @Test + public void t4_stopNodeTask() throws Exception { + StopTaskData itemData = StopTaskData.builder() + .type(ConstValue.DeviceCapacity.CLEANUP.getCode()) + .id("210") + .build(); + + StopTaskReq reqData = new StopTaskReq(); + + reqData.setItems(new ArrayList<>()); + reqData.getItems().add(itemData); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_node") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 5 stop all task. + * + * @throws Exception the exception + */ + @Test + public void t5_stopAllTask() throws Exception { + StopTaskData itemData = StopTaskData.builder() + .type(ConstValue.DeviceCapacity.CLEANUP.getCode()) + .build(); + + StopTaskReq reqData = new StopTaskReq(); + + reqData.setItems(new ArrayList<>()); + reqData.getItems().add(itemData); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_all") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 6 get node task. + * + * @throws Exception the exception + */ + @Test + public void t6_getNodeTask() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .taskId(new String[]{"1", "2"}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/get_node") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + + /** + * T 6 get all task. + * + * @throws Exception the exception + */ + @Test + public void t6_getAllTask() throws Exception { + IDArrayReq reqData = IDArrayReq.builder() + .taskId(new String[]{"1", "2"}) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/get") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122") + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } } diff --git a/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java index 65c2bc7f..33dada66 100644 --- a/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java +++ b/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java @@ -4,126 +4,91 @@ import com.dispose.Global.InitTestEnvironment; import com.dispose.common.ConstValue; import com.dispose.dispose.DeviceRouter; import com.dispose.dispose.DisposeEntryManager; -import com.dispose.dispose.po.DeviceInfo; import com.dispose.pojo.po.DisposeDeviceCapacity; import com.dptech.dispose.DetectionObjectDataForService; import com.dptech.dispose.ProtectionObjectDataForService; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.ArrayList; +import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.apache.cxf.databinding.AbstractDataBinding; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import org.mockito.BDDMockito; -import org.mockito.MockitoAnnotations; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.util.List; - +/** + * The type Dp tech interface test case. + */ @RunWith(SpringRunner.class) @Slf4j @SpringBootTest @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DPTechInterfaceTestCase extends InitTestEnvironment { -// @Before -// public void initVirtualDevice() { -// List protectList = new ArrayList<>(); -// List detectionList = new ArrayList<>(); -// detectionList.add(new DetectionObjectDataForService()); -// detectionList.add(new DetectionObjectDataForService()); -// detectionList.add(new DetectionObjectDataForService()); -// -// protectList.add(new ProtectionObjectDataForService()); -// protectList.add(new ProtectionObjectDataForService()); -// protectList.add(new ProtectionObjectDataForService()); -// -// List capList = new ArrayList<>(); -// capList.add(DisposeDeviceCapacity.builder() -// .capacity(0) -// .tolFlowCapacity(1024) -// .build()); -// capList.add(DisposeDeviceCapacity.builder() -// .capacity(1) -// .build()); -// -// DisposeEntryManager disposeEntryManager = PowerMockito.mock(DisposeEntryManager.class); -// -// PowerMockito.when(disposeEntryManager.getAllDetectionObject()).thenReturn(detectionList); -// PowerMockito.when(disposeEntryManager.getAllProtectionObject()).thenReturn(protectList); -// PowerMockito.when(disposeEntryManager.getProtectDevices()).thenReturn("10.88.76.41"); -// PowerMockito.when(disposeEntryManager.getDeviceLinkStatus()).thenReturn(true); -// PowerMockito.when(disposeEntryManager.getDeviceCapacity()).thenReturn(capList); -// PowerMockito.when(disposeEntryManager.getVersion()).thenReturn("1.0.0"); -// PowerMockito.when(disposeEntryManager.getDeviceInfo()).thenReturn(new DeviceInfo()); -// -// PowerMockito.mockStatic(DeviceRouter.class); -// PowerMockito.when(DeviceRouter.deviceRouterFactory(BDDMockito.anyInt(), BDDMockito.anyString())).thenReturn(disposeEntryManager); -// } - + /** + * T 1 get all detection object from umc. + */ @Test - public void t1_getAllDetectionObjectFromUMC(){ + public void t1_getAllDetectionObjectFromUMC() { try { - DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); + DisposeEntryManager dp = + DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); List detDevs = dp.getAllDetectionObject(); Assert.assertNotEquals(detDevs.size(), 0); - } catch (Exception ex){ + } catch (Exception ex) { Assert.fail(); } } + /** + * T 2 get all protect devices. + */ @Test - public void t2_getAllProtectDevices(){ + public void t2_getAllProtectDevices() { try { - DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); + DisposeEntryManager dp = + DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); String proDevs = dp.getProtectDevices(); Assert.assertNotEquals(proDevs.length(), 0); - } catch (Exception ex){ + } catch (Exception ex) { Assert.fail(); } } + /** + * T 3 get all protect objects. + */ @Test - public void t3_getAllProtectObjects(){ + public void t3_getAllProtectObjects() { try { - DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); + DisposeEntryManager dp = + DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); List proObjs = dp.getAllProtectionObject(); Assert.assertNotEquals(proObjs.size(), 0); - } catch (Exception ex){ + } catch (Exception ex) { Assert.fail(); } } + /** + * T 4 get link status. + */ @Test - public void t4_getLinkStatus(){ + public void t4_getLinkStatus() { DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); @@ -131,6 +96,11 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment { Assert.assertTrue(dp.getDeviceLinkStatus()); } + /** + * T 5 get device capacity. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void t5_getDeviceCapacity() throws JsonProcessingException { diff --git a/src/test/java/com/dispose/exception/ExceptionTest.java b/src/test/java/com/dispose/exception/ExceptionTest.java index 335ff3cd..d077673a 100644 --- a/src/test/java/com/dispose/exception/ExceptionTest.java +++ b/src/test/java/com/dispose/exception/ExceptionTest.java @@ -1,22 +1,15 @@ package com.dispose.exception; -import com.dispose.Global.InitTestEnvironment; import com.dispose.common.ConstValue; -import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.dto.ProtocolRespDTO; import com.dispose.pojo.vo.auth.LoginReq; -import com.dispose.pojo.vo.auth.LoginRsp; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; @@ -28,21 +21,30 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +/** + * The type Exception test. + */ @AutoConfigureMockMvc @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @Slf4j -public class ExceptionTest{ +public class ExceptionTest { + /** + * The Expected ex. + */ + @Rule + public ExpectedException expectedEx = ExpectedException.none(); @Resource private MockMvc mockMvc; - @Resource private ObjectMapper objectMapper; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - + /** + * T 1 input exception. + * + * @throws Exception the exception + */ @Test(expected = Throwable.class) public void t1_inputException() throws Exception { expectedEx.expect(Throwable.class); @@ -67,6 +69,11 @@ public class ExceptionTest{ .getContentAsString(); } + /** + * T 2 global exception. + * + * @throws Exception the exception + */ @Test(expected = Exception.class) public void t2_globalException() throws Exception { expectedEx.expect(Exception.class); diff --git a/src/test/java/com/dispose/manager/UserAccountManagerTest.java b/src/test/java/com/dispose/manager/UserAccountManagerTest.java index c7028cb0..96e2901c 100644 --- a/src/test/java/com/dispose/manager/UserAccountManagerTest.java +++ b/src/test/java/com/dispose/manager/UserAccountManagerTest.java @@ -17,19 +17,25 @@ import org.junit.runners.MethodSorters; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +/** + * The type User account manager test. + */ @RunWith(SpringRunner.class) @Slf4j @SpringBootTest @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class UserAccountManagerTest extends InitTestEnvironment { + private static String userToken; @Resource private UserAccountCacheManager userAccountCacheManager; - @Resource private UserAccountService userAccountService; - private static String userToken; - + /** + * User login. + * + * @throws NoSuchAlgorithmException the no such algorithm exception + */ @Before public void userLogin() throws NoSuchAlgorithmException { MReturnType ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); @@ -41,27 +47,44 @@ public class UserAccountManagerTest extends InitTestEnvironment { Assert.assertNotEquals(userToken.length(), 0); } + /** + * T 1 permission test. + */ @Test public void t1_permissionTest() { Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken), ErrorCode.ERR_OK); } + /** + * T 2 get username by token test. + */ @Test public void t2_getUsernameByTokenTest() { Assert.assertEquals(userAccountCacheManager.getUsernameByToken(userToken), getUSER_NAME()); } + /** + * T 3 verify token test. + */ @Test public void t3_verifyTokenTest() { Assert.assertEquals(userAccountCacheManager.verifyToken(userToken), ErrorCode.ERR_OK); Assert.assertEquals(userAccountCacheManager.verifyToken(userToken + "123"), ErrorCode.ERR_LOGOUT); } + /** + * T 4 verify user login test. + */ @Test public void t4_verifyUserLoginTest() { Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken), ErrorCode.ERR_OK); } + /** + * T 5 get cache user. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void t5_getCacheUser() throws JsonProcessingException { String userInfo = userAccountCacheManager.getCacheUser(); @@ -70,14 +93,20 @@ public class UserAccountManagerTest extends InitTestEnvironment { Assert.assertNotEquals(userInfo.length(), 0); } + /** + * T 6 get usr pwd err times test. + */ @Test public void t6_getUsrPwdErrTimesTest() { Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), 0); } + /** + * T 6 set usr pwd err times test. + */ @Test public void t6_setUsrPwdErrTimesTest() { - for(int i = 0; i < 6; i++) { + for (int i = 0; i < 6; i++) { userAccountCacheManager.setUserPwdErrTimes(getUSER_NAME(), i); Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), i); } @@ -86,11 +115,19 @@ public class UserAccountManagerTest extends InitTestEnvironment { Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), 0); } + /** + * T 7 get user token test. + * + * @throws NoSuchAlgorithmException the no such algorithm exception + */ @Test public void t7_getUserTokenTest() throws NoSuchAlgorithmException { Assert.assertEquals(userAccountCacheManager.getUserToken(getUSER_NAME()), userToken); } + /** + * T 99 clean user token test. + */ @Test public void t99_cleanUserTokenTest() { userAccountCacheManager.cleanUserToken(getUSER_NAME()); diff --git a/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java index 2b32b78a..457c964d 100644 --- a/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java +++ b/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java @@ -7,6 +7,9 @@ import com.dispose.pojo.po.DisposeDeviceCapacity; import com.dispose.service.DisposeNodeManager; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.FixMethodOrder; @@ -16,10 +19,6 @@ import org.junit.runners.MethodSorters; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - /** * The type Dispose device mapper test. */ @@ -78,7 +77,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List dp = disposeDeviceMapper.selectAll(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - dp.forEach(v->{ + dp.forEach(v -> { Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0); }); } @@ -93,7 +92,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List dp = disposeDeviceMapper.selectAll(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - dp.forEach(v->{ + dp.forEach(v -> { Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0); }); } @@ -108,7 +107,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List dp = disposeDeviceMapper.selectAll(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - dp.forEach(v->{ + dp.forEach(v -> { DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(v.getIpAddr()); Assert.assertNotNull(dp); Assert.assertEquals(dev.getIpAddr(), v.getIpAddr()); @@ -125,7 +124,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List dp = disposeDeviceMapper.selectAll(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - dp.forEach(v->{ + dp.forEach(v -> { DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); Assert.assertNotNull(dp); Assert.assertEquals(dev.getId(), v.getId()); @@ -144,8 +143,8 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List dp = disposeDeviceMapper.selectAll(); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - dp.forEach(v->{ - if(v.getIpAddr().equals(ipAddr)) { + dp.forEach(v -> { + if (v.getIpAddr().equals(ipAddr)) { Assert.fail(); } }); diff --git a/src/test/java/com/dispose/mapper/UserAccountMapperTest.java b/src/test/java/com/dispose/mapper/UserAccountMapperTest.java index fa54d944..00df7aa4 100644 --- a/src/test/java/com/dispose/mapper/UserAccountMapperTest.java +++ b/src/test/java/com/dispose/mapper/UserAccountMapperTest.java @@ -5,6 +5,7 @@ import com.dispose.common.ConstValue; import com.dispose.pojo.entity.UserAccount; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.FixMethodOrder; @@ -15,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; - /** * The type User account mapper test. */ diff --git a/src/test/java/com/dispose/service/UserAccountServiceTest.java b/src/test/java/com/dispose/service/UserAccountServiceTest.java index c270ea7e..ea106408 100644 --- a/src/test/java/com/dispose/service/UserAccountServiceTest.java +++ b/src/test/java/com/dispose/service/UserAccountServiceTest.java @@ -21,17 +21,16 @@ import org.springframework.test.context.junit4.SpringRunner; @Slf4j @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class UserAccountServiceTest extends InitTestEnvironment { + private static String token = ""; @Resource private UserAccountService userAccountService; - private static String token = ""; - @Before public void userLogin() throws NoSuchAlgorithmException { MReturnType ret = userAccountService.loginService("admin", "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58"); - if(ret.getFirstParam() == ErrorCode.ERR_OK) { + if (ret.getFirstParam() == ErrorCode.ERR_OK) { UserAccountServiceTest.token = ret.getSecondParam(); } }