REM:
1. 增加任务管理单元测试
2. 重新格式化代码
This commit is contained in:
huangxin 2020-04-22 17:14:41 +08:00
parent df193ea774
commit 31c5d0507b
29 changed files with 721 additions and 334 deletions

View File

@ -30,7 +30,8 @@ public class PhoenixBootApplication {
SpringApplication.run(PhoenixBootApplication.class, args); SpringApplication.run(PhoenixBootApplication.class, args);
log.info("\n----------------------------------------------------------\n\t" log.info("\n----------------------------------------------------------\n\t"
+ "Phoenix Application is running! Access URLs:\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"
+ "----------------------------------------------------------"); + "----------------------------------------------------------");
} }

View File

@ -12,6 +12,8 @@ import javax.validation.ConstraintValidatorContext;
*/ */
public class UserIdValidator implements ConstraintValidator<UserId, Long> { public class UserIdValidator implements ConstraintValidator<UserId, Long> {
private final Set<Long> idSet = Sets.newHashSet(1L, 2L);
/** /**
* 快速失败模式下这里无法注入依赖 参数校验的数据源相关校验放到controller里 方法抽象到下层service中 * 快速失败模式下这里无法注入依赖 参数校验的数据源相关校验放到controller里 方法抽象到下层service中
*/ */
@ -24,8 +26,6 @@ public class UserIdValidator implements ConstraintValidator<UserId, Long> {
return existsById(aLong); return existsById(aLong);
} }
private final Set<Long> idSet = Sets.newHashSet(1L, 2L);
private boolean existsById(long aId) { private boolean existsById(long aId) {
return idSet.contains(aId); return idSet.contains(aId);
} }

View File

@ -43,10 +43,9 @@ public class MyCacheInterceptor {
* 系统统一缓存key前缀 * 系统统一缓存key前缀
*/ */
public static final String CACHE_PREFIX = "PHOENIX_IC" + SPILIT; public static final String CACHE_PREFIX = "PHOENIX_IC" + SPILIT;
private static final ExpressionParser parser = new SpelExpressionParser();
// SpelExpressionParser spelExpressionParser = new SpelExpressionParser(); // SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
public static final String CACHE_NULL = "NULL"; public static final String CACHE_NULL = "NULL";
private static final ExpressionParser parser = new SpelExpressionParser();
@Resource @Resource
private RedisClient redisClient; private RedisClient redisClient;

View File

@ -4,77 +4,6 @@ package com.dispose.common;
* The type Const value. * The type Const value.
*/ */
public class ConstValue { 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. * 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. * 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;
}
} }

View File

@ -64,11 +64,14 @@ public class PatternUtil {
// ip // ip
ipPattern = compiler.compile( 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," +
+ "\\.(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)$"); "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 // 内网IP
internalIpPattern = compiler.compile( 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" + "\\.(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)" + "\\.(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" + "\\.(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)))"); + "\\.(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 // 端口 port 1024-65535
portPattern = compiler.compile( 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 // ip port
ipPortPattern = compiler.compile( 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," +
+ "\\.(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)" "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])$"); + ":([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 // 内网 ip port
internalIpPortPattern = compiler.compile( 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" + "\\.(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)" + "\\.(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" + "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(192"

View File

@ -62,7 +62,8 @@ public class AuthController {
LoginReq reqInfo = mr.getRequestObject(LoginReq.class); LoginReq reqInfo = mr.getRequestObject(LoginReq.class);
MReturnType<ErrorCode, String> ret = userAccountService.loginService(reqInfo.getUserName(), reqInfo.getPassword()); MReturnType<ErrorCode, String> ret = userAccountService.loginService(reqInfo.getUserName(),
reqInfo.getPassword());
if (ret.getFirstParam() != ErrorCode.ERR_OK) { if (ret.getFirstParam() != ErrorCode.ERR_OK) {
return ProtocolRespDTO.result(ret.getFirstParam()); return ProtocolRespDTO.result(ret.getFirstParam());

View File

@ -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); 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); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE);
} }

View File

@ -7,8 +7,8 @@ import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.task.StartTaskReq; import com.dispose.pojo.vo.task.StartTaskReq;
import com.dispose.pojo.vo.task.StartTaskRsp; import com.dispose.pojo.vo.task.StartTaskRsp;
import com.dispose.pojo.vo.task.StopTaskReq; 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.TaskInfoData;
import com.dispose.pojo.vo.task.TaskInfoRsp;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -84,12 +84,12 @@ public class DisposeTaskController {
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
TaskInfoRsp rspInfo = new TaskInfoRsp(); TaskInfoRsp rspInfo = new TaskInfoRsp();
if(reqInfo.getTaskId() == null if (reqInfo.getTaskId() == null
|| reqInfo.getTaskId().length == 0) { || reqInfo.getTaskId().length == 0) {
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS); return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
} }
for(String v : reqInfo.getTaskId()) { for (String v : reqInfo.getTaskId()) {
TaskInfoData taskData = TaskInfoData.builder() TaskInfoData taskData = TaskInfoData.builder()
.taskId(v) .taskId(v)
.build(); .build();
@ -213,12 +213,12 @@ public class DisposeTaskController {
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
TaskInfoRsp rspInfo = new TaskInfoRsp(); TaskInfoRsp rspInfo = new TaskInfoRsp();
if(reqInfo.getTaskId() == null if (reqInfo.getTaskId() == null
|| reqInfo.getTaskId().length == 0) { || reqInfo.getTaskId().length == 0) {
return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS); return ProtocolRespDTO.result(ErrorCode.ERR_INPUTMISS);
} }
for(String v : reqInfo.getTaskId()) { for (String v : reqInfo.getTaskId()) {
TaskInfoData taskData = TaskInfoData.builder() TaskInfoData taskData = TaskInfoData.builder()
.taskId(v) .taskId(v)
.build(); .build();

View File

@ -26,6 +26,58 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants;
*/ */
@Slf4j @Slf4j
public class DPTechImpl implements DisposeEntryManager { 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<String, Object> 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<String, Object> 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. * Gets version.
* *
@ -179,7 +231,7 @@ public class DPTechImpl implements DisposeEntryManager {
* @return the detection object device json * @return the detection object device json
* @throws JsonProcessingException the json processing exception * @throws JsonProcessingException the json processing exception
*/ */
public String getDetectionObjectDeviceJson(){ public String getDetectionObjectDeviceJson() {
try { try {
ArrayOfDetectionObjectDataForService typePort = cleanTypePort.getAllDetectionObjectFromUMC(); ArrayOfDetectionObjectDataForService typePort = cleanTypePort.getAllDetectionObjectFromUMC();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -222,57 +274,5 @@ public class DPTechImpl implements DisposeEntryManager {
return ""; 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<String, Object> 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<String, Object> 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();
}
} }

View File

@ -11,6 +11,14 @@ import java.util.List;
* The type Virtual device. * The type Virtual device.
*/ */
public class VirtualDeviceImpl implements DisposeEntryManager { public class VirtualDeviceImpl implements DisposeEntryManager {
public VirtualDeviceImpl(String ipAddr) {
}
public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) {
}
/** /**
* Run dispose int. * Run dispose int.
* *
@ -63,14 +71,14 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
capList.add(DisposeDeviceCapacity.builder() capList.add(DisposeDeviceCapacity.builder()
.capacity(ConstValue.DeviceCapacity.CLEANUP.getCode()) .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[]{}) .protectIpV6(new String[]{})
.tolFlowCapacity(1024) .tolFlowCapacity(1024)
.build()); .build());
capList.add(DisposeDeviceCapacity.builder() capList.add(DisposeDeviceCapacity.builder()
.capacity(ConstValue.DeviceCapacity.DETECIVE.getCode()) .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[]{}) .protectIpV6(new String[]{})
.tolFlowCapacity(0) .tolFlowCapacity(0)
.build()); .build());
@ -136,12 +144,4 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
public String getProtectDevices() { public String getProtectDevices() {
return "192.168.10.10"; return "192.168.10.10";
} }
public VirtualDeviceImpl(String ipAddr) {
}
public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) {
}
} }

View File

@ -24,16 +24,13 @@ import org.springframework.stereotype.Component;
@Component @Component
@Slf4j @Slf4j
public class UserAccountCacheManagerImpl implements UserAccountCacheManager { public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
private static final Random randomGen = new Random(System.currentTimeMillis());
private final ConcurrentHashMap<String, UserAccountCache> userAccountCache = new ConcurrentHashMap<>();
@Resource @Resource
private DisposeConfigure disposeConfigure; private DisposeConfigure disposeConfigure;
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
private static final Random randomGen = new Random(System.currentTimeMillis());
private final ConcurrentHashMap<String, UserAccountCache> userAccountCache = new ConcurrentHashMap<>();
/** /**
* Verify permission error code. * Verify permission error code.
* *

View File

@ -18,24 +18,6 @@ import lombok.Setter;
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class DisposeCapacity { 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) @JsonView(BaseView.class)
private int type; private int type;
@JsonView(DependIpView.class) @JsonView(DependIpView.class)
@ -44,4 +26,19 @@ public class DisposeCapacity {
private int tolCapacity; private int tolCapacity;
@JsonView(CapacityView.class) @JsonView(CapacityView.class)
private int usedCapacity; 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 {
}
} }

View File

@ -40,9 +40,9 @@ public class DeviceCapacityData extends IDReturnStatus {
cpList.forEach(v -> { cpList.forEach(v -> {
String ipAddrs = String.join(",", String ipAddrs = String.join(",",
Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[] {})) Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[]{}))
+ "," + String.join(",", + "," + String.join(",",
Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[] {}) Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[]{})
); );
if (ipAddrs.endsWith(",")) { if (ipAddrs.endsWith(",")) {

View File

@ -19,7 +19,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) @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 { public class DisposeNodeData extends DeviceCapacityData {
private int type; private int type;
private String name; private String name;

View File

@ -1,16 +1,21 @@
package com.dispose.pojo.vo.task; package com.dispose.pojo.vo.task;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* The type Stop task data.
*/
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"id", "type", "disposeIp"})
public class StopTaskData { public class StopTaskData {
private String id; private String id;
private int type; private int type;

View File

@ -59,7 +59,8 @@ public class MyRedisConfiguration {
/** /**
* @return * @return
* @Description: Redisson哨兵模式实例 具体API操作参照Redisson Github对照表 * @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 * @blog https://blog.csdn.net/unclecoco/article/details/99412915
*/ */
@ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "redisson-sentinel") @ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "redisson-sentinel")

View File

@ -21,14 +21,12 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class DisposeNodeManagerImpl implements DisposeNodeManager { public class DisposeNodeManagerImpl implements DisposeNodeManager {
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
@Resource @Resource
private DisposeDeviceMapper disposeDeviceMapper; private DisposeDeviceMapper disposeDeviceMapper;
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
/** /**
* Load dispose node from db. * Load dispose node from db.
*/ */

View File

@ -5,14 +5,20 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/**
* The type Init test environment.
*/
@Slf4j @Slf4j
@Getter @Getter
public class InitTestEnvironment { public class InitTestEnvironment {
private final String USER_NAME = "admin"; private final String USER_NAME = "admin";
private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58"; private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58";
/**
* Init virtual device.
*/
@BeforeClass @BeforeClass
public static void initVirtualDevice(){ public static void initVirtualDevice() {
GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true; GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true;
log.warn("Current Used Virtual Dispose Device"); log.warn("Current Used Virtual Dispose Device");
} }

View File

@ -4,6 +4,7 @@ package com.dispose.TestSuit;
import com.dispose.controller.AuthControllerTest; import com.dispose.controller.AuthControllerTest;
import com.dispose.controller.DeviceNodeInfoControllerTest; import com.dispose.controller.DeviceNodeInfoControllerTest;
import com.dispose.controller.DeviceNodeManagerControllerTest; import com.dispose.controller.DeviceNodeManagerControllerTest;
import com.dispose.controller.TaskControllerTest;
import com.dispose.dptech.DPTechInterfaceTestCase; import com.dispose.dptech.DPTechInterfaceTestCase;
import com.dispose.manager.UserAccountManagerTest; import com.dispose.manager.UserAccountManagerTest;
import com.dispose.mapper.DisposeDeviceMapperTest; import com.dispose.mapper.DisposeDeviceMapperTest;
@ -24,7 +25,8 @@ import org.junit.runners.Suite;
AuthControllerTest.class, AuthControllerTest.class,
DeviceNodeManagerControllerTest.class, DeviceNodeManagerControllerTest.class,
DeviceNodeInfoControllerTest.class, DeviceNodeInfoControllerTest.class,
UserAccountServiceTest.class UserAccountServiceTest.class,
TaskControllerTest.class
}) })
public class AllDisposePlatformTest { public class AllDisposePlatformTest {
} }

View File

@ -9,8 +9,8 @@ import com.dispose.pojo.po.MReturnType;
import com.dispose.pojo.vo.auth.LoginReq; import com.dispose.pojo.vo.auth.LoginReq;
import com.dispose.pojo.vo.auth.LoginRsp; import com.dispose.pojo.vo.auth.LoginRsp;
import com.dispose.service.UserAccountService; import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -23,9 +23,6 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 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.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 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) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@Slf4j @Slf4j
public class AuthControllerTest extends InitTestEnvironment { public class AuthControllerTest extends InitTestEnvironment {
private static String logToken = "";
@Resource @Resource
private MockMvc mockMvc; private MockMvc mockMvc;
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
private static String logToken = "";
@Before @Before
public void userLogin() throws Exception { public void userLogin() throws Exception {
MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD());

View File

@ -9,7 +9,6 @@ import com.dispose.pojo.vo.common.IDArrayReq;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -32,7 +31,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DeviceNodeInfoControllerTest extends InitTestEnvironment { public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Resource @Resource
@ -48,7 +46,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
private Long getExistsDeviceId() { private Long getExistsDeviceId() {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
if(dp != null && dp.size() > 0) { if (dp != null && dp.size() > 0) {
return dp.get(0).getId(); return dp.get(0).getId();
} }
@ -63,7 +61,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t1_getVersion() throws Exception { public void t1_getVersion() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -72,7 +70,51 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/version") .post("/information/version")
@ -94,7 +136,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t2_getDeviceInfo() throws Exception { public void t2_getDeviceInfo() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -103,7 +145,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/deviceinfo") .post("/information/deviceinfo")
@ -125,7 +194,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t3_getDeviceCapacity() throws Exception { public void t3_getDeviceCapacity() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -134,7 +203,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/capacity") .post("/information/capacity")
@ -156,7 +252,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t3_getDeviceProtectedIp() throws Exception { public void t3_getDeviceProtectedIp() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -165,7 +261,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip") .post("/information/protected_ip")
@ -187,7 +310,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t3_getDisposeNodeList() throws Exception { public void t3_getDisposeNodeList() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -196,7 +319,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_list") .post("/information/node_list")
@ -218,7 +368,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
@Test @Test
public void t3_getDisposeNodeDetails() throws Exception { public void t3_getDisposeNodeDetails() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {String.valueOf(getExistsDeviceId()), "123"}) .id(new String[]{String.valueOf(getExistsDeviceId()), "123"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();
@ -227,7 +377,34 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); 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 mockMvc.perform(MockMvcRequestBuilders
.post("/information/node_details") .post("/information/node_details")

View File

@ -7,6 +7,8 @@ import com.dispose.pojo.po.NewNodeInfo;
import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.device.AddNodeReq; import com.dispose.pojo.vo.device.AddNodeReq;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 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.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -102,7 +99,7 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
@Test @Test
public void t2_delDevice() throws Exception { public void t2_delDevice() throws Exception {
IDArrayReq reqData = IDArrayReq.builder() IDArrayReq reqData = IDArrayReq.builder()
.id(new String[] {"0"}) .id(new String[]{"0"})
.build(); .build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO(); ProtocolReqDTO reqInfo = new ProtocolReqDTO();

View File

@ -5,9 +5,11 @@ import com.dispose.common.ConstValue;
import com.dispose.pojo.dto.ProtocolReqDTO; import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.vo.common.IDArrayReq; import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.task.StartTaskReq; 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 com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 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) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@Slf4j
public class TaskControllerTest extends InitTestEnvironment { public class TaskControllerTest extends InitTestEnvironment {
@Resource @Resource
private MockMvc mockMvc; private MockMvc mockMvc;
@ -55,8 +56,6 @@ public class TaskControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo));
mockMvc.perform(MockMvcRequestBuilders mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
@ -68,4 +67,196 @@ public class TaskControllerTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .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();
}
} }

View File

@ -4,126 +4,91 @@ import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.dispose.DeviceRouter; import com.dispose.dispose.DeviceRouter;
import com.dispose.dispose.DisposeEntryManager; import com.dispose.dispose.DisposeEntryManager;
import com.dispose.dispose.po.DeviceInfo;
import com.dispose.pojo.po.DisposeDeviceCapacity; import com.dispose.pojo.po.DisposeDeviceCapacity;
import com.dptech.dispose.DetectionObjectDataForService; import com.dptech.dispose.DetectionObjectDataForService;
import com.dptech.dispose.ProtectionObjectDataForService; import com.dptech.dispose.ProtectionObjectDataForService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.databinding.AbstractDataBinding;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; 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.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 org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; /**
import java.util.List; * The type Dp tech interface test case.
*/
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@Slf4j @Slf4j
@SpringBootTest @SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DPTechInterfaceTestCase extends InitTestEnvironment { public class DPTechInterfaceTestCase extends InitTestEnvironment {
// @Before /**
// public void initVirtualDevice() { * T 1 get all detection object from umc.
// List<ProtectionObjectDataForService> protectList = new ArrayList<>(); */
// List<DetectionObjectDataForService> 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<DisposeDeviceCapacity> 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);
// }
@Test @Test
public void t1_getAllDetectionObjectFromUMC(){ public void t1_getAllDetectionObjectFromUMC() {
try { 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<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject(); List<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject();
Assert.assertNotEquals(detDevs.size(), 0); Assert.assertNotEquals(detDevs.size(), 0);
} catch (Exception ex){ } catch (Exception ex) {
Assert.fail(); Assert.fail();
} }
} }
/**
* T 2 get all protect devices.
*/
@Test @Test
public void t2_getAllProtectDevices(){ public void t2_getAllProtectDevices() {
try { 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(); String proDevs = dp.getProtectDevices();
Assert.assertNotEquals(proDevs.length(), 0); Assert.assertNotEquals(proDevs.length(), 0);
} catch (Exception ex){ } catch (Exception ex) {
Assert.fail(); Assert.fail();
} }
} }
/**
* T 3 get all protect objects.
*/
@Test @Test
public void t3_getAllProtectObjects(){ public void t3_getAllProtectObjects() {
try { 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<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject(); List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
Assert.assertNotEquals(proObjs.size(), 0); Assert.assertNotEquals(proObjs.size(), 0);
} catch (Exception ex){ } catch (Exception ex) {
Assert.fail(); Assert.fail();
} }
} }
/**
* T 4 get link status.
*/
@Test @Test
public void t4_getLinkStatus(){ public void t4_getLinkStatus() {
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
"10.88.77.15"); "10.88.77.15");
@ -131,6 +96,11 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
Assert.assertTrue(dp.getDeviceLinkStatus()); Assert.assertTrue(dp.getDeviceLinkStatus());
} }
/**
* T 5 get device capacity.
*
* @throws JsonProcessingException the json processing exception
*/
@Test @Test
public void t5_getDeviceCapacity() throws JsonProcessingException { public void t5_getDeviceCapacity() throws JsonProcessingException {

View File

@ -1,22 +1,15 @@
package com.dispose.exception; package com.dispose.exception;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.dto.ProtocolReqDTO; 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.LoginReq;
import com.dispose.pojo.vo.auth.LoginRsp;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.FixMethodOrder;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.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.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* The type Exception test.
*/
@AutoConfigureMockMvc @AutoConfigureMockMvc
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@Slf4j @Slf4j
public class ExceptionTest{ public class ExceptionTest {
/**
* The Expected ex.
*/
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Resource @Resource
private MockMvc mockMvc; private MockMvc mockMvc;
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Rule /**
public ExpectedException expectedEx = ExpectedException.none(); * T 1 input exception.
*
* @throws Exception the exception
*/
@Test(expected = Throwable.class) @Test(expected = Throwable.class)
public void t1_inputException() throws Exception { public void t1_inputException() throws Exception {
expectedEx.expect(Throwable.class); expectedEx.expect(Throwable.class);
@ -67,6 +69,11 @@ public class ExceptionTest{
.getContentAsString(); .getContentAsString();
} }
/**
* T 2 global exception.
*
* @throws Exception the exception
*/
@Test(expected = Exception.class) @Test(expected = Exception.class)
public void t2_globalException() throws Exception { public void t2_globalException() throws Exception {
expectedEx.expect(Exception.class); expectedEx.expect(Exception.class);

View File

@ -17,19 +17,25 @@ import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
/**
* The type User account manager test.
*/
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@Slf4j @Slf4j
@SpringBootTest @SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserAccountManagerTest extends InitTestEnvironment { public class UserAccountManagerTest extends InitTestEnvironment {
private static String userToken;
@Resource @Resource
private UserAccountCacheManager userAccountCacheManager; private UserAccountCacheManager userAccountCacheManager;
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
private static String userToken; /**
* User login.
*
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
@Before @Before
public void userLogin() throws NoSuchAlgorithmException { public void userLogin() throws NoSuchAlgorithmException {
MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD());
@ -41,27 +47,44 @@ public class UserAccountManagerTest extends InitTestEnvironment {
Assert.assertNotEquals(userToken.length(), 0); Assert.assertNotEquals(userToken.length(), 0);
} }
/**
* T 1 permission test.
*/
@Test @Test
public void t1_permissionTest() { public void t1_permissionTest() {
Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken), ErrorCode.ERR_OK); Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken), ErrorCode.ERR_OK);
} }
/**
* T 2 get username by token test.
*/
@Test @Test
public void t2_getUsernameByTokenTest() { public void t2_getUsernameByTokenTest() {
Assert.assertEquals(userAccountCacheManager.getUsernameByToken(userToken), getUSER_NAME()); Assert.assertEquals(userAccountCacheManager.getUsernameByToken(userToken), getUSER_NAME());
} }
/**
* T 3 verify token test.
*/
@Test @Test
public void t3_verifyTokenTest() { public void t3_verifyTokenTest() {
Assert.assertEquals(userAccountCacheManager.verifyToken(userToken), ErrorCode.ERR_OK); Assert.assertEquals(userAccountCacheManager.verifyToken(userToken), ErrorCode.ERR_OK);
Assert.assertEquals(userAccountCacheManager.verifyToken(userToken + "123"), ErrorCode.ERR_LOGOUT); Assert.assertEquals(userAccountCacheManager.verifyToken(userToken + "123"), ErrorCode.ERR_LOGOUT);
} }
/**
* T 4 verify user login test.
*/
@Test @Test
public void t4_verifyUserLoginTest() { public void t4_verifyUserLoginTest() {
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken), ErrorCode.ERR_OK); Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken), ErrorCode.ERR_OK);
} }
/**
* T 5 get cache user.
*
* @throws JsonProcessingException the json processing exception
*/
@Test @Test
public void t5_getCacheUser() throws JsonProcessingException { public void t5_getCacheUser() throws JsonProcessingException {
String userInfo = userAccountCacheManager.getCacheUser(); String userInfo = userAccountCacheManager.getCacheUser();
@ -70,14 +93,20 @@ public class UserAccountManagerTest extends InitTestEnvironment {
Assert.assertNotEquals(userInfo.length(), 0); Assert.assertNotEquals(userInfo.length(), 0);
} }
/**
* T 6 get usr pwd err times test.
*/
@Test @Test
public void t6_getUsrPwdErrTimesTest() { public void t6_getUsrPwdErrTimesTest() {
Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), 0); Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), 0);
} }
/**
* T 6 set usr pwd err times test.
*/
@Test @Test
public void t6_setUsrPwdErrTimesTest() { public void t6_setUsrPwdErrTimesTest() {
for(int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
userAccountCacheManager.setUserPwdErrTimes(getUSER_NAME(), i); userAccountCacheManager.setUserPwdErrTimes(getUSER_NAME(), i);
Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(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); Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), 0);
} }
/**
* T 7 get user token test.
*
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
@Test @Test
public void t7_getUserTokenTest() throws NoSuchAlgorithmException { public void t7_getUserTokenTest() throws NoSuchAlgorithmException {
Assert.assertEquals(userAccountCacheManager.getUserToken(getUSER_NAME()), userToken); Assert.assertEquals(userAccountCacheManager.getUserToken(getUSER_NAME()), userToken);
} }
/**
* T 99 clean user token test.
*/
@Test @Test
public void t99_cleanUserTokenTest() { public void t99_cleanUserTokenTest() {
userAccountCacheManager.cleanUserToken(getUSER_NAME()); userAccountCacheManager.cleanUserToken(getUSER_NAME());

View File

@ -7,6 +7,9 @@ import com.dispose.pojo.po.DisposeDeviceCapacity;
import com.dispose.service.DisposeNodeManager; import com.dispose.service.DisposeNodeManager;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
@ -16,10 +19,6 @@ import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; 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. * The type Dispose device mapper test.
*/ */
@ -78,7 +77,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v->{ dp.forEach(v -> {
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0); Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0);
}); });
} }
@ -93,7 +92,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v->{ dp.forEach(v -> {
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0); Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0);
}); });
} }
@ -108,7 +107,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v->{ dp.forEach(v -> {
DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(v.getIpAddr()); DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(v.getIpAddr());
Assert.assertNotNull(dp); Assert.assertNotNull(dp);
Assert.assertEquals(dev.getIpAddr(), v.getIpAddr()); Assert.assertEquals(dev.getIpAddr(), v.getIpAddr());
@ -125,7 +124,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v->{ dp.forEach(v -> {
DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId());
Assert.assertNotNull(dp); Assert.assertNotNull(dp);
Assert.assertEquals(dev.getId(), v.getId()); Assert.assertEquals(dev.getId(), v.getId());
@ -144,8 +143,8 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll(); List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v->{ dp.forEach(v -> {
if(v.getIpAddr().equals(ipAddr)) { if (v.getIpAddr().equals(ipAddr)) {
Assert.fail(); Assert.fail();
} }
}); });

View File

@ -5,6 +5,7 @@ import com.dispose.common.ConstValue;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
@ -15,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/** /**
* The type User account mapper test. * The type User account mapper test.
*/ */

View File

@ -21,17 +21,16 @@ import org.springframework.test.context.junit4.SpringRunner;
@Slf4j @Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserAccountServiceTest extends InitTestEnvironment { public class UserAccountServiceTest extends InitTestEnvironment {
private static String token = "";
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
private static String token = "";
@Before @Before
public void userLogin() throws NoSuchAlgorithmException { public void userLogin() throws NoSuchAlgorithmException {
MReturnType<ErrorCode, String> ret = userAccountService.loginService("admin", MReturnType<ErrorCode, String> ret = userAccountService.loginService("admin",
"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58"); "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58");
if(ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
UserAccountServiceTest.token = ret.getSecondParam(); UserAccountServiceTest.token = ret.getSecondParam();
} }
} }