diff --git a/src/main/java/com/dispose/common/CleanTaskStatus.java b/src/main/java/com/dispose/common/CleanTaskStatus.java deleted file mode 100644 index d365454e..00000000 --- a/src/main/java/com/dispose/common/CleanTaskStatus.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.dispose.common; - -/** - * The enum Device capacity. - * - * @author - */ -public enum CleanTaskStatus { - /** - * task is cleaning. - */ - CLEANING(1, "清洗中"), - /** - * task is end of cleaning. - */ - ENDOFCLEANING(2, "清洗结束"), - /** - * task is not existed. - */ - NOTASK(3, "该清洗任务不存在"), - /** - * HaoHan device err. - */ - HAOHANERROR(4, "浩瀚设备返回错误"), - /** - * device not support get task status. - */ - DEVNOTSUPPORT(0, "设备不支持获取任务状态"); - - private final int code; - private final String readme; - - CleanTaskStatus(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/ConstValue.java b/src/main/java/com/dispose/common/ConstValue.java index 2d6543f4..43255d2d 100644 --- a/src/main/java/com/dispose/common/ConstValue.java +++ b/src/main/java/com/dispose/common/ConstValue.java @@ -70,9 +70,20 @@ public class ConstValue { * The constant NORMAL. */ public static final int NORMAL = 0; + /** * The constant LOCKED. */ public static final int LOCKED = 1; + + /** + * The constant DISABLED. + */ + public static final int DISABLED = 2; + + /** + * The constant DELETED. + */ + public static final int DELETED = 3; } } diff --git a/src/main/java/com/dispose/common/DeviceCapacity.java b/src/main/java/com/dispose/common/DeviceCapacity.java deleted file mode 100644 index 358791d4..00000000 --- a/src/main/java/com/dispose/common/DeviceCapacity.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.dispose.common; - -/** - * The enum Device capacity. - * - * @author - */ -public enum DeviceCapacity { - /** - * Cleanup device capacity. - */ - CLEANUP(0, "清洗能力"), - /** - * Hidepend device capacity. - */ - HIDEPEND(1, "高防能力"), - /** - * Blackhool device capacity. - */ - BLACKHOOL(2, "黑洞能力"), - /** - * Detecive device capacity. - */ - DETECIVE(3, "检测能力"), - - /** - * Allcapacity device capacity. - */ - ALLCAPACITY(-1, "所有能力"); - - private final int code; - private final String readme; - - DeviceCapacity(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/DisposeDeviceType.java b/src/main/java/com/dispose/common/DisposeDeviceType.java deleted file mode 100644 index bc3f990e..00000000 --- a/src/main/java/com/dispose/common/DisposeDeviceType.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dispose.common; - -/** - * The enum Dispose device type. - * - * @author - */ -public enum DisposeDeviceType { - /** - * Dptech umc dispose device type. - */ - DPTECH_UMC(0, "迪普UMC管理平台"), - /** - * Haohan platform dispose device type. - */ - HAOHAN_PLATFORM(1, "浩瀚处置设备"), - - /** - * Virtual dispose dispose device type. - */ - VIRTUAL_DISPOSE(999, "虚拟处置设备"); - - private final int code; - private final String readme; - - DisposeDeviceType(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/DisposeTaskStatus.java b/src/main/java/com/dispose/common/DisposeTaskStatus.java deleted file mode 100644 index 6e89da6f..00000000 --- a/src/main/java/com/dispose/common/DisposeTaskStatus.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.dispose.common; - -/** - * The enum Dispose task status. - * - * @author - */ -public enum DisposeTaskStatus { - /** - * Task new dispose task status. - */ - TASK_NEW(0, "新建"), - /** - * Task running dispose task status. - */ - TASK_RUNNING(1, "运行中"), - /** - * Task stop dispose task status. - */ - TASK_STOP(2, "停止"), - /** - * Task finish dispose task status. - */ - TASK_FINISH(3, "结束"), - /** - * Task delete dispose task status. - */ - TASK_DELETE(4, "删除"); - - private final int code; - private final String readme; - - DisposeTaskStatus(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/DpTechAttackType.java b/src/main/java/com/dispose/common/DpTechAttackType.java deleted file mode 100644 index 410f84f3..00000000 --- a/src/main/java/com/dispose/common/DpTechAttackType.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.dispose.common; - -/** - * The enum Dp tech attack type. - * - * @author - */ -public enum DpTechAttackType { - /** - * The Tcp syn flood. - */ - TCP_SYN_FLOOD(1, "TCP SYN Flood"), - /** - * The Udp flood. - */ - UDP_FLOOD(2, "UDP Flood"), - /** - * The Icmp flood. - */ - ICMP_FLOOD(3, "ICMP Flood"), - /** - * The Tcp syn ack flood. - */ - TCP_SYN_ACK_FLOOD(6, "TCP SYN-ACK Flood"), - /** - * The Tcp fin flood. - */ - TCP_FIN_FLOOD(7, "TCP FIN Flood"), - /** - * The Ip fragment flood. - */ - IP_FRAGMENT_FLOOD(8, "IP Fragment Flood"), - /** - * The Tcp ack flood. - */ - TCP_ACK_FLOOD(13, "TCP ACK Flood"), - /** - * The Cc flood. - */ - CC_FLOOD(15, "CC Flood"), - /** - * The Http flood. - */ - HTTP_FLOOD(14, "HTTP Flood"), - /** - * The Dns query flood. - */ - DNS_QUERY_FLOOD(16, "DNS Query Flood"), - /** - * The Dns reply flood. - */ - DNS_REPLY_FLOOD(33, "DNS Reply Flood"), - /** - * The Host total traffic. - */ - HOST_TOTAL_TRAFFIC(31, "Host Total Traffic"); - - private final int code; - private final String readme; - - DpTechAttackType(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/FlowDirection.java b/src/main/java/com/dispose/common/FlowDirection.java deleted file mode 100644 index c9ee70bd..00000000 --- a/src/main/java/com/dispose/common/FlowDirection.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.dispose.common; - -/** - * The enum Flow direction. - * - * @author - */ -public enum FlowDirection { - /** - * Direction input flow direction. - */ - DIRECTION_INPUT(0, "流入"), - /** - * Direction output flow direction. - */ - DIRECTION_OUTPUT(1, "流出"), - /** - * Direction twoway flow direction. - */ - DIRECTION_TWOWAY(2, "双向"); - - private final int code; - private final String readme; - - FlowDirection(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets code. - * - * @return the code - */ - public int getCode() { - return this.code; - } - - /** - * Gets readme. - * - * @return the readme - */ - public String getReadme() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/common/GlobalVar.java b/src/main/java/com/dispose/common/GlobalVar.java deleted file mode 100644 index 1cd9a9be..00000000 --- a/src/main/java/com/dispose/common/GlobalVar.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.dispose.common; - -/** - * The type Global var. - * - * @author - */ -public class GlobalVar { - - /** - * The constant SOAP_CONNECT_TIMEOUT. - */ - public static volatile int SOAP_CONNECT_TIMEOUT = 5000; - /** - * The constant SOAP_RECEIVE_TIMEOUT. - */ - public static volatile int SOAP_RECEIVE_TIMEOUT = 5000; - /** - * The constant MAX_THREAT_INFO_VERSION. - */ - public static volatile int MAX_THREAT_INFO_VERSION = -1; - /** - * The constant THREAT_INFO_TYPE. - */ - public static volatile String THREAT_INFO_TYPE = "1"; - /** - * The constant USED_VIRTUAL_DISPOSE_MODE. - */ - public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false; - - /** - * The constant IS_CHECK_REQUEST_TIMEOUT. - */ - public static volatile boolean IS_CHECK_REQUEST_TIMEOUT = false; - - /** - * The constant STRING_SPILT_CHAR. - */ - public static final String STRING_SPILT_CHAR = ","; - - /** - * The constant STRING_IPV4_FLAG. - */ - public static final String STRING_IPV4_FLAG = "."; - - /** - * The constant STRING_IPV6_FLAG. - */ - public static final String STRING_IPV6_FLAG = ":"; - - /** - * The constant STRING_HTTP_AUTH_HEAD. - */ - public static final String STRING_HTTP_AUTH_HEAD = "Bearer "; - - /** - * The constant TASK_ERROR_MAX_RETRY. - */ - public static final int TASK_ERROR_MAX_RETRY = 3; -} diff --git a/src/main/java/com/dispose/common/Helper.java b/src/main/java/com/dispose/common/Helper.java deleted file mode 100644 index a035382d..00000000 --- a/src/main/java/com/dispose/common/Helper.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.dispose.common; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; - -/** - * The type Helper. - * - * @author - */ -public class Helper { - /** - * Attack array to string string. - * - * @param attack the attack - * @return the string - */ - public static String attackArrayToString(Integer[] attack) { - if (attack == null || attack.length == 0) { - return "0"; - } - - StringBuilder strAttack = new StringBuilder(); - - for (int v : attack) { - strAttack.append(v); - strAttack.append(","); - } - - String ret = strAttack.toString(); - - if (ret.endsWith(GlobalVar.STRING_SPILT_CHAR)) { - ret = ret.substring(0, ret.length() - 1); - } - - return ret; - } - - /** - * Attack string to array integer [ ]. - * - * @param str the str - * @return the integer [ ] - */ - public static Integer[] attackStringToArray(String str) { - if (str == null || str.length() == 0) { - return new Integer[]{0}; - } - - String[] spilt = str.split(GlobalVar.STRING_SPILT_CHAR); - List intArray = new ArrayList<>(); - - for (String s : spilt) { - intArray.add(Integer.parseInt(s)); - } - - return intArray.toArray(new Integer[0]); - } - - /** - * Gets timestamp second. - * - * @param dateTime the date time - * @return the timestamp second - */ - public static int getTimestampSecond(String dateTime) { - return (int)(Timestamp.valueOf(dateTime).toInstant().toEpochMilli() / 1000); - } - - /** - * Gets timestamp diff. - * - * @param begin the begin - * @param end the end - * @return the timestamp diff - */ - public static int getTimestampDiff(String begin, String end) { - int starTime = getTimestampSecond(begin); - int endTm = getTimestampSecond(end); - - return endTm - starTime; - } - - /** - * Gets timestamp diff now. - * - * @param begin the begin - * @return the timestamp diff now - */ - public static int getTimestampDiffNow(String begin) { - int starTime = getTimestampSecond(begin); - int endTm = (int)(System.currentTimeMillis() / 1000); - - return endTm - starTime; - } -} diff --git a/src/main/java/com/dispose/common/Http.java b/src/main/java/com/dispose/common/Http.java deleted file mode 100644 index 8b77f1e5..00000000 --- a/src/main/java/com/dispose/common/Http.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.dispose.common; - -import cn.hutool.http.Header; -import cn.hutool.http.HttpRequest; - -import java.util.Map; - -/** - * The type Http. - * - * @author - */ -public class Http { - - /** - * Post json string. - * - * @param url the url - * @param header the header - * @param body the body - * @return the string - */ - public static String postJson(String url, Map header, String body) { - return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body) - .execute().body(); - } - - /** - * Post form string. - * - * @param url the url - * @param header the header - * @param body the body - * @return the string - */ - public static String postForm(String url, Map header, Map body) { - //header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded") - return HttpRequest.post(url).addHeaders(header).form(body) - .execute().body(); - } - - /** - * Get string. - * - * @param url the url - * @param header the header - * @return the string - */ - public static String get(String url, Map header) { - return HttpRequest.get(url).addHeaders(header).execute().body(); - } - -} diff --git a/src/main/java/com/dispose/common/IPAddrType.java b/src/main/java/com/dispose/common/IPAddrType.java deleted file mode 100644 index a3254f6c..00000000 --- a/src/main/java/com/dispose/common/IPAddrType.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.dispose.common; - -import inet.ipaddr.AddressStringException; -import inet.ipaddr.IPAddress; -import inet.ipaddr.IPAddressSeqRange; -import inet.ipaddr.IPAddressString; - -/** - * The enum Ip addr type. - * - * @author - */ -public enum IPAddrType { - /** - * Ipv 4 type ip addr type. - */ - IPV4_TYPE, - /** - * Ipv 6 type ip addr type. - */ - IPV6_TYPE; - - /** - * Gets ip addr type. - * - * @param ipAddr the ip addr - * @return the ip addr type - */ - public static IPAddrType getIpAddrType(String ipAddr) { - if (ipAddr.contains(GlobalVar.STRING_IPV6_FLAG)) { - return IPV6_TYPE; - } else { - return IPV4_TYPE; - } - } - - /** - * Ip in range boolean. - * - * @param startIp the start ip - * @param endIp the end ip - * @param ipAddr the ip addr - * @return the boolean - * @throws AddressStringException the address string exception - */ - public static boolean ipInRange(String startIp, String endIp, String ipAddr) throws AddressStringException { - IPAddress lower = new IPAddressString(startIp).toAddress(); - IPAddress upper = new IPAddressString(endIp).toAddress(); - IPAddress addr = new IPAddressString(ipAddr).toAddress(); - - IPAddressSeqRange range = lower.toSequentialRange(upper); - - return range.contains(addr); - } - - /** - * Ip in range boolean. - * - * @param rangeIp the range ip - * @param ipAddr the ip addr - * @return the boolean - * @throws AddressStringException the address string exception - */ - public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException { - final int numIp = 2; - - // 范围为空字符串或者与IP相同时,返回真 - if (rangeIp.length() == 0 || rangeIp.equals(ipAddr)) { - return true; - } - - String[] ipList = rangeIp.split("-"); - - if (ipList.length != numIp) { - return false; - } - - IPAddress lower = new IPAddressString(ipList[0]).toAddress(); - IPAddress upper = new IPAddressString(ipList[1]).toAddress(); - IPAddress addr = new IPAddressString(ipAddr).toAddress(); - - IPAddressSeqRange range = lower.toSequentialRange(upper); - - return range.contains(addr); - } - - /** - * Is ip address boolean. - * - * @param ipAddr the ip addr - * @return the boolean - */ - public static boolean isIpAddress(String ipAddr) { - - final String ipv6PortChar = "["; - - int counts = ipAddr.length() - ipAddr.replaceAll(GlobalVar.STRING_IPV6_FLAG, "").length(); - - String ipv4Regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." - + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." - + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$"; - - String ipv6Regex = "^(([\\da-fA-F]{1,4}):){8}$"; - - switch (counts) { - // ipv4 - case 0: - return ipAddr.matches(ipv4Regex); - // v4 + port - case 1: - String ipv4 = ipAddr.substring(0, ipAddr.lastIndexOf(GlobalVar.STRING_IPV6_FLAG)); - return ipv4.matches(ipv4Regex); - default: - // Ip v6 + port - if (ipAddr.contains(ipv6PortChar)) { - String ipv6 = ipAddr.substring(1, ipAddr.lastIndexOf(ipv6PortChar)); - return ipv6.matches(ipv6Regex); - } else { - return ipAddr.matches(ipv6Regex); - } - } - } -} - - diff --git a/src/main/java/com/dispose/config/SetupInit.java b/src/main/java/com/dispose/config/SetupInit.java deleted file mode 100644 index 67a1d587..00000000 --- a/src/main/java/com/dispose/config/SetupInit.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.dispose.config; - -import com.dispose.common.GlobalVar; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.TaskService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; - -/** - * The type Setup init. - * - * @author - */ -@Component -@Slf4j -public class SetupInit implements CommandLineRunner { - @Resource - private DisposeConfigure disposeConfigure; - - @Resource - private DpTechConfigure dpTechConfigure; - - @Resource - private DisposeNodeManager disposeNodeManager; - - @Resource - private TaskService taskService; - - private void loadConfigure() { - try { - GlobalVar.SOAP_CONNECT_TIMEOUT = Integer.parseInt(dpTechConfigure.getSoapConnTimeout()); - } catch(Exception ex) { - log.error("load SOAP_CONNECT_TIMEOUT configure error: {}", ex.getMessage()); - } - - try { - GlobalVar.SOAP_RECEIVE_TIMEOUT = Integer.parseInt(dpTechConfigure.getSoapRecvTimeout()); - } catch(Exception ex) { - log.error("load SOAP_RECEIVE_TIMEOUT configure error: {}", ex.getMessage()); - } - - try { - GlobalVar.IS_CHECK_REQUEST_TIMEOUT = Boolean.parseBoolean(disposeConfigure.getCheckProtocolTimeout()); - } catch(Exception ex) { - log.error("load IS_CHECK_REQUEST_TIMEOUT configure error: {}", ex.getMessage()); - } - } - - /** - * Run. - * - * @param args the args - */ - @Override - public void run(String... args) { - // 系统初始化入口 - loadConfigure(); - disposeNodeManager.loadDisposeNodeFromDatabase(); - taskService.loadTaskFromDatabase(); - } -} \ No newline at end of file diff --git a/src/main/java/com/dispose/config/TokenConfig.java b/src/main/java/com/dispose/config/TokenConfig.java deleted file mode 100644 index 1c8489fc..00000000 --- a/src/main/java/com/dispose/config/TokenConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.dispose.config; - -import com.dispose.interceptor.TokenInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * The type Token config. - * - * @author - */ -@Configuration -public class TokenConfig implements WebMvcConfigurer { - /** - * Init auth interceptor token interceptor. - * - * @return the token interceptor - */ - @Bean - public TokenInterceptor initAuthInterceptor(){ - return new TokenInterceptor(); - } - - /** - * Add interceptors. - * - * @param registry the registry - */ - @Override - public void addInterceptors(InterceptorRegistry registry) { - // 注册需要检查token的控制器接口 - registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/information/**"); - registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/manager/**"); - registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/task/**"); - } -} diff --git a/src/main/java/com/dispose/controller/AuthController.java b/src/main/java/com/dispose/controller/AuthController.java deleted file mode 100644 index 14ecf6ff..00000000 --- a/src/main/java/com/dispose/controller/AuthController.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.dispose.controller; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.auth.LoginReq; -import com.dispose.pojo.vo.auth.LoginRsp; -import com.dispose.pojo.vo.auth.LogoutRsp; -import com.dispose.service.UserAccountService; -import com.fasterxml.jackson.core.JsonProcessingException; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import java.security.NoSuchAlgorithmException; - -/** - * The type Auth controller. - * - * @author - */ -@Controller -@RequestMapping(value = "/auth") -@Slf4j -@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口") -@Component -public class AuthController { - @Resource - private UserAccountService userAccountService; - - /** - * User login protocol resp dto. - * - * @param mr the mr - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @PostMapping("/login") - @ResponseBody - @ApiOperation("登录") - public ProtocolRespDTO userLogin(@RequestBody ProtocolReqDTO mr) - throws JsonProcessingException, NoSuchAlgorithmException { - ErrorCode err = mr.verifyRequest(); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - LoginReq reqInfo = mr.getRequestObject(LoginReq.class); - - if (reqInfo.getUserName() == null || reqInfo.getUserName().length() == 0) { - log.error("Request username params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getUserName()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getPassword() == null || reqInfo.getPassword().length() == 0) { - log.error("Request password params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getPassword()); - return ProtocolRespDTO.result(ErrorCode.ERR_PASSWORD); - } - - MulReturnType ret = userAccountService.loginService(reqInfo.getUserName(), - reqInfo.getPassword()); - - if (ret.getFirstParam() != ErrorCode.ERR_OK) { - log.error("User login failed, error:{}", ret.getFirstParam().getMsg()); - return ProtocolRespDTO.result(ret.getFirstParam()); - } - - LoginRsp rspInfo = LoginRsp.builder() - .userName(reqInfo.getUserName()) - .token(ret.getSecondParam()) - .logTime(System.currentTimeMillis()) - .expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS) - .build(); - - rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); - rspInfo.setMessage(ErrorCode.ERR_OK.getMsg()); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * User logout protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/logout") - @ResponseBody - @ApiOperation("注销") - public ProtocolRespDTO userLogout(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - LoginReq reqInfo = mr.getRequestObject(LoginReq.class); - - if (reqInfo.getUserName() == null || reqInfo.getUserName().length() == 0) { - log.error("Request username params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getUserName()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - err = userAccountService.logoutService(reqInfo.getUserName(), mr.getAuthToken()); - - if (err != ErrorCode.ERR_OK) { - log.error("User logout failed, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - LogoutRsp rspInfo = LogoutRsp.builder() - .userName(reqInfo.getUserName()) - .build(); - - rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); - rspInfo.setMessage(ErrorCode.ERR_OK.getMsg()); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } -} diff --git a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java b/src/main/java/com/dispose/controller/DisposeNodeInfoController.java deleted file mode 100644 index b9829cbd..00000000 --- a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java +++ /dev/null @@ -1,712 +0,0 @@ -package com.dispose.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.Helper; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.vo.common.DisposeCapacity; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.pojo.vo.information.DeviceCapacityData; -import com.dispose.pojo.vo.information.DeviceCapacityRsp; -import com.dispose.pojo.vo.information.DeviceInfoData; -import com.dispose.pojo.vo.information.DeviceInfoRsp; -import com.dispose.pojo.vo.information.DisposeNodeData; -import com.dispose.pojo.vo.information.DisposeNodeListRsp; -import com.dispose.pojo.vo.information.LinkStatusListRsp; -import com.dispose.pojo.vo.information.LinkStatusRsp; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.information.VersionListRsp; -import com.dispose.pojo.vo.information.VersionRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.TaskService; -import com.fasterxml.jackson.core.JsonProcessingException; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -/** - * The type Dispose node info controller. - * - * @author - */ -@Controller -@RequestMapping(value = "/information") -@Slf4j -@Api(value = "抗DDoS处置平台能力节点信息接口", tags = "抗DDoS处置平台能力节点信息接口") -@Component -public class DisposeNodeInfoController { - @Resource - private TaskService taskService; - - @Resource - private DisposeNodeManager disposeNodeManager; - - /** - * Gets link status. - * - * @param mr the mr - * @param headers the headers - * @return the link status - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/linkstatus") - @ResponseBody - @ApiOperation("链接状态") - public ProtocolRespDTO getLinkStatus(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - LinkStatusListRsp rspInfo = new LinkStatusListRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> rspInfo.getItems().add(LinkStatusRsp.builder() - .online(v.getLinkStatus()) - .id(v.getId().toString()) - .status(ErrorCode.ERR_OK.getCode()) - .message(ErrorCode.ERR_OK.getMsg()) - .build())); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - rspInfo.getItems().add(LinkStatusRsp.builder() - .online(0) - .id(v) - .status(ErrorCode.ERR_NOSUCHDEVICE.getCode()) - .message(ErrorCode.ERR_NOSUCHDEVICE.getMsg()) - .build()); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets version. - * - * @param mr the mr - * @param headers the headers - * @return the version - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/version") - @ResponseBody - @ApiOperation("处置设备版本") - public ProtocolRespDTO getVersion(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - VersionListRsp rspInfo = new VersionListRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> rspInfo.getItems().add(VersionRsp.builder() - .id(v.getId().toString()) - .version(v.getVersion()) - .status(ErrorCode.ERR_OK.getCode()) - .message(ErrorCode.ERR_OK.getMsg()) - .build())); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - rspInfo.getItems().add(VersionRsp.builder() - .id(v) - .status(ErrorCode.ERR_NOSUCHDEVICE.getCode()) - .message(ErrorCode.ERR_NOSUCHDEVICE.getMsg()) - .build()); - }); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * Gets device info. - * - * @param mr the mr - * @param headers the headers - * @return the device info - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/deviceinfo") - @ResponseBody - @ApiOperation("处置设备信息") - public ProtocolRespDTO getDeviceInfo(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - DeviceInfoRsp rspInfo = new DeviceInfoRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> rspInfo.getItems().add(new DeviceInfoData( - v.getId().toString(), - v.getDevInfo().getVendor(), - v.getDevInfo().getModel(), - v.getDevInfo().getFirmware(), - v.getDevInfo().getOs(), - v.getDevInfo().getKernel(), - v.getDevInfo().getArch(), - v.getDevInfo().getMemory(), - v.getDevInfo().getFreeMemory(), - v.getDevInfo().getCpuUsed(), - ErrorCode.ERR_OK - ))); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE)); - }); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * Gets capacity. - * - * @param mr the mr - * @param headers the headers - * @return the capacity - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/capacity") - @ResponseBody - @ApiOperation("处置设备处置能力") - public ProtocolRespDTO getCapacity(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - DeviceCapacityRsp rspInfo = new DeviceCapacityRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps()); - cpData.setId(v.getId().toString()); - cpData.setStatus(ErrorCode.ERR_OK.getCode()); - cpData.setMessage(ErrorCode.ERR_OK.getMsg()); - rspInfo.getItems().add(cpData); - }); - - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - DeviceCapacityData cpData = new DeviceCapacityData(); - cpData.setId(v); - cpData.setCapacity(null); - cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - rspInfo.getItems().add(cpData); - }); - - return ProtocolRespDTO.result(err, rspInfo, DisposeCapacity.CapacityView.class); - } - - /** - * Gets protected ip. - * - * @param mr the mr - * @param headers the headers - * @return the protected ip - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/protected_ip") - @ResponseBody - @ApiOperation("处置设备防护IP") - public ProtocolRespDTO getProtectedIp(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - DeviceCapacityRsp rspInfo = new DeviceCapacityRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps()); - cpData.setId(v.getId().toString()); - cpData.setStatus(ErrorCode.ERR_OK.getCode()); - cpData.setMessage(ErrorCode.ERR_OK.getMsg()); - rspInfo.getItems().add(cpData); - }); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - DeviceCapacityData cpData = new DeviceCapacityData(); - cpData.setId(v); - cpData.setCapacity(null); - cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - rspInfo.getItems().add(cpData); - }); - - return ProtocolRespDTO.result(err, rspInfo, DisposeCapacity.DependIpView.class); - - } - - /** - * Gets dispose node list. - * - * @param mr the mr - * @param headers the headers - * @return the dispose node list - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/node_list") - @ResponseBody - @ApiOperation("处置设备列表") - public ProtocolRespDTO getDisposeNodeList(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - if (mr.getMsgContent() == null || mr.getMsgContent().length() == 0) { - log.error("ProtocolReqDTO msgContent error"); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - DisposeNodeListRsp rspInfo = new DisposeNodeListRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - DisposeNodeData dpData = DisposeNodeData.builder() - .type(v.getType()) - .name(v.getName()) - .ip(v.getIpAddr()) - .build(); - - dpData.setId(v.getId().toString()); - dpData.setStatus(ErrorCode.ERR_OK.getCode()); - dpData.setMessage(ErrorCode.ERR_OK.getMsg()); - rspInfo.getItems().add(dpData); - }); - - if (reqInfo.getId().length != 0) { - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - DisposeNodeData dpData = new DisposeNodeData(); - dpData.setId(v); - dpData.setCapacity(null); - dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - rspInfo.getItems().add(dpData); - }); - } - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets dispose node details. - * - * @param mr the mr - * @param headers the headers - * @return the dispose node details - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/node_details") - @ResponseBody - @ApiOperation("处置节点详细信息") - public ProtocolRespDTO getDisposeNodeDetails(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - DisposeNodeListRsp rspInfo = new DisposeNodeListRsp(); - rspInfo.setItems(new ArrayList<>()); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - DisposeNodeData dpData = new DisposeNodeData( - v.getType(), v.getName(), v.getIpAddr(), - v.getAreaCode(), v.getManufacturer(), v.getModel(), - v.getVersion(), v.getReadme(), v.getDevCaps()); - - dpData.setId(v.getId().toString()); - dpData.setStatus(ErrorCode.ERR_OK.getCode()); - dpData.setMessage(ErrorCode.ERR_OK.getMsg()); - rspInfo.getItems().add(dpData); - }); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - DisposeNodeData dpData = new DisposeNodeData(); - dpData.setId(v); - dpData.setCapacity(null); - dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - rspInfo.getItems().add(dpData); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets running dispose task list. - * - * @param mr the mr - * @param headers the headers - * @return the running dispose task list - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/run_task") - @ResponseBody - @ApiOperation("获取正在进行的处置任务") - public ProtocolRespDTO getRunningDisposeTaskList(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - NodeTaskRsp rspInfo = new NodeTaskRsp(); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v.getId().toString()); - - List runTasks = taskService.getNodeAllRunningTask(v.getId()); - - if (runTasks == null || runTasks.size() == 0) { - log.error("No tasks in progress"); - taskData.setTaskArray(null); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - } else { - runTasks.forEach(k -> { - int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime()); - - TaskInfoData taskInfoData = TaskInfoData.builder() - .taskId(k.getId().toString()) - .type(k.getType()) - .startTime(Helper.getTimestampSecond(k.getCreateTime())) - .disposeTime(diff) - .disposeIp(k.getDisposeIp()) - .flowAttack(0) - .flowClean(0) - .build(); - - taskData.getTaskArray().add(taskInfoData); - taskData.setStatus(ErrorCode.ERR_OK.getCode()); - taskData.setMessage(ErrorCode.ERR_OK.getMsg()); - }); - } - }); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v); - taskData.setTaskArray(null); - taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets all dispose task list. - * - * @param mr the mr - * @param headers the headers - * @return the all dispose task list - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/all_task") - @ResponseBody - @ApiOperation("获取所有处置任务") - public ProtocolRespDTO getAllDisposeTaskList(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - NodeTaskRsp rspInfo = new NodeTaskRsp(); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v.getId().toString()); - - List runTasks = taskService.getNodeAllTask(v.getId()); - - if (runTasks == null || runTasks.size() == 0) { - log.error("No such tasks"); - taskData.setTaskArray(null); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - } else { - runTasks.forEach(k -> { - int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime()); - - TaskInfoData taskInfoData = TaskInfoData.builder() - .taskId(k.getId().toString()) - .type(k.getType()) - .startTime(Helper.getTimestampSecond(k.getCreateTime())) - .disposeTime(diff) - .disposeIp(k.getDisposeIp()) - .currentStatus(taskService.taskIsRunning(k) ? 0 : 1) - .flowAttack(0) - .flowClean(0) - .build(); - - taskData.getTaskArray().add(taskInfoData); - taskData.setStatus(ErrorCode.ERR_OK.getCode()); - taskData.setMessage(ErrorCode.ERR_OK.getMsg()); - }); - } - }); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> !StringUtils.isNumeric(v) - || valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("device not exist, deviceId:{}", v); - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v); - taskData.setTaskArray(null); - taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } -} diff --git a/src/main/java/com/dispose/controller/DisposeNodeManagerController.java b/src/main/java/com/dispose/controller/DisposeNodeManagerController.java deleted file mode 100644 index c7280cd8..00000000 --- a/src/main/java/com/dispose/controller/DisposeNodeManagerController.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.dispose.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.manager.UserAccountCacheManager; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.dispose.pojo.vo.device.AddNodeReq; -import com.dispose.pojo.vo.device.AddNodeRetData; -import com.dispose.pojo.vo.device.AddNodeRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.TaskService; -import com.fasterxml.jackson.core.JsonProcessingException; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - -/** - * The type Dispose node manager controller. - * - * @author - */ -@Controller -@RequestMapping(value = "/manager") -@Slf4j -@Api(value = "抗DDoS处置平台能力节点管理接口", tags = "抗DDoS处置平台能力节点管理接口") -@Component -public class DisposeNodeManagerController { - @Resource - private DisposeNodeManager disposeNodeManager; - - @Resource - private UserAccountCacheManager userAccountCacheManager; - - @Resource - private TaskService taskService; - - /** - * Add dispose node protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PutMapping("/device") - @ResponseBody - @ApiOperation("添加处置能力节点") - public ProtocolRespDTO addDisposeNode(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - err = userAccountCacheManager.verifyPermission(mr.getAuthToken()); - - if (err != ErrorCode.ERR_OK) { - log.error("User not enough permissions, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - AddNodeReq reqInfo = mr.getRequestObject(AddNodeReq.class); - AddNodeRsp rspInfo = new AddNodeRsp(); - - reqInfo.getItems().forEach(v -> { - DisposeDevice dev = DisposeDevice.builder() - .type(v.getType()) - .name(v.getName()) - .ipAddr(v.getIpAddr()) - .areaCode(v.getAreaCode()) - .manufacturer(v.getManufacturer()) - .model(v.getModel()) - .version(v.getVersion()) - .userName(v.getUserName()) - .password(v.getPassword()) - .url(v.getUrl()) - .build(); - MulReturnType ret; - try { - ret = disposeNodeManager.addNewDisposeDevice(dev); - } catch (Exception ex) { - log.error(ex.getMessage()); - ret = new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, v.getIpAddr()); - } - - AddNodeRetData retStatus = new AddNodeRetData(); - retStatus.setIpAddr(v.getIpAddr()); - retStatus.setDevId(ret.getSecondParam()); - retStatus.setStatus(ret.getFirstParam().getCode()); - retStatus.setMessage(ret.getFirstParam().getMsg()); - rspInfo.getItems().add(retStatus); - }); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * Remove dispose node protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @DeleteMapping("/device") - @ResponseBody - @ApiOperation("删除处置能力节点") - public ProtocolRespDTO removeDisposeNode(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - err = userAccountCacheManager.verifyPermission(mr.getAuthToken()); - - if (err != ErrorCode.ERR_OK) { - log.error("User not enough permissions, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getId() == null) { - log.error("Request params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getId()[0].length() == 0) { - log.error("Prohibit deleting multiple devices at the same time"); - return ProtocolRespDTO.result(ErrorCode.ERR_REMOVEMORE); - } - - List rspInfo = new ArrayList<>(); - - IDReturnStatus retItem = new IDReturnStatus(); - retItem.setId(reqInfo.getId()[0]); - - err = disposeNodeManager.delDisposeDeviceById(Long.valueOf(reqInfo.getId()[0])); - - retItem.setStatus(err.getCode()); - retItem.setMessage(err.getMsg()); - - rspInfo.add(retItem); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } -} diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java deleted file mode 100644 index 040820bd..00000000 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ /dev/null @@ -1,638 +0,0 @@ -package com.dispose.controller; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.common.FlowDirection; -import com.dispose.common.Helper; -import com.dispose.common.IPAddrType; -import com.dispose.manager.TaskCacheManager; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.task.GetTaskReq; -import com.dispose.pojo.vo.task.StartTaskReq; -import com.dispose.pojo.vo.task.StartTaskRsp; -import com.dispose.pojo.vo.task.StopTaskData; -import com.dispose.pojo.vo.task.StopTaskReq; -import com.dispose.pojo.vo.task.TaskInfoRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.TaskService; -import com.dispose.service.UserAccountService; -import com.fasterxml.jackson.core.JsonProcessingException; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.annotation.Resource; -import javax.validation.Valid; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -/** - * The type Dispose task controller. - * - * @author - */ -@Controller -@RequestMapping(value = "/task") -@Slf4j -@Api(value = "抗DDoS处置平台处置任务接口", tags = "抗DDoS处置平台处置任务接口") -@Component -public class DisposeTaskController { - @Resource - private DisposeNodeManager disposeNodeManager; - - @Resource - private TaskService taskService; - - @Resource - private TaskCacheManager taskCacheManager; - - @Resource - private UserAccountService userAccountService; - - private static Long convertTimeToLong(String time) { - DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime parse = LocalDateTime.parse(time, ftf); - return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - } - - /** - * Task start protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/start") - @ResponseBody - @ApiOperation("启动处置任务") - public ProtocolRespDTO taskStart(@RequestBody @Valid ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class); - - if (reqInfo.getId() == null || reqInfo.getId().length() == 0) { - log.error("Request id params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getId()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getType() == null - || reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode() - || reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) { - log.error("Request type params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getType()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getDisposeIp() == null || reqInfo.getDisposeIp().length() == 0 - || !IPAddrType.isIpAddress(reqInfo.getDisposeIp())) { - log.error("Request dispose ip params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeIp()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() <= 0) { - log.error("Request dispose time params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeTime()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - StartTaskRsp rspInfo = new StartTaskRsp(); - - TaskInfoDetail task = TaskInfoDetail.builder() - .deviceId(Long.valueOf(reqInfo.getId())) - .accountId(userAccountService.getUserByToken(mr.getAuthToken()).getId()) - .type(reqInfo.getType()) - .disposeIp(reqInfo.getDisposeIp()) - .planEndTime(String.valueOf(reqInfo.getDisposeTime())) - .flowDirection(reqInfo.getFlowDirection() != null ? reqInfo.getFlowDirection() : FlowDirection.DIRECTION_TWOWAY.getCode()) - .flowBandWidth(reqInfo.getFlowBandwidth() != null ? reqInfo.getFlowBandwidth() : 1024) - .attackType(Helper.attackArrayToString(reqInfo.getAttackType())) - .build(); - - MulReturnType ret = taskService.createTask(task); - - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - TaskInfoDetail tf = taskCacheManager.getTaskById(ret.getSecondParam()); - rspInfo.setId(String.valueOf(tf.getDeviceId())); - rspInfo.setTaskId(String.valueOf(ret.getSecondParam())); - rspInfo.setExpireTime(convertTimeToLong(tf.getPlanEndTime())); - } else { - log.error("Failed to create task, error:{}", ret.getFirstParam().getMsg()); - rspInfo.setId(String.valueOf(reqInfo.getId())); - } - - rspInfo.setStatus(ret.getFirstParam().getCode()); - rspInfo.setMessage(ret.getFirstParam().getMsg()); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Task stop protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/stop") - @ResponseBody - @ApiOperation("停止处置任务") - public ProtocolRespDTO taskStop(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getTaskId() == null - || Arrays.stream(reqInfo.getTaskId()).anyMatch(v -> v.length() == 0)) { - log.error("Request taskId params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - TaskInfoRsp rspInfo = new TaskInfoRsp(); - - Arrays.stream(reqInfo.getTaskId()).forEach(v -> { - TaskInfoData taskData = TaskInfoData.builder().type(DeviceCapacity.CLEANUP.getCode()).build(); - - List> ret = taskService.stopTaskByTaskId(Long.parseLong(v)); - - if (ret.size() == 0) { - log.error("No such dispose task, taskId:{}", v); - taskData.setTaskId(v); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - rspInfo.getItems().add(taskData); - } else { - ret.forEach(k -> { - if (k.getFirstParam() == ErrorCode.ERR_OK) { - ErrorCode retError = k.getFirstParam(); - TaskInfoDetail taskInfo = k.getSecondParam(); - taskData.setId(String.valueOf(taskInfo.getDeviceId())); - taskData.setTaskId(String.valueOf(taskInfo.getId())); - taskData.setType(taskInfo.getType()); - taskData.setDisposeIp(taskInfo.getDisposeIp()); - taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60); - - taskData.setStatus(retError.getCode()); - taskData.setMessage(retError.getMsg()); - - rspInfo.getItems().add(taskData); - } else { - log.error("Stop task: taskId:{}, error:{}", v, k.getFirstParam().getMsg()); - taskData.setTaskId(v); - taskData.setStatus(k.getFirstParam().getCode()); - taskData.setMessage(k.getFirstParam().getMsg()); - } - }); - } - }); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * Task stop by ip protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/stop_ip") - @ResponseBody - @ApiOperation("根据处置IP停止处置任务") - public ProtocolRespDTO taskStopByIp(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class); - - if (reqInfo.getItems().stream().anyMatch(v -> v.getId() == null - || v.getId().length() == 0)) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getItems().stream().anyMatch(v -> v.getType() == null - || v.getType() < DeviceCapacity.ALLCAPACITY.getCode() - || v.getType() > DeviceCapacity.DETECIVE.getCode())) { - log.error("Request type params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getItems().stream().anyMatch(v -> v.getDisposeIp() == null - || v.getDisposeIp().length() == 0 - || !IPAddrType.isIpAddress(v.getDisposeIp()))) { - log.error("Request ip params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - TaskInfoRsp rspInfo = new TaskInfoRsp(); - - reqInfo.getItems().forEach(v -> { - TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build(); - - List> ret = taskService.stopTaskByDisposeIp(Long.parseLong(v.getId()), v.getType(), v.getDisposeIp()); - - if (ret.size() == 0) { - log.error("No such dispose task, deviceId:{}", v.getId()); - taskData.setId(v.getId()); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - rspInfo.getItems().add(taskData); - } else { - ret.forEach(k -> { - if (k.getFirstParam() == ErrorCode.ERR_OK) { - ErrorCode retError = k.getFirstParam(); - TaskInfoDetail taskInfo = k.getSecondParam(); - taskData.setId(String.valueOf(taskInfo.getDeviceId())); - taskData.setTaskId(String.valueOf(taskInfo.getId())); - taskData.setType(taskInfo.getType()); - taskData.setDisposeIp(taskInfo.getDisposeIp()); - taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60); - - taskData.setStatus(retError.getCode()); - taskData.setMessage(retError.getMsg()); - } else { - log.error("Stop task: taskId:{}, type:{}, disposeIp:{}, error:{}", v.getId(), v.getType(), v.getDisposeIp(), - k.getFirstParam().getMsg()); - if (k.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) { - taskData.setDisposeIp(v.getDisposeIp()); - } else if (k.getFirstParam() == ErrorCode.ERR_NOSUCHDEVICE) { - taskData.setId(v.getId()); - } - taskData.setStatus(k.getFirstParam().getCode()); - taskData.setMessage(k.getFirstParam().getMsg()); - } - - rspInfo.getItems().add(taskData); - }); - } - }); - - return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); - } - - /** - * Task stop all of dispose node protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/stop_node") - @ResponseBody - @ApiOperation("停止处置节点处置任务") - public ProtocolRespDTO taskStopAllOfDisposeNode(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - StopTaskReq reqInfo = mr.getRequestObject(StopTaskReq.class); - TaskInfoRsp rspInfo = new TaskInfoRsp(); - - if (reqInfo.getItems().stream().anyMatch(v -> v.getId() == null - || v.getId().length() == 0)) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getItems().stream().anyMatch(v -> v.getType() == null - || v.getType() < DeviceCapacity.ALLCAPACITY.getCode() - || v.getType() > DeviceCapacity.DETECIVE.getCode())) { - log.error("Request type params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - reqInfo.getItems().forEach(v -> { - List> ret = taskService.stopTaskByDisposeNode(Long.parseLong(v.getId()), v.getType()); - - if (ret.size() == 0) { - log.error("No such dispose task, deviceId:{}", v.getId()); - TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build(); - taskData.setId(v.getId()); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - rspInfo.getItems().add(taskData); - } else { - ret.forEach(k -> { - if (k.getFirstParam() == ErrorCode.ERR_OK) { - TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build(); - ErrorCode retError = k.getFirstParam(); - TaskInfoDetail taskInfo = k.getSecondParam(); - taskData.setId(String.valueOf(taskInfo.getDeviceId())); - taskData.setTaskId(String.valueOf(taskInfo.getId())); - taskData.setType(taskInfo.getType()); - taskData.setDisposeIp(taskInfo.getDisposeIp()); - taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60); - - taskData.setStatus(retError.getCode()); - taskData.setMessage(retError.getMsg()); - - rspInfo.getItems().add(taskData); - } else { - log.error("Stop task: deviceId:{}, type:{}, error:{}", v.getId(), - v.getType(), k.getFirstParam().getMsg()); - TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build(); - taskData.setId(v.getId()); - taskData.setStatus(k.getFirstParam().getCode()); - taskData.setMessage(k.getFirstParam().getMsg()); - } - }); - } - }); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Task stop all protocol resp dto. - * - * @param mr the mr - * @param headers the headers - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/stop_all") - @ResponseBody - @ApiOperation("停止所有处置任务") - public ProtocolRespDTO taskStopAll(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - StopTaskData reqInfo = mr.getRequestObject(StopTaskData.class); - - if (reqInfo.getType() == null - || reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode() - || reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) { - log.error("Request type params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - TaskInfoRsp rspInfo = new TaskInfoRsp(); - - List> ret = taskService.stopTaskByType(reqInfo.getType()); - - if (ret.size() == 0) { - log.error("No such dispose task"); - TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build(); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - rspInfo.getItems().add(taskData); - } else { - ret.forEach(k -> { - if (k.getFirstParam() == ErrorCode.ERR_OK) { - TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build(); - ErrorCode retError = k.getFirstParam(); - TaskInfoDetail taskInfo = k.getSecondParam(); - taskData.setId(String.valueOf(taskInfo.getDeviceId())); - taskData.setTaskId(String.valueOf(taskInfo.getId())); - taskData.setType(taskInfo.getType()); - taskData.setDisposeIp(taskInfo.getDisposeIp()); - taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60); - - taskData.setStatus(retError.getCode()); - taskData.setMessage(retError.getMsg()); - - rspInfo.getItems().add(taskData); - } else { - log.error("No task to stop: error:{}", k.getFirstParam().getMsg()); - TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build(); - taskData.setType(reqInfo.getType()); - taskData.setStatus(k.getFirstParam().getCode()); - taskData.setMessage(k.getFirstParam().getMsg()); - } - - }); - } - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets node task. - * - * @param mr the mr - * @param headers the headers - * @return the node task - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/get_node") - @ResponseBody - @ApiOperation("获取节点处置任务") - public ProtocolRespDTO getNodeTask(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - GetTaskReq reqInfo = mr.getRequestObject(GetTaskReq.class); - - if (reqInfo.getId() == null) { - log.error("Request id params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - if (reqInfo.getType() == null - || reqInfo.getType() < DeviceCapacity.ALLCAPACITY.getCode() - || reqInfo.getType() > DeviceCapacity.DETECIVE.getCode()) { - log.error("Request type params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - NodeTaskRsp rspInfo = new NodeTaskRsp(); - - List valuableData = disposeNodeManager.getAllDisposeDevice() - .stream() - .filter(v -> reqInfo.getId().length == 0 - || reqInfo.getId()[0].length() == 0 - || Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v.getId().toString()); - - AtomicBoolean bHasData = new AtomicBoolean(false); - taskService.getNodeAllRunningTask(v.getId()).forEach(k -> { - if (v.getType().equals(reqInfo.getType()) - || reqInfo.getType() == DeviceCapacity.ALLCAPACITY.getCode()) { - int diff = Helper.getTimestampDiff(k.getCreateTime(), k.getPlanEndTime()); - TaskInfoData taskInfoData = TaskInfoData.builder() - .taskId(k.getId().toString()) - .type(k.getType()) - .startTime(Helper.getTimestampSecond(k.getCreateTime())) - .disposeTime(diff) - .disposeIp(k.getDisposeIp()) - .flowAttack(0) - .flowClean(0) - .build(); - - taskData.getTaskArray().add(taskInfoData); - bHasData.compareAndSet(false, true); - } - }); - - if (bHasData.get()) { - taskData.setStatus(ErrorCode.ERR_OK.getCode()); - taskData.setMessage(ErrorCode.ERR_OK.getMsg()); - } else { - log.error("No such task, deviceId:{}", v.getId()); - taskData.setId(v.getId().toString()); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - taskData.setTaskArray(null); - } - }); - - List unExists = Arrays.stream(reqInfo.getId()) - .filter(v -> v.length() > 0) - .filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("No such task, deviceId:{}", v); - NodeTaskData taskData = new NodeTaskData(); - rspInfo.getItems().add(taskData); - taskData.setId(v); - taskData.setTaskArray(null); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } - - /** - * Gets all task. - * - * @param mr the mr - * @param headers the headers - * @return the all task - * @throws JsonProcessingException the json processing exception - */ - @PostMapping("/get") - @ResponseBody - @ApiOperation("获取全部处置任务") - public ProtocolRespDTO getAllTask(@RequestBody ProtocolReqDTO mr, - @RequestHeader HttpHeaders headers) - throws JsonProcessingException { - ErrorCode err = mr.verifyRequest(headers); - - if (err != ErrorCode.ERR_OK) { - log.error("Request header error, error:{}", err.getMsg()); - return ProtocolRespDTO.result(err); - } - - IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class); - - if (reqInfo.getTaskId() == null) { - log.error("Request taskId params error, error:{}", mr.getMsgContent()); - return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); - } - - TaskInfoRsp rspInfo = new TaskInfoRsp(); - - List valuableData = taskService.getAllTask() - .stream() - .filter(v -> reqInfo.getTaskId().length == 0 - || reqInfo.getTaskId()[0].length() == 0 - || Arrays.stream(reqInfo.getTaskId()).anyMatch(s -> s.equals(v.getId().toString()))) - .collect(Collectors.toList()); - - valuableData.forEach(v -> { - int diff = Helper.getTimestampDiff(v.getCreateTime(), v.getPlanEndTime()); - - TaskInfoData taskInfoData = TaskInfoData.builder() - .taskId(v.getId().toString()) - .type(v.getType()) - .startTime(Helper.getTimestampSecond(v.getCreateTime())) - .disposeTime(diff / 60) - .disposeIp(v.getDisposeIp()) - .attackType(Helper.attackStringToArray(v.getAttackType())) - .flowDirection(v.getFlowDirection()) - .flowBandWidth(v.getFlowBandWidth()) - .flowAttack(0) - .flowClean(0) - .build(); - - rspInfo.getItems().add(taskInfoData); - taskInfoData.setId(v.getDeviceId().toString()); - taskInfoData.setStatus(ErrorCode.ERR_OK.getCode()); - taskInfoData.setMessage(ErrorCode.ERR_OK.getMsg()); - }); - - List unExists = Arrays.stream(reqInfo.getTaskId()) - .filter(v -> v.length() > 0) - .filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v))) - .collect(Collectors.toList()); - - unExists.forEach(v -> { - log.error("No such task, taskId:{}", v); - TaskInfoData taskData = new TaskInfoData(); - rspInfo.getItems().add(taskData); - taskData.setTaskId(v); - taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg()); - }); - - return ProtocolRespDTO.result(err, rspInfo); - } -} \ No newline at end of file diff --git a/src/main/java/com/dispose/dispose/DeviceRouter.java b/src/main/java/com/dispose/dispose/DeviceRouter.java deleted file mode 100644 index 14949e34..00000000 --- a/src/main/java/com/dispose/dispose/DeviceRouter.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.dispose.dispose; - -import com.dispose.common.DisposeDeviceType; -import com.dispose.common.GlobalVar; -import com.dispose.dispose.impl.DpTechImpl; -import com.dispose.dispose.impl.HaoHanImpl; -import com.dispose.dispose.impl.VirtualDeviceImpl; -import com.dispose.pojo.entity.DisposeDevice; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * The type Device router. - * - * @author - */ -public class DeviceRouter { - - private static final ConcurrentHashMap DEVICE_CACHE_MAP = new ConcurrentHashMap<>(); - - private static String getMapKey(int devType, String ipAddr) { - return devType + "_" + ipAddr; - } - - /** - * Device router factory dispose entry manager. - * - * @param device the device - * @return the dispose entry manager - */ - public static DisposeEntryManager deviceRouterFactory(DisposeDevice device) { - - String mapKey = getMapKey(device.getType(), device.getIpAddr()); - - // 判断缓存中是否创建过对象,如果创建过直接从缓存中获取 - if (DEVICE_CACHE_MAP.containsKey(mapKey)) { - return DEVICE_CACHE_MAP.get(mapKey); - } else { - DisposeEntryManager dev = null; - // 第一次访问创建新对象并缓存 - if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - // 虚拟设备,供调试业务使用 - dev = new VirtualDeviceImpl(device); - } else if (device.getType() == DisposeDeviceType.DPTECH_UMC.getCode()) { - // 迪普设备 - dev = new DpTechImpl(device); - } else if (device.getType() == DisposeDeviceType.HAOHAN_PLATFORM.getCode()) { - // 浩瀚设备 - dev = new HaoHanImpl(device); - } - - if (dev != null) { - DEVICE_CACHE_MAP.put(mapKey, dev); - return dev; - } - } - - // 始终返回一个虚拟设备作为默认设备 - DisposeEntryManager dev = new VirtualDeviceImpl(device); - DEVICE_CACHE_MAP.put(mapKey, dev); - return dev; - } - - /** - * Gets device router factory. - * - * @param devType the dev type - * @param ipAddr the ip addr - * @return the device router factory - */ - public static DisposeEntryManager getDeviceRouterFactory(int devType, String ipAddr) { - - String mapKey = getMapKey(devType, ipAddr); - - // 判断缓存中是否创建过对象,如果创建过直接从缓存中获取 - if (DEVICE_CACHE_MAP.containsKey(mapKey)) { - return DEVICE_CACHE_MAP.get(mapKey); - } else { - // 始终返回一个虚拟设备作为默认设备 - DisposeEntryManager dev = new VirtualDeviceImpl(DisposeDevice.builder().build()); - DEVICE_CACHE_MAP.put(mapKey, dev); - return dev; - } - } -} diff --git a/src/main/java/com/dispose/dispose/DisposeEntryManager.java b/src/main/java/com/dispose/dispose/DisposeEntryManager.java deleted file mode 100644 index 725afb29..00000000 --- a/src/main/java/com/dispose/dispose/DisposeEntryManager.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.dispose.dispose; - - -import com.dispose.common.CleanTaskStatus; -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.dispose.po.DeviceInfo; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.po.MulReturnType; - -import java.util.List; - -/** - * The interface Dispose entry manager. - * - * @author - */ -public interface DisposeEntryManager { - /** - * Run dispose mul return type. - * - * @param ip the ip - * @param type the type - * @param duration the duration - * @return the mul return type - */ - MulReturnType runDispose(String ip, DeviceCapacity type, Long duration); - - /** - * Stop dispose mul return type. - * - * @param ipAddr the ip addr - * @param type the type - * @param devTaskId the dev task id - * @return the mul return type - */ - MulReturnType stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId); - - - /** - * Gets all detection object. - * - * @param the type parameter - * @return the all detection object - */ - T getAllDetectionObject(); - - /** - * Gets all protection object. - * - * @param the type parameter - * @return the all protection object - */ - T getAllProtectionObject(); - - /** - * Gets device capacity. - * - * @return the device capacity - */ - List getDeviceCapacity(); - - /** - * Gets detection devices. - * - * @return the detection devices - */ - String getDetectionDevices(); - - /** - * Gets protect devices. - * - * @return the protect devices - */ - String getProtectDevices(); - - /** - * Gets device link status. - * - * @return the device link status - */ - boolean getDeviceLinkStatus(); - - /** - * Gets version. - * - * @return the version - */ - String getVersion(); - - /** - * Gets device info. - * - * @return the device info - */ - DeviceInfo getDeviceInfo(); - - /** - * Gets device clean task status. - * @param devTaskId device Task Id. - * - * @return the task status - */ - CleanTaskStatus getCleanTaskStatus(Long devTaskId); -} diff --git a/src/main/java/com/dispose/dispose/impl/DpTechImpl.java b/src/main/java/com/dispose/dispose/impl/DpTechImpl.java deleted file mode 100644 index 298bc8e5..00000000 --- a/src/main/java/com/dispose/dispose/impl/DpTechImpl.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.dispose.dispose.impl; - -import com.dispose.common.CleanTaskStatus; -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DpTechAttackType; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.config.DisposeConfigure; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.dispose.po.DeviceInfo; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.po.MulReturnType; -import com.dptech.dispose.AbnormalFlowCleaningServicePortType; -import com.dptech.dispose.ArrayOfProtectionObjectDataForService; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.cxf.endpoint.Client; -import org.apache.cxf.frontend.ClientProxy; -import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; -import org.apache.cxf.transport.http.HTTPConduit; -import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; -import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; -import org.apache.wss4j.dom.WSConstants; -import org.apache.wss4j.dom.handler.WSHandlerConstants; - -import javax.annotation.Resource; -import javax.xml.ws.BindingProvider; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; - -/** - * The type Dp tech. - * - * @author - */ -@Slf4j -@Data -public class DpTechImpl implements DisposeEntryManager { - private final AbnormalFlowCleaningServicePortType cleanTypePort; - - private String password; - - @Resource - private DisposeConfigure disposeConfigure; - - /** - * Instantiates a new Dp tech. - * - * @param dev the dev - */ - public DpTechImpl(DisposeDevice dev) { - JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); - jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); - jaxWsProxyFactoryBean.setAddress(String.format(dev.getUrl(), dev.getIpAddr())); - - this.setPassword(dev.getPassword()); - - //WS-Security Head - Map outProps = new HashMap<>(); - outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); - - // 配置用户名,密码类型 - outProps.put(WSHandlerConstants.USER, dev.getUserName()); - outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); - - // 添加WSSecure头部验证信息 - jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); - - this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); - - Map ctx = ((BindingProvider) this.cleanTypePort).getRequestContext(); - ctx.put("password", dev.getPassword()); - ctx.put("username", dev.getUserName()); - - // 配置连接,访问超时时间 - Client proxy = ClientProxy.getClient(this.cleanTypePort); - HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); - HTTPClientPolicy policy = new HTTPClientPolicy(); - // 请求超时 - policy.setConnectionTimeout(GlobalVar.SOAP_CONNECT_TIMEOUT); - //读取超时 - policy.setReceiveTimeout(GlobalVar.SOAP_RECEIVE_TIMEOUT); - conduit.setClient(policy); - } - - /** - * Gets version. - * - * @return the version - */ - @Override - public String getVersion() { - return "Not Support"; - } - - /** - * Gets device info. - * - * @return the device info - */ - @Override - public DeviceInfo getDeviceInfo() { - // 当前设备接口不支持,返回模拟数据 - return DeviceInfo.builder() - .vendor("DPTech") - .model("UMC") - .firmware("Unknown") - .os("Windows Server") - .kernel("Windows") - .arch("x86_64") - .memory(-1) - .freeMemory(-1) - .cpuUsed(-1) - .build(); - } - - /** - * Gets device capacity. - * - * @return the device capacity - */ - @Override - public List getDeviceCapacity() { - List capList = new ArrayList<>(); - - try { - // 从设备中获取所有检测设备 - String devs = cleanTypePort.getAllDetectDevices(); - - // 保存检测能力信息 - if (devs != null && devs.length() > 0) { - capList.add(DisposeDeviceCapacity.builder() - .capacity(DeviceCapacity.DETECIVE.getCode()) - .tolFlowCapacity(0) - .build()); - } - - // 从设备中获取清洗设备 - devs = cleanTypePort.getAllProtectDevices(); - - if (devs != null && devs.length() > 0) { - List strIpV4 = new ArrayList<>(); - List strIpV6 = new ArrayList<>(); - - // 读取清洗设备支持的清洗IP范围 - ArrayOfProtectionObjectDataForService objs = cleanTypePort.getAllProtectionObjectFromUMC(); - // 将DPTech设备的IP格式转换成IP访问列表,支持IPv6,IPv4 - objs.getProtectionObjectDataForService().forEach(v -> { - String ipSeg = v.getIpSegment().getValue(); - if (v.getIpType() == 0 && ipSeg.length() > 0) { - strIpV4.addAll(Arrays.asList(ipSeg.replaceAll("\\d+_", "").split(","))); - } else if (v.getIpType() == 1 && ipSeg.length() > 0) { - strIpV6.addAll(Arrays.asList(ipSeg.replaceAll("\\d+_", "").split(","))); - } - }); - - // 保存清洗能力信息 - capList.add(DisposeDeviceCapacity.builder() - // 清洗能力 - .capacity(DeviceCapacity.CLEANUP.getCode()) - .tolFlowCapacity(0) - // IPv4范围 - .protectIpV4(strIpV4.toArray(new String[0])) - // IPv6范围 - .protectIpV6(strIpV6.toArray(new String[0])) - .build()); - } - } catch (Exception ex) { - log.error(ex.getMessage()); - } - - return capList; - } - - /** - * Gets device link status. - * - * @return the device link status - */ - @Override - public boolean getDeviceLinkStatus() { - try { - // 获取防护对象接口调用成功认为设备心跳正常 - getAllProtectionObject(); - return true; - } catch (Exception ex) { - log.error(ex.getMessage()); - } - - return false; - } - - /** - * Run dispose mul return type. - * - * @param ip the ip - * @param type the type - * @param duration the duration - * @return the mul return type - */ - @Override - public MulReturnType runDispose(String ip, DeviceCapacity type, Long duration) { - ErrorCode err = ErrorCode.ERR_OK; - // 当前系统接入设备仅仅支持流量清洗功能 - if (type != DeviceCapacity.CLEANUP) { - return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); - } - - try { - log.info("++++Begging DPTech Start Cleanup Task: {}", ip); - // DPTech流量清洗需要对入口,出口方向,各种攻击类型分别调用接口下发清洗任务 - // 遍历出口,入口两个方向 - for (int d : new int[]{0, 1}) { - // 遍历所有清洗类型 - for (DpTechAttackType t : DpTechAttackType.values()) { - CompletableFuture.supplyAsync(() -> cleanTypePort.startAbnormalTaskForUMC(ip, t.getCode(), d)) - .whenComplete((v, ex) -> { - if (ex != null) { - log.error("DPTech run dispose: {}, {}, error:{}", ip, t.getCode(), ex.getMessage()); - } else { - log.debug("Cleanup: {} --> {}:{}", d, t.getReadme(), t.getCode()); - if(v.getResultRetVal() != ErrorCode.ERR_OK.getCode()) { - log.error("DPTech run dispose {} error: {}", ip, v.getResultInfo()); - } - } - }); - } - } - - log.info("----Finish DPTech Start Cleanup Task: {}", ip); - } catch (Exception ex) { - log.error(ex.getMessage()); - log.error("----Error DPTech Start Cleanup Task: {}", ip); - err = ErrorCode.ERR_SYSTEMEXCEPTION; - } - - return new MulReturnType<>(err, null); - } - - /** - * Stop dispose mul return type. - * - * @param ipAddr the ip addr - * @param type the type - * @param devTaskId the dev task id - * @return the mul return type - */ - @Override - public MulReturnType stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) { - ErrorCode err = ErrorCode.ERR_OK; - - if (type != DeviceCapacity.CLEANUP) { - return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); - } - - try { - log.info("++++Begging DPTech Stop Cleanup Task: {}", ipAddr); - // 遍历入口,出口两个方向 - for (int d : new int[]{0, 1}) { - for (DpTechAttackType t : DpTechAttackType.values()) { - CompletableFuture.supplyAsync(() -> cleanTypePort.stopAbnormalTaskForUMC(ipAddr, t.getCode(), d)) - .whenComplete((v, ex) -> { - if (ex != null) { - log.error("DPTech stop dispose: {}, {}, error:{}", ipAddr, t.getCode(), ex.getMessage()); - } else { - log.debug("Stop Cleanup: {} --> {}:{}", d, t.getReadme(), t.getCode()); - if(v.getResultRetVal() != ErrorCode.ERR_OK.getCode()) { - log.error("DPTech stop dispose {} error: {}", ipAddr, v.getResultInfo()); - } - } - }); - } - } - - log.info("----Finish DPTech Stop Cleanup Task: {}", ipAddr); - } catch (Exception ex) { - log.error(ex.getMessage()); - log.error("----Error DPTech Stop Cleanup Task: {}", ipAddr); - err = ErrorCode.ERR_SYSTEMEXCEPTION; - } - - return new MulReturnType<>(err, null); - } - - /** - * Gets all detection object. - * - * @param the type parameter - * @return the all detection object - */ - @Override - @SuppressWarnings("unchecked") - public T getAllDetectionObject() { - try { - return (T) cleanTypePort.getAllDetectionObjectFromUMC().getDetectionObjectDataForService(); - } catch (Exception ex) { - log.error(ex.getMessage()); - return null; - } - } - - /** - * Gets all protection object. - * - * @param the type parameter - * @return the all protection object - */ - @Override - @SuppressWarnings("unchecked") - public T getAllProtectionObject() { - try { - return (T) cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService(); - } catch (Exception ex) { - log.error(ex.getMessage()); - return null; - } - } - - /** - * Gets protect devices. - * - * @return the protect devices - */ - @Override - public String getProtectDevices() { - try { - return cleanTypePort.getAllProtectDevices(); - } catch (Exception ex) { - log.error(ex.getMessage()); - return ""; - } - } - - /** - * Gets detection devices. - * - * @return the detection devices - */ - @Override - public String getDetectionDevices() { - try { - return cleanTypePort.getAllDetectDevices(); - } catch (Exception ex) { - log.error(ex.getMessage()); - return ""; - } - } - - /** - * Gets device clean task status. - * - * @param devTaskId device Task Id. - * @return the task status - */ - @Override - public CleanTaskStatus getCleanTaskStatus(Long devTaskId) { - return CleanTaskStatus.DEVNOTSUPPORT; - } -} - diff --git a/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java b/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java deleted file mode 100644 index 5654df24..00000000 --- a/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java +++ /dev/null @@ -1,281 +0,0 @@ -package com.dispose.dispose.impl; - -import com.dispose.common.CleanTaskStatus; -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.common.Http; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.dispose.po.DeviceInfo; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.haohan.CleanReq; -import com.dispose.pojo.vo.haohan.CleanRsp; -import com.dispose.pojo.vo.haohan.CommonRsp; -import com.dispose.pojo.vo.haohan.StopCleanReq; -import com.dispose.pojo.vo.haohan.CleanTaskStatusRsp; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Hao han. - * - * @author - */ -@Slf4j -public class HaoHanImpl implements DisposeEntryManager { - - private final ObjectMapper objectMapper = new ObjectMapper(); - - private final String deviceAddress; - - /** - * Instantiates a new Hao han. - * - * @param dev the dev - */ - public HaoHanImpl(DisposeDevice dev) { - deviceAddress = String.format(dev.getUrl(), dev.getIpAddr()); - } - - /** - * Run dispose mul return type. - * - * @param ip the ip - * @param type the type - * @param duration the duration - * @return the mul return type - */ - @Override - public MulReturnType runDispose(String ip, DeviceCapacity type, Long duration) { - CleanReq req = CleanReq.builder() - .ip(ip) - .duration(duration) - .orderFrom("China Mobile") - .build(); - - log.info("++++Begging Haohan Start Cleanup Task: {}", ip); - - try { - String ret = Http.postJson(deviceAddress + "/sendTow", - null, - objectMapper.writeValueAsString(req)); - - CleanRsp rsp = objectMapper.readValue(ret, CleanRsp.class); - - if (rsp == null) { - log.error("----Error Haohan start clean {} server return error", ip); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - if (rsp.getState() != ErrorCode.ERR_OK.getCode()) { - log.error("----Error Haohan start clean {} return error: {}, {}", ip, rsp.getState(), rsp.getMsg()); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - log.info("----Finish Haohan Start Cleanup Task: {}", ip); - return new MulReturnType<>(ErrorCode.ERR_OK, rsp.getCleanTaskId()); - } catch (JsonProcessingException e) { - log.error("----Error Haohan Start Cleanup Task: {}", ip); - return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); - } - } - - /** - * Stop dispose mul return type. - * - * @param ipAddr the ip addr - * @param type the type - * @param devTaskId the dev task id - * @return the mul return type - */ - @Override - public MulReturnType stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) { - StopCleanReq req = StopCleanReq.builder() - .cleanTaskId(devTaskId) - .orderFrom("China Mobile") - .build(); - - log.info("++++Begging Haohan Stop Cleanup Task: {}", devTaskId); - - try { - String ret = Http.postJson(deviceAddress + "/delTow", - null, - objectMapper.writeValueAsString(req)); - - CommonRsp rsp = objectMapper.readValue(ret, CommonRsp.class); - - if (rsp == null) { - log.error("----Error Haohan stop task{} server return error", devTaskId); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - log.info("----Finish Haohan Stop Cleanup Task: {}", devTaskId); - return new MulReturnType<>(ErrorCode.ERR_OK, null); - } catch (JsonProcessingException e) { - log.error("----Error Haohan Stop Cleanup Task: {}", devTaskId); - return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); - } - } - - /** - * Gets version. - * - * @return the version - */ - @Override - public String getVersion() { - return "Not Support"; - } - - /** - * Gets device info. - * - * @return the device info - */ - @Override - public DeviceInfo getDeviceInfo() { - // 当前设备接口不支持,返回模拟数据 - return DeviceInfo.builder() - .vendor("HaoHan") - .model("Unknown") - .firmware("Unknown") - .os("Linux Server") - .kernel("Linux") - .arch("x86_64") - .memory(-1) - .freeMemory(-1) - .cpuUsed(-1) - .build(); - } - - /** - * Gets device capacity. - * - * @return the device capacity - */ - @Override - public List getDeviceCapacity() { - List capList = new ArrayList<>(); - - // 保存清洗能力信息 - capList.add(DisposeDeviceCapacity.builder() - // 清洗能力 - .capacity(DeviceCapacity.CLEANUP.getCode()) - .tolFlowCapacity(0) - // IPv4范围 - .protectIpV4(new String[]{""}) - // IPv6范围 - .protectIpV6(new String[]{""}) - .build()); - - return capList; - } - - /** - * Gets device link status. - * - * @return the device link status - */ - @Override - public boolean getDeviceLinkStatus() { - try { - String jsonRequest = "{\"cleanTaskId\":\"-1\"}"; - //"http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow" - Http.postJson(deviceAddress + "cleanTaskFlow", - null, - jsonRequest); - return true; - } catch (Exception ex) { - log.error(ex.getMessage()); - } - - return false; - } - - /** - * Gets all detection object. - * - * @param the type parameter - * @return the all detection object - */ - @Override - public T getAllDetectionObject() { - return null; - } - - /** - * Gets all protection object. - * - * @param the type parameter - * @return the all protection object - */ - @Override - public T getAllProtectionObject() { - return null; - } - - /** - * Gets protect devices. - * - * @return the protect devices - */ - @Override - public String getProtectDevices() { - return null; - } - - /** - * Gets detection devices. - * - * @return the detection devices - */ - @Override - public String getDetectionDevices() { - return null; - } - - /** - * Gets device clean task status. - * - * @param devTaskId device Task Id. - * @return the task status - */ - @Override - public CleanTaskStatus getCleanTaskStatus(Long devTaskId) { - try { - String jsonRequest = String.valueOf(devTaskId); - //"http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState" - String ret = Http.postJson(deviceAddress + "getCleanTaskState", - null, - jsonRequest); - - CleanTaskStatusRsp rsp = objectMapper.readValue(ret, CleanTaskStatusRsp.class); - - if (rsp == null) { - log.error("----Error Haohan get task{} status error", devTaskId); - return CleanTaskStatus.HAOHANERROR; - } - - if (rsp.getState() == 0) { - if (rsp.getCleanTaskState() == 1) { - log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState()); - return CleanTaskStatus.CLEANING; - } - - log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState()); - return CleanTaskStatus.ENDOFCLEANING; - } else { - log.error("----Get task {}, status {}", devTaskId, rsp.getCleanTaskState()); - return CleanTaskStatus.NOTASK; - } - } catch (Exception ex) { - log.error(ex.getMessage()); - return CleanTaskStatus.HAOHANERROR; - } - } -} diff --git a/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java b/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java deleted file mode 100644 index 8664a784..00000000 --- a/src/main/java/com/dispose/dispose/impl/VirtualDeviceImpl.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.dispose.dispose.impl; - -import com.dispose.common.CleanTaskStatus; -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.dispose.po.DeviceInfo; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.po.MulReturnType; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Virtual device. - * - * @author - */ -public class VirtualDeviceImpl implements DisposeEntryManager { - - /** - * Instantiates a new Virtual device. - * - * @param dev the dev - */ - public VirtualDeviceImpl(DisposeDevice dev) { - - } - - /** - * Run dispose mul return type. - * - * @param ip the ip - * @param type the type - * @param duration the duration - * @return the mul return type - */ - @Override - public MulReturnType runDispose(String ip, DeviceCapacity type, Long duration) { - return new MulReturnType<>(ErrorCode.ERR_OK, null); - } - - /** - * Stop dispose mul return type. - * - * @param ipAddr the ip addr - * @param type the type - * @param devTaskId the dev task id - * @return the mul return type - */ - @Override - public MulReturnType stopDispose(String ipAddr, DeviceCapacity type, Long devTaskId) { - return new MulReturnType<>(ErrorCode.ERR_OK, null); - } - - /** - * Gets version. - * - * @return the version - */ - @Override - public String getVersion() { - return "Virtual_Device_1.0.0"; - } - - /** - * Gets device info. - * - * @return the device info - */ - @Override - public DeviceInfo getDeviceInfo() { - return DeviceInfo.builder() - .vendor("Virtual") - .model("Dispose_1000") - .firmware("Unknown") - .os("Unknown") - .kernel("Linux") - .arch("x86_64") - .memory(-1) - .freeMemory(-1) - .cpuUsed(-1) - .build(); - } - - /** - * Gets device capacity. - * - * @return the device capacity - */ - @Override - public List getDeviceCapacity() { - List capList = new ArrayList<>(); - - capList.add(DisposeDeviceCapacity.builder() - .capacity(DeviceCapacity.CLEANUP.getCode()) - .protectIpV4(new String[]{"192.168.3.2-192.168.3.5", "192.168.5.2-192.168.5.10", "192.168.4.2-192.168.4.5"}) - .protectIpV6(new String[]{}) - .tolFlowCapacity(1024) - .build()); - - capList.add(DisposeDeviceCapacity.builder() - .capacity(DeviceCapacity.DETECIVE.getCode()) - .protectIpV4(new String[]{"192.168.2.1", "192.168.2.2"}) - .protectIpV6(new String[]{}) - .tolFlowCapacity(0) - .build()); - - return capList; - } - - /** - * Gets device link status. - * - * @return the device link status - */ - @Override - public boolean getDeviceLinkStatus() { - return GlobalVar.USED_VIRTUAL_DISPOSE_MODE; - } - - /** - * Gets all detection object. - * - * @param the type parameter - * @return the all detection object - */ - @Override - @SuppressWarnings("unchecked") - public T getAllDetectionObject() { - List detectionObjects = new ArrayList<>(); - - detectionObjects.add("192.168.10.12-192.168.10.124"); - return (T) detectionObjects; - } - - /** - * Gets all protection object. - * - * @param the type parameter - * @return the all protection object - */ - @Override - @SuppressWarnings("unchecked") - public T getAllProtectionObject() { - List protectObjects = new ArrayList<>(); - - protectObjects.add("10.10.10.1-10.10.10.100"); - protectObjects.add("172.168.133.12-172.168.133.48"); - return (T) protectObjects; - } - - /** - * Gets detection devices. - * - * @return the detection devices - */ - @Override - public String getDetectionDevices() { - return "192.168.10.11"; - } - - /** - * Gets protect devices. - * - * @return the protect devices - */ - @Override - public String getProtectDevices() { - return "192.168.10.10"; - } - - /** - * Gets device clean task status. - * - * @param devTaskId device Task Id. - * @return the task status - */ - @Override - public CleanTaskStatus getCleanTaskStatus(Long devTaskId) { - return CleanTaskStatus.DEVNOTSUPPORT; - } -} diff --git a/src/main/java/com/dispose/dispose/po/DeviceInfo.java b/src/main/java/com/dispose/dispose/po/DeviceInfo.java deleted file mode 100644 index ca3bc737..00000000 --- a/src/main/java/com/dispose/dispose/po/DeviceInfo.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.dispose.dispose.po; - -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -/** - * The type Device info. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -public class DeviceInfo implements Serializable { - - private static final long serialVersionUID = 1L; - - private String vendor; - private String model; - private String firmware; - private String os; - private String kernel; - private String arch; - private int memory; - private int freeMemory; - private int cpuUsed; - - /** - * Instantiates a new Device info. - * - * @param vendor the vendor - * @param model the model - * @param firmware the firmware - * @param os the os - * @param kernel the kernel - * @param arch the arch - * @param memory the memory - * @param freeMemory the free memory - * @param cpuUsed the cpu used - */ - public DeviceInfo(String vendor, - String model, - String firmware, - String os, - String kernel, - String arch, - int memory, - int freeMemory, - int cpuUsed) { - this.vendor = vendor; - this.model = model; - this.firmware = firmware; - this.os = os; - this.kernel = kernel; - this.arch = arch; - this.memory = memory; - this.freeMemory = freeMemory; - this.cpuUsed = cpuUsed; - } -} diff --git a/src/main/java/com/dispose/exception/GlobalExceptionHandler.java b/src/main/java/com/dispose/exception/GlobalExceptionHandler.java deleted file mode 100644 index 063bdb2a..00000000 --- a/src/main/java/com/dispose/exception/GlobalExceptionHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.dispose.exception; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.po.ReturnStatus; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletRequest; - -/** - * The type Global exception handler. - * - * @author - */ -@ControllerAdvice -@Slf4j -public class GlobalExceptionHandler { - - /** - * Handle exception protocol resp dto. - * - * @param request the request - * @param e the e - * @return the protocol resp dto - */ - @ExceptionHandler(Throwable.class) - @ResponseBody - public ProtocolRespDTO handleException(HttpServletRequest request, Throwable e) { - log.error("进入全局异常处理", e); - ProtocolRespDTO resp = new ProtocolRespDTO(); - ErrorCode err = ErrorCode.ERR_SYSTEMEXCEPTION; - - resp.setVer(ConstValue.Protocol.VERSION); - resp.setCode(err.getHttpCode()); - resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - resp.setTimeStamp(System.currentTimeMillis()); - resp.setMsgContent((new ReturnStatus(err.getCode(), err.getMsg())).toString()); - - return resp; - } - - /** - * Param exception protocol resp dto. - * - * @param request the request - * @param e the e - * @return the protocol resp dto - */ - @ExceptionHandler(Exception.class) - @ResponseBody - public ProtocolRespDTO paramException(HttpServletRequest request, Exception e) { - log.error("进入参数校验异常处理", e); - - ProtocolRespDTO resp = new ProtocolRespDTO(); - ErrorCode err = ErrorCode.ERR_PARAMEXCEPTION; - - resp.setVer(ConstValue.Protocol.VERSION); - resp.setCode(err.getHttpCode()); - resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - resp.setTimeStamp(System.currentTimeMillis()); - resp.setMsgContent((new ReturnStatus(err.getCode(), err.getMsg())).toString()); - - return resp; - } -} diff --git a/src/main/java/com/dispose/interceptor/TokenInterceptor.java b/src/main/java/com/dispose/interceptor/TokenInterceptor.java deleted file mode 100644 index 92aabb2c..00000000 --- a/src/main/java/com/dispose/interceptor/TokenInterceptor.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.dispose.interceptor; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.service.UserAccountService; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.servlet.HandlerInterceptor; -import reactor.util.annotation.NonNull; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * The type Token interceptor. - * - * @author - */ -@Slf4j -public class TokenInterceptor implements HandlerInterceptor { - @Resource - private UserAccountService userAccountService; - - /** - * Pre handle boolean. - * - * @param request the request - * @param response the response - * @param handler the handler - * @return the boolean - * @throws Exception the exception - */ - @Override - public boolean preHandle(HttpServletRequest request, - @NonNull HttpServletResponse response, - @NonNull Object handler) throws Exception { - // 提取header中的Authorization字段里面的token值 - String token = request.getHeader("Authorization"); - - if (token != null && token.length() > 0) { - token = token.replaceFirst(GlobalVar.STRING_HTTP_AUTH_HEAD, ""); - ErrorCode err = userAccountService.authTokenCheck(token); - // 判断token是否合法 - if (err != ErrorCode.ERR_OK) { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application/json;charset=UTF-8"); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - response.getWriter().write(new ObjectMapper().writeValueAsString(ProtocolRespDTO.result(err))); - log.error("Http request token [{}] is error: {}", token, err); - return false; - } - } else { - // 缺少必要的认证头部 - response.setCharacterEncoding("UTF-8"); - response.setContentType("application/json;charset=UTF-8"); - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.getWriter().write(new ObjectMapper().writeValueAsString(ProtocolRespDTO.result(ErrorCode.ERR_MISSAUTHHEAD))); - log.error("Http request head miss \"Authorization\" item"); - return false; - } - - return true; - } -} diff --git a/src/main/java/com/dispose/manager/TaskCacheManager.java b/src/main/java/com/dispose/manager/TaskCacheManager.java deleted file mode 100644 index 7de38e2f..00000000 --- a/src/main/java/com/dispose/manager/TaskCacheManager.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.dispose.manager; - -import com.dispose.common.ErrorCode; -import com.dispose.pojo.vo.common.TaskInfoDetail; - -import java.util.List; - -/** - * The interface Task cache manager. - * - * @author - */ -public interface TaskCacheManager { - /** - * Add task error code. - * - * @param taskData the task data - * @return the error code - */ - ErrorCode addTask(TaskInfoDetail taskData); - - /** - * Gets task by id. - * - * @param id the id - * @return the task by id - */ - TaskInfoDetail getTaskById(Long id); - - /** - * Gets all task. - * - * @return the all task - */ - List getAllRunningTask(); - - /** - * Remove task. - * - * @param id the id - */ - void removeTask(Long id); - - /** - * Upgrade task status error code. - * - * @param id the id - * @param status the status - * @return the error code - */ - ErrorCode upgradeTaskStatus(Long id, int status); -} diff --git a/src/main/java/com/dispose/manager/impl/TaskCacheManagerImpl.java b/src/main/java/com/dispose/manager/impl/TaskCacheManagerImpl.java deleted file mode 100644 index 7b8395d9..00000000 --- a/src/main/java/com/dispose/manager/impl/TaskCacheManagerImpl.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.dispose.manager.impl; - -import com.dispose.common.ErrorCode; -import com.dispose.manager.TaskCacheManager; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The type Task cache manager. - * - * @author - */ -@Component -@Slf4j -public class TaskCacheManagerImpl implements TaskCacheManager { - private final ConcurrentHashMap taskCacheMap = new ConcurrentHashMap<>(); - - @Resource - private DisposeTaskMapper disposeTaskMapper; - - - /** - * Gets all task. - * - * @return the all task - */ - @Override - public List getAllRunningTask() { - return new ArrayList<>(taskCacheMap.values()); - } - - /** - * Gets task by id. - * - * @param id the id - * @return the task by id - */ - @Override - public TaskInfoDetail getTaskById(Long id) { - if (taskCacheMap.containsKey(id)) { - return taskCacheMap.get(id); - } - - return null; - } - - /** - * Add task error code. - * - * @param taskData the task data - * @return the error code - */ - @Override - public ErrorCode addTask(TaskInfoDetail taskData) { - // 输入参数验证 - if (taskData == null - || taskData.getDisposeIp() == null - || taskData.getDisposeIp().length() == 0 - || taskData.getId() == -1) { - if (taskData != null) { - log.error("Add task error: taskId:{}, devId:{}, disposeIp:{}", taskData.getId(), taskData.getDeviceId(), taskData.getDisposeIp()); - } else { - log.error("No Task info detail"); - } - return ErrorCode.ERR_INPUTMISS; - } - - // 判断任务是否已经存在 - if (taskCacheMap.containsKey(taskData.getId())) { - log.error("Task info detail already existed:taskId:{}, devId:{}, disposeIp:{}", - taskData.getId(), taskData.getDeviceId(), taskData.getDisposeIp()); - return ErrorCode.ERR_DEVICEEXISTS; - } - - // 添加到Map缓存中 - // 保留字段 - taskData.setRetryTimes(0); - taskCacheMap.put(taskData.getId(), taskData); - return ErrorCode.ERR_OK; - } - - /** - * Remove task. - * - * @param id the id - */ - @Override - public void removeTask(Long id) { - taskCacheMap.remove(id); - } - - /** - * Upgrade task status error code. - * - * @param id the id - * @param status the status - * @return the error code - */ - @Override - public ErrorCode upgradeTaskStatus(Long id, int status) { - if (!taskCacheMap.containsKey(id)) { - log.error("No such task to update the taskStatus: taskId:{}", id); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - // 更新状态 - taskCacheMap.get(id).setCurrentStatus(status); - - disposeTaskMapper.changeTaskCurrentStatus(id, status); - - return ErrorCode.ERR_OK; - } -} diff --git a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java deleted file mode 100644 index f5a40841..00000000 --- a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java +++ /dev/null @@ -1,288 +0,0 @@ -package com.dispose.manager.impl; - -import cn.hutool.core.convert.Convert; -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.config.DisposeConfigure; -import com.dispose.manager.UserAccountCacheManager; -import com.dispose.pojo.po.UserAccountCache; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Optional; -import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The type User account cache manager. - * - * @author - */ -@Component -@Slf4j -public class UserAccountCacheManagerImpl implements UserAccountCacheManager { - private static final Random RANDOM_GEN = new Random(System.currentTimeMillis()); - private final ConcurrentHashMap userAccountCache = new ConcurrentHashMap<>(); - @Resource - private DisposeConfigure disposeConfigure; - @Resource - private ObjectMapper objectMapper; - - /** - * Verify permission error code. - * - * @param token the token - * @return the error code - */ - @Override - public ErrorCode verifyPermission(String token) { - if (String.valueOf(false).equals(disposeConfigure.getCheckAdminPermission())) { - return ErrorCode.ERR_OK; - } - - String username = getUsernameByToken(token); - - if (username == null || username.length() == 0) { - log.error("User {} not logged in", username); - return ErrorCode.ERR_LOGOUT; - } - - return ErrorCode.ERR_OK; - } - - /** - * Gets username by token. - * - * @param token the token - * @return the username by token - */ - @Override - public String getUsernameByToken(String token) { - if (userAccountCache.containsKey(token)) { - return userAccountCache.get(token).getUsername(); - } - - log.error("according to token [{}] not found username in cache", token); - return null; - } - - /** - * Verify token error code. - * - * @param token the token - * @return the error code - */ - @Override - public ErrorCode verifyToken(String token) { - // 判断当前token是否存在,如果不存在则用户没有登录 - if (!userAccountCache.containsKey(token)) { - return ErrorCode.ERR_LOGOUT; - } else { - UserAccountCache uc = userAccountCache.get(token); - - // 根据token提取用户信息,判断当前token是否超时 - if ((System.currentTimeMillis() - uc.getLastAccess()) - >= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) { - log.error("User {} token timeout before {}", uc.getUsername(), uc.getLastAccess()); - return ErrorCode.ERR_TOKENTIMEOUT; - } else { - // 更新用户最后一次访问时间戳 - uc.setLastAccess(System.currentTimeMillis()); - } - - return ErrorCode.ERR_OK; - } - } - - /** - * Verify user login error code. - * - * @param username the username - * @param token the token - * @return the error code - */ - @Override - public ErrorCode verifyUserLogin(String username, String token) { - // 缓存中通过用户名查找当前用户 - Optional findRet = userAccountCache.values().stream() - .filter(userAccountCache -> username.equals(userAccountCache.getUsername())) - .findFirst(); - - // 用户不存在 - if (!findRet.isPresent()) { - log.error("User {} not exists", username); - return ErrorCode.ERR_LOGOUT; - } - - UserAccountCache uc = findRet.get(); - - // 如果token为空说明用户没有登录 - if (uc.getToken().length() == 0) { - log.error("User {} token is empty", username); - return ErrorCode.ERR_LOGOUT; - } - - // 判断用户访问时间间隔是否超时 - if ((System.currentTimeMillis() - uc.getLastAccess()) - >= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) { - log.error("User {} token is timeout: current {}, last access {}, timeout setting {}", - username, System.currentTimeMillis(), uc.getLastAccess(), ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS); - return ErrorCode.ERR_TOKENTIMEOUT; - } - - // 判断token是否正确 - if (!uc.getToken().equals(token)) { - log.error("User {} token {} is error", username, token); - return ErrorCode.ERR_TOKENNOTFOUND; - } - - return ErrorCode.ERR_OK; - } - - /** - * Gets cache user. - * - * @return the cache user - * @throws JsonProcessingException the json processing exception - */ - @Override - public String getCacheUser() throws JsonProcessingException { - return objectMapper.writeValueAsString(userAccountCache); - } - - /** - * Clean user token. - * - * @param username the username - */ - @Override - public void cleanUserToken(String username) { - // 根据用户名在缓存中查找用户 - Optional findRet = userAccountCache.values().stream() - .filter(userAccountCache -> username.equals(userAccountCache.getUsername())) - .findFirst(); - - if (findRet.isPresent()) { - UserAccountCache uc = findRet.get(); - // 缓存中删除当前用户 - userAccountCache.remove(uc.getToken()); - } - } - - /** - * Gets usr pwd err times. - * - * @param username the username - * @return the usr pwd err times - */ - @Override - public int getUsrPwdErrTimes(String username) { - Optional findRet = userAccountCache.values().stream() - .filter(userAccountCache -> username.equals(userAccountCache.getUsername())) - .findFirst(); - - if (findRet.isPresent()) { - UserAccountCache uc = findRet.get(); - return uc.getPwdErrTimes(); - } else { - // 缓存不存在,说明用户未登录过或者已经过期,创建一个新用户缓存 - UserAccountCache uc = UserAccountCache.builder() - .username(username) - .token("") - .lastAccess(System.currentTimeMillis()) - .pwdErrTimes(0) - .build(); - - userAccountCache.put(uc.getToken(), uc); - return 0; - } - } - - /** - * Sets user pwd err times. - * - * @param username the username - * @param errTimes the err times - */ - @Override - public void setUserPwdErrTimes(String username, Integer errTimes) { - Optional findRet = userAccountCache.values().stream() - .filter(userAccountCache -> username.equals(userAccountCache.getUsername())) - .findFirst(); - - if (findRet.isPresent()) { - UserAccountCache uc = findRet.get(); - uc.setPwdErrTimes(Math.abs(errTimes)); - } - } - - /** - * Gets user token. - * - * @param username the username - * @return the user token - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @Override - public String getUserToken(String username) throws NoSuchAlgorithmException { - UserAccountCache uc; - - // 根据用户名在缓存中查找用户 - Optional findRet = userAccountCache.values().stream() - .filter(userAccountCache -> username.equals(userAccountCache.getUsername())) - .findFirst(); - - if (findRet.isPresent()) { - uc = findRet.get(); - - // token过期获取以前没有token,创建一个新token - if ((System.currentTimeMillis() - uc.getLastAccess()) - >= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS - || uc.getToken().length() == 0) { - // 移除过期的项 - userAccountCache.remove(uc.getToken()); - // 更新token,访问时间 - uc.setToken(createUserToken(username)); - // 重新添加到缓存中 - userAccountCache.put(uc.getToken(), uc); - log.info("Refresh {} Token:{}", username, uc.getToken()); - } else { - log.info("Get {} Token:{}", username, uc.getToken()); - } - - uc.setLastAccess(System.currentTimeMillis()); - } else { - // 用户不存在说明没有登陆过,创建一个新的用户缓存 - uc = UserAccountCache.builder() - .username(username) - .token(createUserToken(username)) - .pwdErrTimes(0) - .lastAccess(System.currentTimeMillis()).build(); - - userAccountCache.put(uc.getToken(), uc); - - log.info("Create {} Token:{}", username, uc.getToken()); - - } - return uc.getToken(); - } - - private String createUserToken(String username) throws NoSuchAlgorithmException { - // 获取指定摘要算法的messageDigest对象 - MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); - - String tokenKey = username + - Convert.toStr(RANDOM_GEN.nextInt()) + - Convert.toStr(System.currentTimeMillis()); - // 调用digest方法,进行加密操作 - byte[] cipherBytes = messageDigest.digest(tokenKey.getBytes()); - - return Hex.encodeHexString(cipherBytes); - } -} diff --git a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java deleted file mode 100644 index 8758d78c..00000000 --- a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.dispose.mapper; - -import com.dispose.pojo.entity.DisposeDevice; -import tk.mybatis.mapper.common.Mapper; -import tk.mybatis.mapper.common.MySqlMapper; - -/** - * The interface Dispose device mapper. - * - * @author - */ -public interface DisposeDeviceMapper extends Mapper, MySqlMapper { - /** - * Add new dispose device. - * - * @param dev the dev - */ - void addNewDisposeDevice(DisposeDevice dev); - - /** - * Is device exists by ip int. - * - * @param ipAddr the ip addr - * @return the int - */ - int isDeviceExistsByIp(String ipAddr); - - /** - * Is device exists by id int. - * - * @param id the id - * @return the int - */ - int isDeviceExistsById(Long id); - - /** - * Gets device by ip. - * - * @param ipAddr the ip addr - * @return the device by ip - */ - DisposeDevice getDeviceByIp(String ipAddr); - - /** - * Gets device by id. - * - * @param id the id - * @return the device by id - */ - DisposeDevice getDeviceById(Long id); - - /** - * Del dispose device by ip. - * - * @param ipAddr the ip addr - */ - void delDisposeDeviceByIp(String ipAddr); -} diff --git a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java deleted file mode 100644 index 6d20cb20..00000000 --- a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.dispose.mapper; - -import com.dispose.pojo.vo.common.TaskInfoDetail; -import org.apache.ibatis.annotations.Param; -import tk.mybatis.mapper.common.IdsMapper; -import tk.mybatis.mapper.common.Mapper; -import tk.mybatis.mapper.common.MySqlMapper; - -import java.util.List; - -/** - * The interface Dispose task mapper. - * - * @author - */ -public interface DisposeTaskMapper extends Mapper, - IdsMapper, MySqlMapper { - - /** - * Add new task. - * - * @param taskInfo the task info - */ - void addNewTask(TaskInfoDetail taskInfo); - - /** - * Remove task by id. - * - * @param id the id - */ - void removeTaskById(Long id); - - /** - * Change task current status. - * - * @param id the id - * @param status the status - */ - void changeTaskCurrentStatus(@Param("id") Long id, - @Param("status") int status); - - /** - * Gets task current status. - * - * @param id the id - * @return the task current status - */ - int getTaskCurrentStatus(Long id); - - /** - * Gets task info by id. - * - * @param id the id - * @return the task info by id - */ - TaskInfoDetail getTaskById(Long id); - - /** - * Gets all task by dispose ip. - * - * @param ipAddr the ip addr - * @return the all task by dispose ip - */ - List getAllTaskByDisposeIp(@Param("ipAddr") String ipAddr); - - /** - * Gets all task by node dev id. - * - * @param devId the dev id - * @return the all task by node dev id - */ - List getAllTaskByNodeDevId(Long devId); - - /** - * Gets node all task by user id. - * - * @param userId the user id - * @return the node all task by user id - */ - List getNodeAllTaskByUserId(Long userId); - - /** - * Gets node task by ip and status. - * - * @param devId the dev id - * @param ipAddr the ip addr - * @param status the status - * @return the node task by ip and status - */ - List getNodeTaskByIpAndStatus(@Param("devId") Long devId, - @Param("ipAddr") String ipAddr, - @Param("status") int status); - - /** - * Gets all task by status. - * - * @param status the status - * @return the all task by status - */ - List getAllTaskByStatus(@Param("status") int status); - - /** - * Gets task by task info. - * - * @param devId the dev id - * @param userId the user id - * @param ipAddr the ip addr - * @param type the type - * @return the task by task info - */ - List getTaskByTaskDetail( - @Param("devId") Long devId, - @Param("userId") Long userId, - @Param("ipAddr") String ipAddr, - @Param("type") int type - ); - - /** - * Gets all task by type. - * - * @param type the type - * @return the all task by type - */ - List getAllTaskByType(@Param("type") int type); -} diff --git a/src/main/java/com/dispose/mapper/TaskInfoMapper.java b/src/main/java/com/dispose/mapper/TaskInfoMapper.java deleted file mode 100644 index 0bb2ec0a..00000000 --- a/src/main/java/com/dispose/mapper/TaskInfoMapper.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.dispose.mapper; - - -import com.dispose.pojo.vo.common.TaskInfo; -import org.apache.ibatis.annotations.Param; -import tk.mybatis.mapper.common.Mapper; -import tk.mybatis.mapper.common.MySqlMapper; - -import java.util.List; - -/** - * The interface Task info mapper. - * - * @author - */ -public interface TaskInfoMapper extends Mapper, MySqlMapper { - /** - * Add new task info. - * - * @param taskId the task id - * @param deviceId the device id - * @param externId the extern id - * @param status the status - */ - void addNewTaskInfo(@Param("taskId") Long taskId, - @Param("deviceId") Long deviceId, - @Param("externId") Long externId, - @Param("status") Long status); - - /** - * Gets task info. - * - * @param taskId the task id - * @param deviceId the device id - * @return the task info - */ - TaskInfo getTaskInfo(@Param("taskId") Long taskId, - @Param("deviceId") Long deviceId); - - /** - * Gets task info by task id. - * - * @param taskId the task id - * @return the task info by task id - */ - List getTaskInfoByTaskId(Long taskId); - - /** - * Change task info status. - * - * @param id the id - * @param status the status - */ - void changeTaskInfoStatus(@Param("id") Long id, - @Param("status") Long status); - - /** - * Gets task info current status. - * - * @param id the id - * @return the task info current status - */ - int getTaskInfoCurrentStatus(Long id); - - /** - * Remove task by id. - * - * @param id the id - */ - void removeTaskInfoById(Long id); -} diff --git a/src/main/java/com/dispose/pojo/dto/BaseProtocolDTO.java b/src/main/java/com/dispose/pojo/dto/BaseProtocolDTO.java deleted file mode 100644 index 0ebd9075..00000000 --- a/src/main/java/com/dispose/pojo/dto/BaseProtocolDTO.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.dispose.pojo.dto; - -import com.dispose.common.ConstValue; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Base protocol dto. - * - * @author - */ -@Data -@NoArgsConstructor -@ApiModel("通信协议实体") -@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "msgContent"}) -public abstract class BaseProtocolDTO { - @ApiModelProperty(value = "协议版本号", required = true, example = "1") - private Integer ver; - - @ApiModelProperty(value = "msgContent字段内容编码格式:\n" + - "0:无编码格式,普通字符串\n" + - "1:base64编码格式\n" + - "2:采用AES加密后的base64编码格式\n", required = true, - allowableValues = "0, 1, 2", - example = "0") - private Integer cryptoType; - - @ApiModelProperty(value = "当前UTC时间戳", required = true, example = "1526625689000") - private Long timeStamp; - - @ApiModelProperty(value = "协议详细内容,Json字符串格式。\n" + - "保存该cmdId命令相关的详细内容,\n" + - "具体每个cmdId命令的详细内容参看对应的命令协议定义", - example = "{}") - private String msgContent; - - /** - * Is request timeout boolean. - * - * @return the boolean - */ - @JsonIgnore - public Boolean isRequestTimeout() { - - if (!ConstValue.GlobalConfigure.IS_SKIP_TIMEOUT_CHECK) { - Long current = System.currentTimeMillis(); - long timeDiff = current - this.timeStamp; - - return timeDiff > 0 && timeDiff <= 3000; - } - - return false; - } -} diff --git a/src/main/java/com/dispose/pojo/dto/ProtocolReqDTO.java b/src/main/java/com/dispose/pojo/dto/ProtocolReqDTO.java deleted file mode 100644 index 4694e701..00000000 --- a/src/main/java/com/dispose/pojo/dto/ProtocolReqDTO.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.dispose.pojo.dto; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.NoArgsConstructor; -import lombok.ToString; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpHeaders; - -import java.util.Objects; - -/** - * The type Protocol req dto. - * - * @author - */ -@NoArgsConstructor -@ToString -@Slf4j -public class ProtocolReqDTO extends BaseProtocolDTO { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private static String token = ""; - - /** - * Gets request object. - * - * @param the type parameter - * @param objType the obj type - * @return the request object - * @throws JsonProcessingException the json processing exception - */ - public T getRequestObject(Class objType) throws JsonProcessingException { - // 返回协议 MsgContent 字段内容 - return OBJECT_MAPPER.readValue(this.getMsgContent(), objType); - } - - /** - * Gets auth token. - * - * @return the auth token - */ - @JsonIgnore - public String getAuthToken() { - return ProtocolReqDTO.token; - } - - /** - * Verify request error code. - * - * @param headers the headers - * @return the error code - */ - public ErrorCode verifyRequest(HttpHeaders headers) { - - ErrorCode err = verifyRequest(); - - if (err != ErrorCode.ERR_OK) { - log.error("headers error, error:{}", err.getMsg()); - return err; - } - - // 是否有必要的HTTP Head字段 - if (headers == null) { - log.error("Http request is missing authentication header"); - return ErrorCode.ERR_MISSAUTHHEAD; - } - - try { - String authString = Objects.requireNonNull(headers.get("Authorization")).get(0); - - if (authString.length() == 0 || !authString.startsWith(GlobalVar.STRING_HTTP_AUTH_HEAD)) { - log.error("Input Authorization header error: [{}]", authString); - return ErrorCode.ERR_PARAMEXCEPTION; - } - // 保持当前请求token内容 - ProtocolReqDTO.token = authString.replaceFirst(GlobalVar.STRING_HTTP_AUTH_HEAD, ""); - } catch (Exception ex) { - log.error(ex.getMessage()); - return ErrorCode.ERR_MISSAUTHHEAD; - } - - return ErrorCode.ERR_OK; - } - - /** - * Verify request error code. - * - * @return the error code - */ - public ErrorCode verifyRequest() { - - if (this.getVer() == null || this.getCryptoType() == null || this.getTimeStamp() == null) { - log.error("request params error: ver:{}, cryptoType:{}, TimeStamp:{}", this.getVer(), this.getCryptoType(), this.getTimeStamp()); - return ErrorCode.ERR_PARAMEXCEPTION; - } - - // 校验版本 - if (this.getVer() < ConstValue.Protocol.VERSION) { - log.error("version error: ver:{}", this.getVer()); - return ErrorCode.ERR_VERSION; - } - - // 校验时间错 - if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT - && Math.abs(System.currentTimeMillis() - this.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) { - log.error("request timeout: diffTimeMillis:{}", Math.abs(System.currentTimeMillis() - this.getTimeStamp())); - return ErrorCode.ERR_REQUESTTIMEOUT; - } - - return ErrorCode.ERR_OK; - } -} diff --git a/src/main/java/com/dispose/pojo/dto/ProtocolRespDTO.java b/src/main/java/com/dispose/pojo/dto/ProtocolRespDTO.java deleted file mode 100644 index d8541113..00000000 --- a/src/main/java/com/dispose/pojo/dto/ProtocolRespDTO.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.dispose.pojo.dto; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.pojo.po.ReturnStatus; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Protocol resp dto. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "code", "msgContent"}) -public class ProtocolRespDTO extends BaseProtocolDTO { - - @ApiModelProperty(value = "服务器返回状态码", - example = "200") - private Integer code; - - private static String getObjectJson(Object obj) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - - return objectMapper.writeValueAsString(obj); - } - - private static String getObjectJson(Object obj, Class objType) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - - return objectMapper.writerWithView(objType).writeValueAsString(obj); - } - - /** - * Result protocol resp dto. - * - * @param err the err - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - public static ProtocolRespDTO result(ErrorCode err) throws JsonProcessingException { - ProtocolRespDTO resp = new ProtocolRespDTO(); - - resp.setVer(ConstValue.Protocol.VERSION); - resp.setCode(err.getHttpCode()); - resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - resp.setTimeStamp(System.currentTimeMillis()); - resp.setMsgContent(getObjectJson(new ReturnStatus(err.getCode(), err.getMsg()))); - - return resp; - } - - /** - * Result protocol resp dto. - * - * @param err the err - * @param respMsg the resp msg - * @return the protocol resp dto - */ - public static ProtocolRespDTO result(ErrorCode err, String respMsg) { - return result(err, respMsg, ConstValue.Protocol.CRYPTO_NONE); - } - - /** - * Result protocol resp dto. - * - * @param err the err - * @param obj the obj - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - public static ProtocolRespDTO result(ErrorCode err, Object obj) throws JsonProcessingException { - return result(err, getObjectJson(obj), ConstValue.Protocol.CRYPTO_NONE); - } - - /** - * Result protocol resp dto. - * - * @param the type parameter - * @param err the err - * @param obj the obj - * @param objType the obj type - * @return the protocol resp dto - * @throws JsonProcessingException the json processing exception - */ - public static ProtocolRespDTO result(ErrorCode err, Object obj, Class objType) throws JsonProcessingException { - return result(err, getObjectJson(obj, objType), ConstValue.Protocol.CRYPTO_NONE); - } - - /** - * Result protocol resp dto. - * - * @param err the err - * @param respMsg the resp msg - * @param crypto the crypto - * @return the protocol resp dto - */ - public static ProtocolRespDTO result(ErrorCode err, String respMsg, Integer crypto) { - ProtocolRespDTO resp = new ProtocolRespDTO(); - - resp.setVer(ConstValue.Protocol.VERSION); - resp.setCode(err.getHttpCode()); - resp.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - resp.setTimeStamp(System.currentTimeMillis()); - resp.setMsgContent(respMsg); - - return resp; - } -} diff --git a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java b/src/main/java/com/dispose/pojo/entity/DisposeDevice.java deleted file mode 100644 index 03031eed..00000000 --- a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.dispose.pojo.entity; - -import com.dispose.dispose.po.DeviceInfo; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import tk.mybatis.mapper.annotation.KeySql; -import tk.mybatis.mapper.annotation.NameStyle; -import tk.mybatis.mapper.code.Style; - -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; -import java.io.Serializable; -import java.util.List; - -/** - * The type Dispose device. - * - * @author - */ -@Getter -@Setter -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -@Table(name = "dispose_device") -@NameStyle(Style.normal) -public class DisposeDevice implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @KeySql(useGeneratedKeys = true) - private Long id; - - private String ipAddr; - - private Integer type; - - private Integer areaCode; - - private String name; - - private String manufacturer; - - private String model; - - private String version; - - private String userName; - - private String password; - - private String url; - - private String readme; - - private Integer status; - - @Transient - private Integer linkStatus; - - @Transient - private List devCaps; - - @Transient - private DeviceInfo devInfo; -} diff --git a/src/main/java/com/dispose/pojo/po/DisposeDeviceCapacity.java b/src/main/java/com/dispose/pojo/po/DisposeDeviceCapacity.java deleted file mode 100644 index 705c4c02..00000000 --- a/src/main/java/com/dispose/pojo/po/DisposeDeviceCapacity.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.dispose.pojo.po; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import java.io.Serializable; - -/** - * The type Dispose device capacity. - * - * @author - */ -@Getter -@Setter -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class DisposeDeviceCapacity implements Serializable { - - private static final long serialVersionUID = 1L; - - private Integer capacity; - - private Integer tolFlowCapacity; - - private String[] protectIpV4; - - private String[] protectIpV6; -} diff --git a/src/main/java/com/dispose/pojo/po/NewNodeInfo.java b/src/main/java/com/dispose/pojo/po/NewNodeInfo.java deleted file mode 100644 index 593a890e..00000000 --- a/src/main/java/com/dispose/pojo/po/NewNodeInfo.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.dispose.pojo.po; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type New node info. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class NewNodeInfo { - private String id; - private Integer type; - private String ipAddr; - private Integer areaCode; - private String name; - private String manufacturer; - private String model; - private String userName; - private String password; - private String url; - private String version; - private String readme; -} diff --git a/src/main/java/com/dispose/pojo/po/ReturnStatus.java b/src/main/java/com/dispose/pojo/po/ReturnStatus.java deleted file mode 100644 index d78c0b0f..00000000 --- a/src/main/java/com/dispose/pojo/po/ReturnStatus.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.dispose.pojo.po; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Return status. - * - * @author - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class ReturnStatus { - private Integer status; - private String message; - - /** - * To string string. - * - * @return the string - */ - @Override - public String toString() { - return "{\"status\":" + status + ", \"message\":\"" + message + "\"}"; - } -} diff --git a/src/main/java/com/dispose/pojo/po/UserAccountCache.java b/src/main/java/com/dispose/pojo/po/UserAccountCache.java deleted file mode 100644 index ab036bde..00000000 --- a/src/main/java/com/dispose/pojo/po/UserAccountCache.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.dispose.pojo.po; - -import lombok.Builder; -import lombok.Data; - -/** - * The type User account cache. - * - * @author - */ -@Data -@Builder -public class UserAccountCache { - private String username; - private String token; - private Long lastAccess; - private Integer pwdErrTimes; -} diff --git a/src/main/java/com/dispose/pojo/vo/auth/LoginReq.java b/src/main/java/com/dispose/pojo/vo/auth/LoginReq.java deleted file mode 100644 index f4481dbf..00000000 --- a/src/main/java/com/dispose/pojo/vo/auth/LoginReq.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dispose.pojo.vo.auth; - - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Login req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class LoginReq { - private String userName; - private String password; -} diff --git a/src/main/java/com/dispose/pojo/vo/auth/LoginRsp.java b/src/main/java/com/dispose/pojo/vo/auth/LoginRsp.java deleted file mode 100644 index d9acece2..00000000 --- a/src/main/java/com/dispose/pojo/vo/auth/LoginRsp.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.dispose.pojo.vo.auth; - -import com.dispose.pojo.po.ReturnStatus; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Login rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"}) -public class LoginRsp extends ReturnStatus { - private String userName; - private String token; - private Long logTime; - private Long expireTime; -} diff --git a/src/main/java/com/dispose/pojo/vo/auth/LogoutRsp.java b/src/main/java/com/dispose/pojo/vo/auth/LogoutRsp.java deleted file mode 100644 index feecfd6c..00000000 --- a/src/main/java/com/dispose/pojo/vo/auth/LogoutRsp.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dispose.pojo.vo.auth; - -import com.dispose.pojo.po.ReturnStatus; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Logout rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"}) -public class LogoutRsp extends ReturnStatus { - private String userName; -} diff --git a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java b/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java deleted file mode 100644 index 00dff080..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.dispose.pojo.vo.common; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonView; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -/** - * The type Dispose capacity. - * - * @author - */ -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class DisposeCapacity { - @JsonView(BaseView.class) - private Integer type; - @JsonView(DependIpView.class) - private String disposeIp; - @JsonView(CapacityView.class) - private Integer tolCapacity; - @JsonView(CapacityView.class) - private Integer usedCapacity; - - /** - * The interface Base view. - * - * @author - */ - public interface BaseView { - } - - /** - * The interface Capacity view. - * - * @author - */ - public interface CapacityView extends BaseView { - } - - /** - * The interface Depend ip view. - * - * @author - */ - public interface DependIpView extends BaseView { - } -} diff --git a/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java b/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java deleted file mode 100644 index 1140367e..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.dispose.pojo.vo.common; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * The type Id array req. - * - * @author - */ -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class IDArrayReq { - private String[] id; - private String[] taskId; - - public void setId(String[] id) { - List idList = Arrays.asList(id); - - if (idList.contains(null)) { - this.id = null; - } else if (idList.contains("")) { - this.id = new String[]{""}; - } else { - Map ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); - System.out.println(ret); - - List keyList = new ArrayList<>(ret.keySet()); - this.id = keyList.toArray(new String[0]); - } - } - - public void setTaskId(String[] taskId) { - List idList = Arrays.asList(taskId); - - if (idList.contains(null)) { - this.taskId = null; - } else if (idList.contains("")) { - this.taskId = new String[]{""}; - } else { - Map ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); - System.out.println(ret); - - List keyList = new ArrayList<>(ret.keySet()); - this.taskId = keyList.toArray(new String[0]); - } - } -} diff --git a/src/main/java/com/dispose/pojo/vo/common/IDReturnStatus.java b/src/main/java/com/dispose/pojo/vo/common/IDReturnStatus.java deleted file mode 100644 index 97ba4412..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/IDReturnStatus.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.dispose.pojo.vo.common; - -import com.dispose.pojo.po.ReturnStatus; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Id return status. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"id", "devId", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class IDReturnStatus extends ReturnStatus { - private String id; - private String devId; -} diff --git a/src/main/java/com/dispose/pojo/vo/common/TaskInfo.java b/src/main/java/com/dispose/pojo/vo/common/TaskInfo.java deleted file mode 100644 index af3c49ed..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/TaskInfo.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.dispose.pojo.vo.common; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import tk.mybatis.mapper.annotation.NameStyle; -import tk.mybatis.mapper.code.Style; - -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * The type Task info. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "task_info") -@NameStyle(Style.normal) -public class TaskInfo { - private static final long serialVersionUID = 1L; - - @Id - private Long id; - private Long taskId; - private Long deviceId; - private String beginTime; - private String endTime; - private Long externId; - private Long status; -} diff --git a/src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java b/src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java deleted file mode 100644 index 912e4dd1..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.dispose.pojo.vo.common; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Task info data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"id", "taskId", "currentStatus", "type", "disposeIp", "startTime", "disposeTime", - "flowDirection", "attackType", "flowBandWidth", "flowAttack", "flowClean", "leftTime", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class TaskInfoData extends IDReturnStatus { - private String taskId; - private Integer type; - private String disposeIp; - private Integer leftTime; - private Integer startTime; - private Integer disposeTime; - private Integer flowDirection; - private Integer[] attackType; - private Integer flowBandWidth; - - private Integer flowAttack; - - private Integer flowClean; - - private Integer currentStatus; -} diff --git a/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java b/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java deleted file mode 100644 index f17bf900..00000000 --- a/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.dispose.pojo.vo.common; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import tk.mybatis.mapper.annotation.NameStyle; -import tk.mybatis.mapper.code.Style; - -import javax.persistence.Id; -import javax.persistence.Table; -import java.io.Serializable; - -/** - * The type Task info detail. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "dispose_task") -@NameStyle(Style.normal) -public class TaskInfoDetail implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - private Long id; - private Long deviceId; - private Long accountId; - private Integer type; - private String disposeIp; - private String createTime; - private String planEndTime; - private String endTime; - private Integer flowDirection; - private String attackType; - private Integer flowBandWidth; - private Integer currentStatus; - - private int retryTimes; -} diff --git a/src/main/java/com/dispose/pojo/vo/device/AddNodeReq.java b/src/main/java/com/dispose/pojo/vo/device/AddNodeReq.java deleted file mode 100644 index 05ed4145..00000000 --- a/src/main/java/com/dispose/pojo/vo/device/AddNodeReq.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dispose.pojo.vo.device; - -import com.dispose.pojo.po.NewNodeInfo; -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Add node req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class AddNodeReq { - private List items; -} diff --git a/src/main/java/com/dispose/pojo/vo/device/AddNodeRetData.java b/src/main/java/com/dispose/pojo/vo/device/AddNodeRetData.java deleted file mode 100644 index 76169d59..00000000 --- a/src/main/java/com/dispose/pojo/vo/device/AddNodeRetData.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.dispose.pojo.vo.device; - -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Add node ret data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@JsonPropertyOrder({"id", "ipAddr", "devId", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class AddNodeRetData extends IDReturnStatus { - private String ipAddr; -} diff --git a/src/main/java/com/dispose/pojo/vo/device/AddNodeRsp.java b/src/main/java/com/dispose/pojo/vo/device/AddNodeRsp.java deleted file mode 100644 index f2f3b203..00000000 --- a/src/main/java/com/dispose/pojo/vo/device/AddNodeRsp.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.dispose.pojo.vo.device; - - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Add node rsp. - * - * @author - */ -@Data -@JsonInclude(JsonInclude.Include.NON_NULL) -public class AddNodeRsp { - /** - * The Items. - */ - List items; - - /** - * Instantiates a new Add node rsp. - */ - public AddNodeRsp() { - this.items = new ArrayList<>(); - } -} diff --git a/src/main/java/com/dispose/pojo/vo/haohan/CleanReq.java b/src/main/java/com/dispose/pojo/vo/haohan/CleanReq.java deleted file mode 100644 index 25e11930..00000000 --- a/src/main/java/com/dispose/pojo/vo/haohan/CleanReq.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dispose.pojo.vo.haohan; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Clean req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CleanReq { - private String ip; - private String orderFrom; - private Long duration; -} diff --git a/src/main/java/com/dispose/pojo/vo/haohan/CleanRsp.java b/src/main/java/com/dispose/pojo/vo/haohan/CleanRsp.java deleted file mode 100644 index 6ab49e58..00000000 --- a/src/main/java/com/dispose/pojo/vo/haohan/CleanRsp.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dispose.pojo.vo.haohan; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Clean rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CleanRsp extends CommonRsp { - private Long cleanTaskId; -} diff --git a/src/main/java/com/dispose/pojo/vo/haohan/CleanTaskStatusRsp.java b/src/main/java/com/dispose/pojo/vo/haohan/CleanTaskStatusRsp.java deleted file mode 100644 index bdbffbe7..00000000 --- a/src/main/java/com/dispose/pojo/vo/haohan/CleanTaskStatusRsp.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dispose.pojo.vo.haohan; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Clean rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CleanTaskStatusRsp extends CommonRsp { - private Long cleanTaskState; -} diff --git a/src/main/java/com/dispose/pojo/vo/haohan/CommonRsp.java b/src/main/java/com/dispose/pojo/vo/haohan/CommonRsp.java deleted file mode 100644 index ef155251..00000000 --- a/src/main/java/com/dispose/pojo/vo/haohan/CommonRsp.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.dispose.pojo.vo.haohan; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Common rsp. - * - * @author - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CommonRsp { - private Integer state; - private String msg; -} diff --git a/src/main/java/com/dispose/pojo/vo/haohan/StopCleanReq.java b/src/main/java/com/dispose/pojo/vo/haohan/StopCleanReq.java deleted file mode 100644 index cd635fad..00000000 --- a/src/main/java/com/dispose/pojo/vo/haohan/StopCleanReq.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.dispose.pojo.vo.haohan; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Stop clean req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class StopCleanReq { - private Long cleanTaskId; - private String orderFrom; -} - - diff --git a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java b/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java deleted file mode 100644 index ea3dca1e..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityData.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.common.GlobalVar; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.vo.common.DisposeCapacity; -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * The type Device capacity data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@JsonPropertyOrder({"id", "capacity", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class DeviceCapacityData extends IDReturnStatus { - /** - * The Capacity. - */ - List capacity; - - /** - * Instantiates a new Device capacity data. - * - * @param cpList the cp list - */ - public DeviceCapacityData(List cpList) { - this.capacity = new ArrayList<>(); - - if (cpList == null) { - return; - } - - cpList.forEach(v -> { - String ipAddrs = String.join(",", - Arrays.asList(v.getProtectIpV4() != null ? v.getProtectIpV4() : new String[]{})) - + "," + String.join(",", - Arrays.asList(v.getProtectIpV6() != null ? v.getProtectIpV6() : new String[]{}) - ); - - if (ipAddrs.endsWith(GlobalVar.STRING_SPILT_CHAR)) { - ipAddrs = ipAddrs.substring(0, ipAddrs.length() - 1); - } - - DisposeCapacity cp = DisposeCapacity.builder() - .type(v.getCapacity()) - .tolCapacity(v.getTolFlowCapacity()) - .usedCapacity(0) - .disposeIp(ipAddrs) - .build(); - - this.capacity.add(cp); - }); - } -} diff --git a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityRsp.java b/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityRsp.java deleted file mode 100644 index 9e2e4752..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DeviceCapacityRsp.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Device capacity rsp. - * - * @author - */ -@Data -@NoArgsConstructor -@JsonPropertyOrder({"id", "capacity", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class DeviceCapacityRsp { - private List items; -} diff --git a/src/main/java/com/dispose/pojo/vo/information/DeviceInfoData.java b/src/main/java/com/dispose/pojo/vo/information/DeviceInfoData.java deleted file mode 100644 index 9c63dce9..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DeviceInfoData.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.common.ErrorCode; -import com.dispose.dispose.po.DeviceInfo; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Device info data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@JsonPropertyOrder({"id"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class DeviceInfoData extends DeviceInfo { - private String id; - private int status; - private String message; - - /** - * Instantiates a new Device info data. - * - * @param id the id - * @param vendor the vendor - * @param model the model - * @param firmware the firmware - * @param os the os - * @param kernel the kernel - * @param arch the arch - * @param memory the memory - * @param freeMemory the free memory - * @param cpuUsed the cpu used - * @param err the err - */ - public DeviceInfoData(String id, - String vendor, - String model, - String firmware, - String os, - String kernel, - String arch, - int memory, - int freeMemory, - int cpuUsed, - ErrorCode err) { - super(vendor, model, firmware, os, kernel, arch, memory, freeMemory, cpuUsed); - this.id = id; - this.status = err.getCode(); - this.message = err.getMsg(); - } - - /** - * Instantiates a new Device info data. - * - * @param id the id - * @param err the err - */ - public DeviceInfoData(String id, - ErrorCode err) { - this.id = id; - this.status = err.getCode(); - this.message = err.getMsg(); - } -} - diff --git a/src/main/java/com/dispose/pojo/vo/information/DeviceInfoRsp.java b/src/main/java/com/dispose/pojo/vo/information/DeviceInfoRsp.java deleted file mode 100644 index 4ebc5cd2..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DeviceInfoRsp.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.dispose.pojo.vo.information; - -import lombok.Data; - -import java.util.List; - -/** - * The type Device info rsp. - * - * @author - */ -@Data -public class DeviceInfoRsp { - /** - * The Items. - */ - List items; -} diff --git a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java b/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java deleted file mode 100644 index 9b47a680..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeData.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Dispose node data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status", - "message"}) -public class DisposeNodeData extends DeviceCapacityData { - private Integer type; - private String name; - private String ip; - private Integer areaCode; - private String manufacturer; - private String model; - private String version; - private String readme; - - /** - * Instantiates a new Dispose node data. - * - * @param type the type - * @param name the name - * @param ip the ip - * @param areaCode the area code - * @param manufacturer the manufacturer - * @param model the model - * @param version the version - * @param readme the readme - * @param capacity the capacity - */ - public DisposeNodeData(int type, String name, String ip, Integer areaCode, - String manufacturer, String model, String version, - String readme, - List capacity) { - super(capacity); - this.type = type; - this.name = name; - this.ip = ip; - this.areaCode = areaCode; - this.manufacturer = manufacturer; - this.model = model; - this.version = version; - this.readme = readme; - } -} diff --git a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeListRsp.java b/src/main/java/com/dispose/pojo/vo/information/DisposeNodeListRsp.java deleted file mode 100644 index a8c0f69c..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/DisposeNodeListRsp.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.dispose.pojo.vo.information; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Dispose node list rsp. - * - * @author - */ -@Data -@NoArgsConstructor -public class DisposeNodeListRsp { - private List items; -} diff --git a/src/main/java/com/dispose/pojo/vo/information/LinkStatusListRsp.java b/src/main/java/com/dispose/pojo/vo/information/LinkStatusListRsp.java deleted file mode 100644 index dd4a0285..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/LinkStatusListRsp.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Project: phoenix_ddos_handle2 - * - * File Created at 2020/5/11 10:59 - * - * Copyright 2019 CMCC Corporation Limited. - * All rights reserved. - * - * This software is the confidential and proprietary information of - * ZYHY Company. ("Confidential Information"). You shall not - * disclose such Confidential Information and shall use it only in - * accordance with the terms of the license. - */ -package com.dispose.pojo.vo.information; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Link status list rsp. - * - * @author - */ -@Data -@NoArgsConstructor -public class LinkStatusListRsp { - private List items; -} \ No newline at end of file diff --git a/src/main/java/com/dispose/pojo/vo/information/LinkStatusRsp.java b/src/main/java/com/dispose/pojo/vo/information/LinkStatusRsp.java deleted file mode 100644 index da65ebd3..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/LinkStatusRsp.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Link status rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"id", "devId", "online", "status", "message"}) -public class LinkStatusRsp extends IDReturnStatus { - private int online; - private String id; - private Integer status; - private String message; -} diff --git a/src/main/java/com/dispose/pojo/vo/information/NodeTaskData.java b/src/main/java/com/dispose/pojo/vo/information/NodeTaskData.java deleted file mode 100644 index 60c9df4b..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/NodeTaskData.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Node task data. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@AllArgsConstructor -@JsonPropertyOrder({"id", "taskArray", "status", "message"}) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class NodeTaskData extends IDReturnStatus { - private List taskArray; - - /** - * Instantiates a new Node task data. - */ - public NodeTaskData() { - this.taskArray = new ArrayList<>(); - } -} diff --git a/src/main/java/com/dispose/pojo/vo/information/NodeTaskRsp.java b/src/main/java/com/dispose/pojo/vo/information/NodeTaskRsp.java deleted file mode 100644 index feb14c3e..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/NodeTaskRsp.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.dispose.pojo.vo.information; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Node task rsp. - * - * @author - */ -@Data -@Builder -@AllArgsConstructor -public class NodeTaskRsp { - private List items; - - /** - * Instantiates a new Node task rsp. - */ - public NodeTaskRsp() { - this.items = new ArrayList<>(); - } -} diff --git a/src/main/java/com/dispose/pojo/vo/information/VersionListRsp.java b/src/main/java/com/dispose/pojo/vo/information/VersionListRsp.java deleted file mode 100644 index 288cfc49..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/VersionListRsp.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Project: phoenix_ddos_handle2 - * - * File Created at 2020/5/11 12:54 - * - * Copyright 2019 CMCC Corporation Limited. - * All rights reserved. - * - * This software is the confidential and proprietary information of - * ZYHY Company. ("Confidential Information"). You shall not - * disclose such Confidential Information and shall use it only in - * accordance with the terms of the license. - */ -package com.dispose.pojo.vo.information; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Version list rsp. - * - * @author - */ -@Data -@NoArgsConstructor -public class VersionListRsp { - private List items; - -} \ No newline at end of file diff --git a/src/main/java/com/dispose/pojo/vo/information/VersionRsp.java b/src/main/java/com/dispose/pojo/vo/information/VersionRsp.java deleted file mode 100644 index 6605ca51..00000000 --- a/src/main/java/com/dispose/pojo/vo/information/VersionRsp.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.dispose.pojo.vo.information; - -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Version rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"id", "devId", "version", "status", "message"}) -public class VersionRsp extends IDReturnStatus { - private String version; - private String id; - private String devId; - private Integer status; - private String message; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/GetTaskReq.java b/src/main/java/com/dispose/pojo/vo/task/GetTaskReq.java deleted file mode 100644 index d718537f..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/GetTaskReq.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.dispose.pojo.vo.task; - -import com.dispose.pojo.vo.common.IDArrayReq; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Get task req. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetTaskReq extends IDArrayReq { - private Integer type; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/StartTaskReq.java b/src/main/java/com/dispose/pojo/vo/task/StartTaskReq.java deleted file mode 100644 index 10bee16d..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/StartTaskReq.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.dispose.pojo.vo.task; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Start task req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class StartTaskReq { - private String id; - private Integer type; - private String disposeIp; - private Integer disposeTime; - private Integer flowDirection; - private Integer[] attackType; - private Integer flowBandwidth; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/StartTaskRsp.java b/src/main/java/com/dispose/pojo/vo/task/StartTaskRsp.java deleted file mode 100644 index 7eb297b1..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/StartTaskRsp.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.dispose.pojo.vo.task; - -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -/** - * The type Start task rsp. - * - * @author - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonPropertyOrder({"id", "taskId", "expireTime", "status", "message"}) -public class StartTaskRsp extends IDReturnStatus { - private String taskId; - private Long expireTime; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java b/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java deleted file mode 100644 index 022ea117..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/StopTaskData.java +++ /dev/null @@ -1,25 +0,0 @@ -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. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"id", "type", "disposeIp"}) -public class StopTaskData { - private String id; - private Integer type; - private String disposeIp; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/StopTaskReq.java b/src/main/java/com/dispose/pojo/vo/task/StopTaskReq.java deleted file mode 100644 index 7cc4b560..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/StopTaskReq.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.dispose.pojo.vo.task; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * The type Stop task req. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class StopTaskReq { - /** - * The Items. - */ - List items; -} diff --git a/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java b/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java deleted file mode 100644 index 9c734a83..00000000 --- a/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.dispose.pojo.vo.task; - -import com.dispose.pojo.vo.common.TaskInfoData; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Task info rsp. - * - * @author - */ -@Data -@Builder -@AllArgsConstructor -public class TaskInfoRsp { - /** - * The Items. - */ - List items; - - /** - * Instantiates a new Task info rsp. - */ - public TaskInfoRsp() { - this.items = new ArrayList<>(); - } -} diff --git a/src/main/java/com/dispose/service/DisposeNodeManager.java b/src/main/java/com/dispose/service/DisposeNodeManager.java deleted file mode 100644 index 4e8a86b2..00000000 --- a/src/main/java/com/dispose/service/DisposeNodeManager.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.dispose.service; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; - -import java.util.List; - -/** - * The interface Dispose node manager. - * - * @author - */ -public interface DisposeNodeManager { - /** - * Add new dispose device m return type. - * - * @param dev the dev - * @return the m return type - */ - MulReturnType addNewDisposeDevice(DisposeDevice dev); - - /** - * Del dispose device by ip error code. - * - * @param ipAddr the ip addr - * @return the error code - */ - ErrorCode delDisposeDeviceByIp(String ipAddr); - - /** - * Del dispose device by id error code. - * - * @param id the id - * @return the error code - */ - ErrorCode delDisposeDeviceById(Long id); - - /** - * Gets all dispose device. - * - * @return the all dispose device - */ - List getAllDisposeDevice(); - - /** - * Gets dispose device by ip. - * - * @param ipAddr the ip addr - * @return the dispose device by ip - */ - DisposeDevice getDisposeDeviceByIp(String ipAddr); - - /** - * Gets dispose device by id. - * - * @param id the id - * @return the dispose device by id - */ - DisposeDevice getDisposeDeviceById(Long id); - - /** - * Load dispose node from database. - */ - void loadDisposeNodeFromDatabase(); - - /** - * Cleanup dispose node cache. - */ - void cleanupDisposeNodeCache(); - - /** - * Gets dispose device. - * - * @param ipAddr the ip addr - * @param capacity the capacity - * @return the dispose device - */ - List getDisposeDevice(String ipAddr, DeviceCapacity capacity); -} diff --git a/src/main/java/com/dispose/service/TaskService.java b/src/main/java/com/dispose/service/TaskService.java deleted file mode 100644 index 7e705a08..00000000 --- a/src/main/java/com/dispose/service/TaskService.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.dispose.service; - -import com.dispose.common.ErrorCode; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.common.TaskInfoDetail; - -import java.util.List; - -/** - * The interface Task service. - * - * @author - */ -public interface TaskService { - /** - * Load task from database. - */ - void loadTaskFromDatabase(); - - /** - * Create task m return type. - * - * @param task the task - * @return the m return type - */ - MulReturnType createTask(TaskInfoDetail task); - - /** - * Start task error code. - * - * @param taskId the task id - * @return the error code - */ - ErrorCode startTask(Long taskId); - - /** - * Stop task error code. - * - * @param taskId the task id - * @return the error code - */ - ErrorCode stopTask(Long taskId); - - /** - * Stop task by dispose ip list. - * - * @param devId the dev id - * @param type the type - * @param ipAddr the ip addr - * @return the list - */ - List> stopTaskByDisposeIp(Long devId, int type, String ipAddr); - - /** - * Stop task by task id list. - * - * @param taskId the task id - * @return the list - */ - List> stopTaskByTaskId(Long taskId); - - /** - * Stop task by type list. - * - * @param type the type - * @return the list - */ - List> stopTaskByType(int type); - - /** - * Stop task by dispose node list. - * - * @param devId the dev id - * @param type the type - * @return the list - */ - List> stopTaskByDisposeNode(Long devId, int type); - - /** - * Finish task error code. - * - * @param taskId the task id - * @return the error code - */ - ErrorCode finishTask(Long taskId); - - /** - * Task is running boolean. - * - * @param task the task - * @return the boolean - */ - boolean taskIsRunning(TaskInfoDetail task); - - /** - * Task is expired boolean. - * - * @param task the task - * @return the boolean - */ - boolean taskIsExpired(TaskInfoDetail task); - - /** - * Task is exists boolean. - * - * @param devId the dev id - * @param userId the user id - * @param disposeIp the dispose ip - * @param disposeType the dispose type - * @return the boolean - */ - boolean taskIsExists(Long devId, Long userId, String disposeIp, int disposeType); - - /** - * Gets node all running task. - * - * @param devId the dev id - * @return the node all running task - */ - List getNodeAllRunningTask(Long devId); - - /** - * Gets node all task. - * - * @param devId the dev id - * @return the node all task - */ - List getNodeAllTask(Long devId); - - /** - * Gets all task. - * - * @return the all task - */ - List getAllTask(); - - /** - * Gets active task. - * - * @return the active task - */ - List getActiveTask(); -} diff --git a/src/main/java/com/dispose/service/UserAccountService.java b/src/main/java/com/dispose/service/UserAccountService.java index 7f26fb22..a3e1ed36 100644 --- a/src/main/java/com/dispose/service/UserAccountService.java +++ b/src/main/java/com/dispose/service/UserAccountService.java @@ -13,11 +13,11 @@ import java.security.NoSuchAlgorithmException; */ public interface UserAccountService { /** - * Login service m return type. + * Login service mul return type. * * @param username the username * @param password the password - * @return the m return type + * @return the mul return type * @throws NoSuchAlgorithmException the no such algorithm exception */ MulReturnType loginService(String username, String password) throws NoSuchAlgorithmException; diff --git a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java b/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java deleted file mode 100644 index f0d9bc0c..00000000 --- a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java +++ /dev/null @@ -1,293 +0,0 @@ -package com.dispose.service.impl; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.common.IPAddrType; -import com.dispose.dispose.DeviceRouter; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.mapper.TaskInfoMapper; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.UserAccountService; -import inet.ipaddr.AddressStringException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * The type Dispose node manager. - * - * @author - */ -@Service -@Slf4j -public class DisposeNodeManagerImpl implements DisposeNodeManager { - private final ConcurrentHashMap disposeDevMap = new ConcurrentHashMap<>(); - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - @Resource - private UserAccountService userAccountService; - @Resource - private TaskInfoMapper taskInfoMapper; - - /** - * Cleanup dispose node cache. - */ - @Override - public void cleanupDisposeNodeCache() { - disposeDevMap.clear(); - } - - /** - * Load dispose node from database. - */ - @Override - public void loadDisposeNodeFromDatabase() { - // 清理缓存中的所有内容 - disposeDevMap.clear(); - - // 从数据库中加载所有设备 - List devList = disposeDeviceMapper.selectAll(); - - if (devList == null) { - log.error("No device in database"); - return; - } - - devList.forEach(v -> { - // 对每个设备进行初始化 - //DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(), - // v.getIpAddr(), IPAddrType.getIpAddrType(v.getIpAddr())); - - DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v); - // 链接状态 - v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0); - // 版本信息 - v.setVersion(dp.getVersion()); - // 设备信息 - v.setDevInfo(dp.getDeviceInfo()); - // 设备能力信息 - v.setDevCaps(dp.getDeviceCapacity()); - - disposeDevMap.put(v.getIpAddr(), v); - }); - } - - /** - * Del dispose device by id error code. - * - * @param id the id - * @return the error code - */ - @Override - public ErrorCode delDisposeDeviceById(Long id) { - DisposeDevice dev = disposeDeviceMapper.getDeviceById(id); - - if (dev == null) { - log.error("No such device: deviceId:{}", id); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - return delDisposeDeviceByIp(dev.getIpAddr()); - } - - /** - * Del dispose device by ip error code. - * - * @param ipAddr the ip addr - * @return the error code - */ - @Override - public ErrorCode delDisposeDeviceByIp(String ipAddr) { - // 判断该IP是否存在 - if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0 - || !disposeDevMap.containsKey(ipAddr)) { - log.error("No such dispose device: ipAddr:{}", ipAddr); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - // 缓存中取出设备 - DisposeDevice dev = disposeDevMap.get(ipAddr); - - if (dev == null) { - log.error("No such dispose device in cache: ipAddr:{}", ipAddr); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - //删除task info表中的任务 - taskInfoMapper.removeTaskInfoById(dev.getId()); - - // 删除数据库和缓存中内容 - disposeDeviceMapper.delDisposeDeviceByIp(ipAddr); - disposeDevMap.remove(ipAddr); - - return ErrorCode.ERR_OK; - } - - /** - * Add new dispose device m return type. - * - * @param dev the dev - * @return the m return type - */ - @Override - public MulReturnType addNewDisposeDevice(DisposeDevice dev) { - DisposeEntryManager dp; - - if (dev.getType() == null || dev.getIpAddr() == null - || dev.getIpAddr().length() == 0 - || !IPAddrType.isIpAddress(dev.getIpAddr())) { - log.error("Add device error: type {}, ip {} url {}", dev.getType(), dev.getIpAddr(), dev.getUrl()); - return new MulReturnType<>(ErrorCode.ERR_PARAMS, String.valueOf(-1)); - } - - try { - // 获取处置设备硬件访问接口 - dp = DeviceRouter.deviceRouterFactory(dev); - - // 判断设备是否在线 - if (!dp.getDeviceLinkStatus()) { - log.error("The device heartbeat is abnormal and offline: deviceId:{}, type:{}, ip:{}", - dev.getId(), dev.getType(), dev.getIpAddr()); - return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1)); - } - } catch (Exception ex) { - log.error("No such dispose device: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr()); - return new MulReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1)); - } - - // 从缓存中获取设备信息 - DisposeDevice dbDev = disposeDeviceMapper.getDeviceByIp(dev.getIpAddr()); - - // 设备已经存在 - if (dbDev != null) { - log.error("The dispose device already exists: deviceId:{}, type:{}, ip:{}", dev.getId(), dev.getType(), dev.getIpAddr()); - return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId())); - } - - // 获取设备能力 - if (dev.getDevCaps() == null) { - // 更新能力 - dev.setDevCaps(dp.getDeviceCapacity()); - } else { - // 添加能力 - dev.getDevCaps().addAll(dp.getDeviceCapacity()); - } - - dev.setDevInfo(dp.getDeviceInfo()); - - // 保存设备信息到数据库中 - disposeDeviceMapper.addNewDisposeDevice(dev); - - // 保存设备信息到缓存中 - disposeDevMap.put(dev.getIpAddr(), dev); - return new MulReturnType<>(ErrorCode.ERR_OK, dev.getId().toString()); - } - - /** - * Gets all dispose device. - * - * @return the all dispose device - */ - @Override - public List getAllDisposeDevice() { - return new ArrayList<>(disposeDevMap.values()); - } - - /** - * Gets dispose device by ip. - * - * @param ipAddr the ip addr - * @return the dispose device by ip - */ - @Override - public DisposeDevice getDisposeDeviceByIp(String ipAddr) { - return disposeDevMap.get(ipAddr); - } - - /** - * Gets dispose device by id. - * - * @param id the id - * @return the dispose device by id - */ - @Override - public DisposeDevice getDisposeDeviceById(Long id) { - Optional findRet = disposeDevMap.values().stream() - .filter(disposeDevMap -> id.equals(disposeDevMap.getId())) - .findFirst(); - - return findRet.orElse(null); - } - - private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) { - try { - if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) { - for (String s : cap.getProtectIpV4()) { - if (IPAddrType.ipInRange(s, ipAddr)) { - return true; - } - } - } else if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) { - for (String s : cap.getProtectIpV6()) { - if (IPAddrType.ipInRange(s, ipAddr)) { - return true; - } - } - } - } catch (AddressStringException e) { - log.error(e.getMessage()); - return false; - } - - log.error("The IP address is not within device capacity: ipAddr:{}, capIpv4:{}, capIpv6:{}", - ipAddr, cap.getProtectIpV4(), cap.getProtectIpV6()); - return false; - } - - /** - * Gets dispose device. - * - * @param ipAddr the ip addr - * @param capacity the capacity - * @return the dispose device - */ - @Override - public List getDisposeDevice(String ipAddr, DeviceCapacity capacity) { - List devList = new ArrayList<>(); - - for (DisposeDevice dev : disposeDevMap.values()) { - // 判断设备是否在线 - if (dev.getLinkStatus() != 1) { - continue; - } - - // 判断当前设备是否支持处置能力 - List capList = dev.getDevCaps() - .stream() - .filter(f -> f.getCapacity() == capacity.getCode()) - .collect(Collectors.toList()); - - // 设备是否支持处置该IP的 - if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) { - log.info("{} with {} used device {}:{}", ipAddr, capacity.getReadme(), dev.getId(), dev.getIpAddr()); - devList.add(dev); - } - } - - if (devList.size() == 0) { - log.error("No such device to process {} of {}", ipAddr, capacity.getReadme()); - } - - return devList; - } -} diff --git a/src/main/java/com/dispose/service/impl/TaskServiceImpl.java b/src/main/java/com/dispose/service/impl/TaskServiceImpl.java deleted file mode 100644 index 9316598d..00000000 --- a/src/main/java/com/dispose/service/impl/TaskServiceImpl.java +++ /dev/null @@ -1,544 +0,0 @@ -package com.dispose.service.impl; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.ErrorCode; -import com.dispose.common.Helper; -import com.dispose.dispose.DeviceRouter; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.manager.TaskCacheManager; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.mapper.TaskInfoMapper; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.common.TaskInfo; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.TaskService; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - -/** - * The type Task service. - * - * @author - */ -@Service -@Slf4j -public class TaskServiceImpl implements TaskService { - - @Resource - private ObjectMapper objectMapper; - - @Resource - private TaskCacheManager taskCacheManager; - - @Resource - private DisposeTaskMapper disposeTaskMapper; - - @Resource - private DisposeNodeManager disposeNodeManager; - - @Resource - private TaskInfoMapper taskInfoMapper; - - private List getDisposeNode(String disposeIp, int devCapType) { - DeviceCapacity cap; - - try { - cap = DeviceCapacity.values()[devCapType]; - } catch (Exception ex) { - cap = DeviceCapacity.CLEANUP; - } - - if (cap == null) { - cap = DeviceCapacity.CLEANUP; - } - - return disposeNodeManager.getDisposeDevice(disposeIp, cap); - } - - /** - * Load task from database. - */ - @Override - public void loadTaskFromDatabase() { - // 从数据库中取出所有任务 - List taskList = disposeTaskMapper.selectAll().stream() - .filter(this::taskIsRunning) - .collect(Collectors.toList()); - - taskList.forEach(v -> { - v.setRetryTimes(0); - if (taskCacheManager.addTask(v) != ErrorCode.ERR_OK) { - try { - log.error("load error:\n" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); - } catch (JsonProcessingException e) { - log.error(e.getMessage()); - } - } - }); - } - - /** - * Create task m return type. - * - * @param task the task - * @return the m return type - */ - @Override - public MulReturnType createTask(TaskInfoDetail task) { - List disposeDevice = new ArrayList<>(); - Long taskId = task.getDeviceId(); - - // 首先查找有没有能处置这个ip的能力节点 - // 没有指定处置能力节点的情况 - if (taskId == null || taskId < 0) { - disposeDevice = getDisposeNode(task.getDisposeIp(), task.getType()); - task.setDeviceId(-1L); - } else { // 指定了处置能力节点的情况 - DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(taskId); - if (dev != null) { - disposeDevice.add(dev); - task.setDeviceId(dev.getId()); - } - } - - if (disposeDevice.size() == 0) { - log.error("No such device to dispose this task: devId:{}, disposeIp:{}, type:{}", - task.getDeviceId(), task.getDisposeIp(), task.getType()); - return MulReturnType.builder() - .firstParam(ErrorCode.ERR_NOSUCHDEVICE) - .secondParam(-1L) - .build(); - } - - // 查询当前是否有相同能力节点,相同用户,相同处置IP的且正在执行的处置任务,如果存在则忽略该次任务(依照产品需求) - List taskList = taskCacheManager.getAllRunningTask() - .stream() - .filter(v -> ((taskId == null || taskId == -1L) || Objects.equals(v.getDeviceId(), task.getDeviceId()) ||(v.getDeviceId() == -1L) ) - && Objects.equals(v.getAccountId(), task.getAccountId()) - && taskIsRunning(v) - && Objects.equals(v.getType(), task.getType()) - && Objects.equals(v.getDisposeIp(), task.getDisposeIp())) - .collect(Collectors.toList()); - - if (taskList.size() > 0) { - log.error("Same dispose task is running: devId:{}, disposeIp:{}, type:{}", - task.getDeviceId(), task.getDisposeIp(), task.getType()); - return MulReturnType.builder() - .firstParam(ErrorCode.ERR_TASKRUNNING) - .secondParam(taskList.get(0).getId()) - .build(); - } - - // 将该任务写入数据库和缓存,等到定时任务真正启动该任务 - disposeTaskMapper.addNewTask(task); - - task.setCreateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - - TaskInfoDetail cacheTask = disposeTaskMapper.getTaskById(task.getId()); - - ErrorCode err = taskCacheManager.addTask(cacheTask); - - log.info("Create new dispose task: devId:{}, disposeIp:{}, type:{}, result:{}", - task.getDeviceId(), task.getDisposeIp(), task.getType(), err.getMsg()); - - return MulReturnType.builder().firstParam(err).secondParam(task.getId()).build(); - } - - /** - * Start task error code. - * - * @param taskId the task id - * @return the error code - */ - @Override - public ErrorCode startTask(Long taskId) { - ErrorCode err = ErrorCode.ERR_OK; - - // 从缓存中根据任务id取回需要启动的任务的详细信息 - TaskInfoDetail task = taskCacheManager.getTaskById(taskId); - - if (task == null) { - log.error("No such task: taskId:{}", taskId); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - long planDuration = Helper.getTimestampDiff(task.getCreateTime(), task.getPlanEndTime()) / 60; - - List dev = getDisposeNode(task.getDisposeIp(), task.getType()); - - // 判断是否有支持处置该IP的能力 - if (dev.size() == 0) { - log.info("No dispose device handle: disposeIp:{}, devCapType:{}", task.getDisposeIp(), task.getType()); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - // 对新建的任务执行启动操作 - if (task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) { - // 更新任务状态为进行中 - taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode()); - - dev.forEach(k -> { - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(k.getType(), k.getIpAddr()); - - // 异步启动处置任务 - CompletableFuture.supplyAsync(() -> dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()], planDuration)) - .whenComplete((v, ex) -> { - if (ex != null) { - log.error("Start task: taskId:{}, error:{}", taskId, ex.getMessage()); - // 增加设备执行清洗任务信息 - taskInfoMapper.addNewTaskInfo(taskId, k.getId(), null, - (long) ErrorCode.ERR_SYSTEMEXCEPTION.getCode()); - } else { - if (v.getFirstParam() != ErrorCode.ERR_OK) { - // 执行任务失败恢复缓存中的任务状态 - taskInfoMapper.addNewTaskInfo(taskId, k.getId(), null, (long) v.getFirstParam().getCode()); - log.error("Start task: taskId:{}, disposeIp:{}, error:{}", - taskId, task.getDisposeIp(), v.getFirstParam().getMsg()); - } else { - // 执行任务成功 - taskInfoMapper.addNewTaskInfo(taskId, k.getId(), v.getSecondParam(), (long) v.getFirstParam().getCode()); - log.info("Start task finished: taskId:{}, disposeId:{}, type:{}", - taskId, task.getDisposeIp(), task.getType()); - } - } - }); - }); - } - - return err; - } - - /** - * Stop task error code. - * - * @param taskId the task id - * @return the error code - */ - @Override - public ErrorCode stopTask(Long taskId) { - TaskInfoDetail task = taskCacheManager.getTaskById(taskId); - - if (task != null) { - List dev = getDisposeNode(task.getDisposeIp(), task.getType()); - - // 判断是否有支持处置该IP的能力 - if (dev.size() == 0) { - log.info("No dispose device handle: disposeIp:{}, devCapType:{}", task.getDisposeIp(), task.getType()); - return ErrorCode.ERR_NOSUCHDEVICE; - } - - int prdStatus = task.getCurrentStatus(); - - ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_STOP.getCode()); - - if (err != ErrorCode.ERR_OK) { - log.error("Failed to update task status, currentStatus:{}", task.getCurrentStatus()); - return err; - } - - dev.forEach(k -> { - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(k.getType(), k.getIpAddr()); - - TaskInfo taskInfo = taskInfoMapper.getTaskInfo(taskId, k.getId()); - - // 异步启动处置任务 - CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), - DeviceCapacity.values()[task.getType()], - (taskInfo == null || taskInfo.getExternId() == null) ? -1 : taskInfo.getExternId())) - .whenComplete((v, ex) -> { - if (ex != null) { - // 恢复缓存中任务状态到先前状态 - taskCacheManager.upgradeTaskStatus(taskId, prdStatus); - log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage()); - } else { - if (v.getFirstParam() != ErrorCode.ERR_OK) { - // 恢复缓存中任务状态到先前状态 - taskCacheManager.upgradeTaskStatus(taskId, prdStatus); - log.error("Stop task: taskId:{}, error:{}", taskId, v.getFirstParam().getMsg()); - } else { - // 任务执行完成后更新数据库处置任务状态 - finishTask(taskId); - log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}", - taskId, task.getDisposeIp(), task.getType()); - } - } - }); - }); - } else { - log.error("No such task: taskId:{}", taskId); - return ErrorCode.ERR_NOSUCHTASK; - } - - return ErrorCode.ERR_OK; - } - - /** - * Finish task error code. - * - * @param taskId the task id - * @return the error code - */ - @Override - public ErrorCode finishTask(Long taskId) { - // 设置缓存任务状态为完成状态 - ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode()); - - if (err == ErrorCode.ERR_OK) { - // 设置数据库任务状态为完成状态 - disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode()); - Integer currentStatus = disposeTaskMapper.getTaskById(taskId).getCurrentStatus(); - log.info("taskId:{}, currentStatus:{}", taskId, currentStatus); - // 移除缓存中的任务信息 - taskCacheManager.removeTask(taskId); - } - - return err; - } - - /** - * Task is running boolean. - * - * @param task the task - * @return the boolean - */ - @Override - public boolean taskIsRunning(TaskInfoDetail task) { - return task.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode() - || task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode(); - } - - /** - * Task is expired boolean. - * - * @param task the task - * @return the boolean - */ - @Override - public boolean taskIsExpired(TaskInfoDetail task) { - return LocalDateTime.parse(task.getPlanEndTime(), - DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) - .isBefore(LocalDateTime.now()); - } - - /** - * Gets node all running task. - * - * @param devId the dev id - * @return the node all running task - */ - @Override - public List getNodeAllRunningTask(Long devId) { - List taskList = taskCacheManager - .getAllRunningTask() - .stream() - .filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode() - && (v.getDeviceId().equals(devId)) || v.getDeviceId() == -1L) - .collect(Collectors.toList()); - - if (taskList.size() > 0) { - log.info("The device has tasks running: devId:{}, tasksRunningNumber:{}", devId, taskList.size()); - return taskList; - } - - return new ArrayList<>(); - } - - /** - * Gets node all task. - * - * @param devId the dev id - * @return the node all task - */ - @Override - public List getNodeAllTask(Long devId) { - List taskList = new ArrayList<>(); - - //-1广播,所有设备都下发清洗任务 - List curId = disposeTaskMapper.getAllTaskByNodeDevId(devId); - List allId = disposeTaskMapper.getAllTaskByNodeDevId(-1L); - - if(allId != null && allId.size() > 0) { - taskList.addAll(allId); - } - - if(curId != null && curId.size() > 0) { - taskList.addAll(curId); - } - - if (taskList.size() > 0) { - log.info("The device has tasks: devId:{}, tasksNumber:{}", devId, taskList.size()); - } else { - log.info("The device has nothing tasks: devId:{}", devId); - } - - return taskList; - } - - /** - * Gets all task. - * - * @return the all task - */ - @Override - public List getAllTask() { - List taskList = disposeTaskMapper.selectAll(); - - if (taskList.size() > 0) { - return taskList; - } - return new ArrayList<>(); - } - - /** - * Gets active task. - * - * @return the active task - */ - @Override - public List getActiveTask() { - List taskList = taskCacheManager.getAllRunningTask(); - - if (taskList.size() > 0) { - return taskList; - } - return new ArrayList<>(); - } - - /** - * Stop task by task id list. - * - * @param taskId the task id - * @return the list - */ - @Override - public List> stopTaskByTaskId(Long taskId) { - List> retList = new ArrayList<>(); - - // 根据处置IP,拿出所有正在处置的任务 - List taskList = taskCacheManager.getAllRunningTask().stream() - .filter(v -> (Objects.equals(v.getId(), taskId)) - && taskIsRunning(v)) - .collect(Collectors.toList()); - - // 对符合条件的任务调用停止命令 - taskList.forEach(v -> { - ErrorCode err = stopTask(v.getId()); - retList.add(new MulReturnType<>(err, v)); - }); - - return retList; - } - - /** - * Task is exists boolean. - * - * @param devId the dev id - * @param userId the user id - * @param disposeIp the dispose ip - * @param disposeType the dispose type - * @return the boolean - */ - @Override - public boolean taskIsExists(Long devId, Long userId, String disposeIp, int disposeType) { - return taskCacheManager.getAllRunningTask().stream() - .anyMatch(v -> Objects.equals(v.getAccountId(), userId) - && Objects.equals(v.getDeviceId(), devId) - && Objects.equals(v.getDisposeIp(), disposeIp) - && Objects.equals(v.getType(), disposeType)); - } - - /** - * Stop task by dispose ip list. - * - * @param devId the dev id - * @param type the type - * @param ipAddr the ip addr - * @return the list - */ - @Override - public List> stopTaskByDisposeIp(Long devId, int type, String ipAddr) { - List> retList = new ArrayList<>(); - - // 根据处置IP,拿出所有正在处置的任务 - List taskList = taskCacheManager.getAllRunningTask().stream() - .filter(v -> (Objects.equals(v.getDeviceId(), devId)) - && (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode()) - && Objects.equals(v.getDisposeIp(), ipAddr) - && taskIsRunning(v)) - .collect(Collectors.toList()); - - // 对符合条件的任务调用停止命令 - taskList.forEach(v -> { - ErrorCode err = stopTask(v.getId()); - retList.add(new MulReturnType<>(err, v)); - }); - - return retList; - } - - /** - * Stop task by dispose node list. - * - * @param devId the dev id - * @param type the type - * @return the list - */ - @Override - public List> stopTaskByDisposeNode(Long devId, int type) { - List> retList = new ArrayList<>(); - - // 根据处置IP,拿出所有正在处置的任务 - List taskList = taskCacheManager.getAllRunningTask().stream() - .filter(v -> ((devId == -1L) || Objects.equals(v.getDeviceId(), devId)) - && (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode()) - && taskIsRunning(v)) - .collect(Collectors.toList()); - - // 对符合条件的任务调用停止命令 - taskList.forEach(v -> { - ErrorCode err = stopTask(v.getId()); - retList.add(new MulReturnType<>(err, v)); - }); - - return retList; - } - - /** - * Stop task by type list. - * - * @param type the type - * @return the list - */ - @Override - public List> stopTaskByType(int type) { - List> retList = new ArrayList<>(); - - // 根据处置IP,拿出所有正在处置的任务 - List taskList = taskCacheManager.getAllRunningTask().stream() - .filter(v -> (Objects.equals(v.getType(), type) || type == DeviceCapacity.ALLCAPACITY.getCode()) - && taskIsRunning(v)) - .collect(Collectors.toList()); - - // 对符合条件的任务调用停止命令 - taskList.forEach(v -> { - ErrorCode err = stopTask(v.getId()); - retList.add(new MulReturnType<>(err, v)); - }); - - return retList; - } -} diff --git a/src/main/java/com/dispose/swagger/Swagger2Config.java b/src/main/java/com/dispose/swagger/Swagger2Config.java deleted file mode 100644 index 3e43b7e2..00000000 --- a/src/main/java/com/dispose/swagger/Swagger2Config.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.dispose.swagger; - -import com.dispose.config.MyConfig; -import com.google.common.base.Predicates; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Contact; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -import javax.annotation.Resource; -import java.util.Collections; - -/** - * The type Swagger 2 config. - * - * @author - */ -@Configuration -@EnableSwagger2 -public class Swagger2Config { - - @Resource - private MyConfig myConfig; - - /** - * Api docket. - * - * @return the docket - */ - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2).enable(Boolean.parseBoolean(myConfig.getSwaggerSwitch())) - .select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()) - // 错误路径不监控 - .paths(Predicates.not(PathSelectors.regex("/error.*"))) - // 对根下所有路径进行监控 - .paths(PathSelectors.regex("/.*")) - .build().apiInfo(apiInfo()); - } - - private ApiInfo apiInfo() { - return new ApiInfo( - "phoenix脚手架工程API示例", "展示所有API信息,方便测试", "API V1.0", "xxx", new Contact("phoenix", - "http://git.komect.net/WLFHCZ/phoenix_share_framework.git", "phoenix@cmhi.chinamobile.com"), - "CMCC.HY", "", Collections.emptyList()); - } - -} diff --git a/src/main/java/com/dispose/task/DeviceManagerTask.java b/src/main/java/com/dispose/task/DeviceManagerTask.java deleted file mode 100644 index b4a91f0b..00000000 --- a/src/main/java/com/dispose/task/DeviceManagerTask.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.dispose.task; - -import com.dispose.dispose.DeviceRouter; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.service.DisposeNodeManager; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.List; - -/** - * The type Device manager task. - * - * @author - */ -@Component -public class DeviceManagerTask { - @Resource - private DisposeNodeManager disposeNodeManager; - - /** - * Thread pool task. - */ - @Async("bizExecutor") - @Scheduled(cron = "0/30 * * * * ?") - public void threadPoolTask() { - List devList = disposeNodeManager.getAllDisposeDevice(); - - devList.forEach(v -> { - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(v.getType(), v.getIpAddr()); - // 自动更新设备心跳状态 - v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0); - // 自动读取设备系统版本信息 - v.setVersion(dp.getVersion()); - // 自动更新系统信息 - v.setDevInfo(dp.getDeviceInfo()); - }); - } -} diff --git a/src/main/java/com/dispose/task/TaskManagerTask.java b/src/main/java/com/dispose/task/TaskManagerTask.java deleted file mode 100644 index cc642f79..00000000 --- a/src/main/java/com/dispose/task/TaskManagerTask.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.dispose.task; - -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.service.TaskService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.Iterator; - -/** - * The type Task manager task. - * - * @author - */ -@Component -@Slf4j -public class TaskManagerTask { - @Resource - private TaskService taskService; - - /** - * Task runtime manager. - */ - @Async("bizExecutor") - @Scheduled(fixedDelay = 1000) - public void taskRuntimeManager() { - Iterator it = taskService.getActiveTask().iterator(); - - // 由于可能删除列表中的项目,所以使用迭代器 - while (it.hasNext()) { - TaskInfoDetail taskData = it.next(); - - // 判断是否存在正在运行的过期的任务,如果存在则结束该任务 - if(taskService.taskIsExpired(taskData) && taskService.taskIsRunning(taskData)) { - log.info("Finish expired task {}:{} begin at {}", - taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime()); - taskService.stopTask(taskData.getId()); - it.remove(); - continue; - } - - // 如果重试次数过多,停止处理该任务 - if(taskData.getRetryTimes() > GlobalVar.TASK_ERROR_MAX_RETRY) { - continue; - } - - // 判断是否有新建任务,如果有的话启动新建的处置任务 - if (taskData.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) { - log.info("Start task {}:{} of {}", - taskData.getId(), taskData.getDisposeIp(), taskData.getCreateTime()); - if (taskService.startTask(taskData.getId()) != ErrorCode.ERR_OK) { - taskData.setRetryTimes(taskData.getRetryTimes() + 1); - log.error("startTask Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp()); - } - } - } - } -} diff --git a/src/main/java/com/dispose/thread/ThreadPoolConfig.java b/src/main/java/com/dispose/thread/ThreadPoolConfig.java deleted file mode 100644 index 7229289b..00000000 --- a/src/main/java/com/dispose/thread/ThreadPoolConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.dispose.thread; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.Executor; - -/** - * The type Thread pool config. - * - * @author - */ -@Configuration -public class ThreadPoolConfig { - - /** - * Log executor executor. - * - * @return the executor - */ - @Bean - public Executor logExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setThreadNamePrefix("myLog-"); - executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() << 1 + 1); - executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); - return executor; - } - - /** - * Biz executor executor. - * - * @return the executor - */ - @Bean - public Executor bizExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setThreadNamePrefix("myBiz-"); - executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() << 1 + 1); - executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); - return executor; - } - -} diff --git a/src/main/resources/db/data.sql b/src/main/resources/db/data.sql index ddca1461..58780e8d 100644 --- a/src/main/resources/db/data.sql +++ b/src/main/resources/db/data.sql @@ -1,8 +1,8 @@ -- ---------------------------- -- Records of dispose_device -- ---------------------------- -INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0); -INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0); +INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0); +INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 1, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0); -- ---------------------------- diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 63d5cbb6..8e403add 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -15,26 +15,23 @@ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- --- Table structure for dispose_device +-- Table structure for task_info -- ---------------------------- -DROP TABLE IF EXISTS `dispose_device`; -CREATE TABLE `dispose_device` +DROP TABLE IF EXISTS `task_info`; +CREATE TABLE `task_info` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', - `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备IP地址, IPv4/IPv6', - `type` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', - `areaCode` int(11) NULL DEFAULT NULL COMMENT '设备物理位置区域码', - `name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', - `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', - `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', - `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', - `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', - `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', - `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL类型', - `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', - `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常, 1:删除', + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', + `taskId` int(10) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', + `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', + `beginTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '任务开始时间', + `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', + `externId` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '扩展ID(供浩瀚处置任务使用)', + `status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态', PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `ipAddr` (`ipAddr`) USING BTREE + INDEX `task_info_ibfk_1` (`taskId`) USING BTREE, + INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE, + CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT, + CONSTRAINT `task_info_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 @@ -70,23 +67,26 @@ CREATE TABLE `dispose_task` ROW_FORMAT = Dynamic; -- ---------------------------- --- Table structure for task_info +-- Table structure for dispose_device -- ---------------------------- -DROP TABLE IF EXISTS `task_info`; -CREATE TABLE `task_info` +DROP TABLE IF EXISTS `dispose_device`; +CREATE TABLE `dispose_device` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', - `taskId` int(10) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', - `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', - `beginTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '任务开始时间', - `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', - `externId` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '扩展ID(供浩瀚处置任务使用)', - `status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态', + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', + `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备IP地址, IPv4/IPv6', + `type` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', + `areaCode` int(11) NULL DEFAULT NULL COMMENT '设备物理位置区域码', + `name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', + `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', + `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', + `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', + `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', + `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', + `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL类型', + `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', + `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常, 1:删除', PRIMARY KEY (`id`) USING BTREE, - INDEX `task_info_ibfk_1` (`taskId`) USING BTREE, - INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE, - CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT, - CONSTRAINT `task_info_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT + UNIQUE INDEX `ipAddr` (`ipAddr`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 diff --git a/src/main/resources/mappers/DisposeDevice.xml b/src/main/resources/mappers/DisposeDevice.xml deleted file mode 100644 index 50390f48..00000000 --- a/src/main/resources/mappers/DisposeDevice.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - INSERT IGNORE INTO - dispose_device(ipAddr, type, - areaCode, name, manufacturer, - model, version, userName, password, url, readme, status) - VALUES - (#{ipAddr}, #{type}, - #{areaCode}, #{name}, #{manufacturer}, - #{model}, #{version}, #{userName}, #{password}, #{url}, #{readme}, 0) - - - - - - - - - - DELETE - dispose_device - FROM - dispose_device - WHERE - dispose_device.ipAddr = #{ipAddr} - - \ No newline at end of file diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml deleted file mode 100644 index 82934bb1..00000000 --- a/src/main/resources/mappers/DisposeTask.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - INSERT IGNORE INTO dispose_task(deviceId, accountId, type, disposeIp, - planEndTime, flowDirection, attackType, flowBandWidth, - currentStatus) - VALUES (#{deviceId}, #{accountId}, #{type}, #{disposeIp}, - date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType}, - #{flowBandWidth}, #{currentStatus}) - - - - DELETE - dispose_task - FROM dispose_task - WHERE dispose_task.id = #{id} - - - - UPDATE - dispose_task - SET - currentStatus = #{status, jdbcType=INTEGER} - - , endTime = CURRENT_TIMESTAMP - - WHERE - id = #{id, jdbcType=INTEGER} - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mappers/TaskInfoMapper.xml b/src/main/resources/mappers/TaskInfoMapper.xml deleted file mode 100644 index 718412bd..00000000 --- a/src/main/resources/mappers/TaskInfoMapper.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - INSERT IGNORE INTO task_info(taskId, deviceId, externId, status) - VALUES (#{taskId}, #{deviceId}, #{externId}, #{status}) - - - - - - - - UPDATE - task_info - SET - status = #{status, jdbcType=INTEGER} - WHERE - id = #{id, jdbcType=INTEGER} - - - - - - DELETE - task_info - FROM task_info - WHERE task_info.deviceId = #{deviceId} - - - diff --git a/src/test/java/com/dispose/test/Global/InitTestEnvironment.java b/src/test/java/com/dispose/test/Global/InitTestEnvironment.java deleted file mode 100644 index 2d5820b9..00000000 --- a/src/test/java/com/dispose/test/Global/InitTestEnvironment.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.dispose.test.Global; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.dto.ProtocolRespDTO; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.service.UserAccountService; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.springframework.test.context.ActiveProfiles; - -import javax.annotation.Resource; -import java.util.Iterator; - -/** - * The type Init test environment. - */ -@Slf4j -@Getter -@ActiveProfiles("test") -public class InitTestEnvironment { - /** - * The connect timeout. - */ - public static final int HTTP_CONNECT_TIMEOUT = 10000; - /** - * The constant logToken. - */ - private static String logToken = "45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122"; - /** - * The User name. - */ - private final String USER_NAME = "admin"; - /** - * The Password. - */ - private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58"; - /** - * The User account service. - */ - @Resource - private UserAccountService userAccountService; - - /** - * Init virtual device. - */ - @BeforeClass - public static void initVirtualDevice() { - GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true; - GlobalVar.IS_CHECK_REQUEST_TIMEOUT = true; - - log.warn("Current Used Virtual Dispose Device"); - } - - /** - * User login. - * - * @throws Exception the exception - */ - @Before - public void userLogin() throws Exception { - MulReturnType ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); - - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); - logToken = ret.getSecondParam(); - - Assert.assertNotNull(logToken); - Assert.assertNotEquals(logToken.length(), 0); - } - - /** - * Gets log token. - * - * @return the log token - */ - public String getLogToken() { - return logToken; - } - - /** - * Verify resp string. - * - * @param resp the resp - * @return the string - */ - public String verifyResp(String resp) { - try { - ObjectMapper objectMapper = new ObjectMapper(); - ProtocolRespDTO rspInfo = objectMapper.readValue(resp, ProtocolRespDTO.class); - - // 校验版本 - if (rspInfo.getVer() < ConstValue.Protocol.VERSION) { - Assert.fail(); - } - - // 校验时间错 - if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT - && Math.abs(System.currentTimeMillis() - rspInfo.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) { - Assert.fail(); - } - - return rspInfo.getMsgContent(); - } catch (Exception ex) { - Assert.fail(); - } - - Assert.fail(); - return ""; - } - - /** - * Check response body. - * - * @param data the data - * @param reqTime the req time - * @return the string - * @throws JSONException the json exception - */ - public String verifyRep(String data, Long reqTime) throws JSONException { - Long verValue = 2L; - ErrorCode err = ErrorCode.ERR_OK; - - JSONObject jsonObject = new JSONObject(data); - Iterator it = jsonObject.keys(); - System.out.println(); - while (it.hasNext()) { - // 获得key - String key = it.next(); - String value = jsonObject.getString(key); - System.out.println("key: " + key + ",value:" + value); - } - - Long repTime = Long.valueOf(jsonObject.getString("timeStamp")); - if ((jsonObject.getString("timeStamp").length() == 0) || (repTime - reqTime) > HTTP_CONNECT_TIMEOUT) { - err = ErrorCode.ERR_REQTIMEOUT; - } - Assert.assertEquals(err, ErrorCode.ERR_OK); - - Long ver = Long.valueOf(jsonObject.getString("ver")); - if ((jsonObject.getString("ver").length() == 0) || (!ver.equals(verValue))) { - err = ErrorCode.ERR_VERSION; - } - Assert.assertEquals(err, ErrorCode.ERR_OK); - - long cryptoType = Long.parseLong(jsonObject.getString("cryptoType")); - if ((String.valueOf(cryptoType).length() == 0) || (cryptoType < 0)) { - err = ErrorCode.ERR_INPUTMISS; - } - Assert.assertEquals(err, ErrorCode.ERR_OK); - - return jsonObject.getString("msgContent"); - } -} diff --git a/src/test/java/com/dispose/test/TestSuit/AllDisposePlatformTest.java b/src/test/java/com/dispose/test/TestSuit/AllDisposePlatformTest.java deleted file mode 100644 index f686d113..00000000 --- a/src/test/java/com/dispose/test/TestSuit/AllDisposePlatformTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.dispose.test.TestSuit; - - -import com.dispose.test.config.DisposeConfigureTest; -import com.dispose.test.config.MyConfigTest; -import com.dispose.test.controller.AuthControllerTest; -import com.dispose.test.controller.DeviceNodeInfoControllerTest; -import com.dispose.test.controller.DeviceNodeManagerControllerTest; -import com.dispose.test.controller.TaskControllerTest; -import com.dispose.test.dptech.DPTechInterfaceTestCase; -import com.dispose.test.manager.UserAccountManagerTest; -import com.dispose.test.mapper.DisposeDeviceMapperTest; -import com.dispose.test.mapper.DisposeTaskMapperTest; -import com.dispose.test.mapper.UserAccountMapperTest; -import com.dispose.test.service.DisposeNodeManagerTest; -import com.dispose.test.service.TaskServiceTest; -import com.dispose.test.service.UserAccountServiceTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * The type All dispose platform test. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ -// MyConfigTest.class, -// TaskServiceTest.class, -// DisposeConfigureTest.class, -// DisposeTaskMapperTest.class, -// DisposeNodeManagerTest.class, -// DPTechInterfaceTestCase.class, -// UserAccountMapperTest.class, -// UserAccountManagerTest.class, -// DisposeDeviceMapperTest.class, -// AuthControllerTest.class, -// DeviceNodeManagerControllerTest.class, -// DeviceNodeInfoControllerTest.class, -// UserAccountServiceTest.class, -// TaskControllerTest.class -}) - -public class AllDisposePlatformTest { -} diff --git a/src/test/java/com/dispose/test/TestSuit/QATest.java b/src/test/java/com/dispose/test/TestSuit/QATest.java deleted file mode 100644 index d1af6ec6..00000000 --- a/src/test/java/com/dispose/test/TestSuit/QATest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.dispose.test.TestSuit; - -import com.dispose.test.controller.AuthControllerQATest; -import com.dispose.test.controller.AuthControllerSmokeTest; -import com.dispose.test.controller.DeviceNodeInfoControllerQATest; -import com.dispose.test.controller.DeviceNodeInfoControllerSmokeTest; -import com.dispose.test.controller.DeviceNodeManagerControllerQATest; -import com.dispose.test.controller.DeviceNodeManagerControllerSmokeTest; -import com.dispose.test.controller.TaskControllerQATest; -import com.dispose.test.controller.TaskControllerSmokeTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ -// AuthControllerQATest.class, -// AuthControllerSmokeTest.class, -// DeviceNodeManagerControllerQATest.class, -// DeviceNodeManagerControllerSmokeTest.class, -// DeviceNodeInfoControllerQATest.class, -// DeviceNodeInfoControllerSmokeTest.class, -// TaskControllerQATest.class, -// TaskControllerSmokeTest.class -}) -public class QATest { -} diff --git a/src/test/java/com/dispose/test/TestSuit/SmokeTest.java b/src/test/java/com/dispose/test/TestSuit/SmokeTest.java deleted file mode 100644 index 98ee538b..00000000 --- a/src/test/java/com/dispose/test/TestSuit/SmokeTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.dispose.test.TestSuit; - -import com.dispose.test.controller.AuthControllerSmokeTest; -import com.dispose.test.controller.DeviceNodeInfoControllerSmokeTest; -import com.dispose.test.controller.DeviceNodeManagerControllerSmokeTest; -import com.dispose.test.controller.TaskControllerSmokeTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * The type Smoke test. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ -// AuthControllerSmokeTest.class, -// DeviceNodeManagerControllerSmokeTest.class, -// DeviceNodeInfoControllerSmokeTest.class, -// TaskControllerSmokeTest.class -}) - -public class SmokeTest { -} diff --git a/src/test/java/com/dispose/test/config/DisposeConfigureTest.java b/src/test/java/com/dispose/test/config/DisposeConfigureTest.java deleted file mode 100644 index 9e42376e..00000000 --- a/src/test/java/com/dispose/test/config/DisposeConfigureTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.dispose.test.config; - -import com.dispose.config.DisposeConfigure; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; - -/** - * The type Dispose configure test. - */ -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DisposeConfigureTest extends InitTestEnvironment { - /** - * The Dispose configure. - */ - @Resource - private DisposeConfigure disposeConfigure; - - /** - * User login. - */ - @Override - public void userLogin() { - } - - /** - * T 1 dispose cfg test. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t1_disposeCfgTest() throws JsonProcessingException { - Assert.assertNotNull(disposeConfigure); - - log.info(new ObjectMapper().writeValueAsString(disposeConfigure)); - } -} diff --git a/src/test/java/com/dispose/test/config/MyConfigTest.java b/src/test/java/com/dispose/test/config/MyConfigTest.java deleted file mode 100644 index 21ae0553..00000000 --- a/src/test/java/com/dispose/test/config/MyConfigTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.dispose.test.config; - -import com.dispose.config.MyConfig; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; - -/** - * The type My config test. - */ -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MyConfigTest extends InitTestEnvironment { - /** - * The My config. - */ - @Resource - private MyConfig myConfig; - - /** - * User login. - */ - @Override - public void userLogin() { - } - - /** - * T 1 my config test. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t1_myConfigTest() throws JsonProcessingException { - Assert.assertNotNull(myConfig); - - log.info(new ObjectMapper().writeValueAsString(myConfig)); - } -} diff --git a/src/test/java/com/dispose/test/controller/AuthControllerQATest.java b/src/test/java/com/dispose/test/controller/AuthControllerQATest.java deleted file mode 100644 index a66d3a77..00000000 --- a/src/test/java/com/dispose/test/controller/AuthControllerQATest.java +++ /dev/null @@ -1,716 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.auth.LogoutRsp; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -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; - -/** - * The type Auth controller exception smoke test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -public class AuthControllerQATest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * A 2 ver json exception test. - * - * @throws Exception the exception - */ - @Test - public void a1_loginVerJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" + - "\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 3 ver null exception test. - * - * @throws Exception the exception - */ - @Test - public void a2_loginVerNullExceptionTest() throws Exception { - String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 4 crypto json exception test. - * - * @throws Exception the exception - */ - @Test - public void a3_loginCryptoJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 5 crypto null exception test. - * - * @throws Exception the exception - */ - @Test - public void a4_loginCryptoNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 7 username empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a5_loginUsernameEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - /** - * A 8 username null exception test. - * - * @throws Exception the exception - */ - @Test - public void a6_loginUsernameNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - - - /** - * B 1 password null exception test. - * - * @throws Exception the exception - */ - @Test - public void b1_loginPasswordNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"password\\\":null,\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode())); - } - - /** - * B 2 password error exception test. - * - * @throws Exception the exception - */ - @Test - public void b2_loginPasswordErrorExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"password\\\":\\\"123456\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode())); - } - - /** - * B 3 password empty exception test. - * - * @throws Exception the exception - */ - @Test - public void b3_loginPasswordEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode())); - } - - /** - * B 4 msg empty exception test. - * - * @throws Exception the exception - */ - @Test - public void b4_loginMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * B 5 msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void b5_loginMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"null\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * B 6 username type exception test. - * - * @throws Exception the exception - */ - @Test - public void b6_loginUsernameIntExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":1}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode())); - } - - /** - * C 1 normal logout test . - * - * @throws Exception the exception - */ - @Test - public void c1_logoutNormalLogoutTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LogoutRsp rspInfo = objectMapper.readValue(verifyResp(ret), LogoutRsp.class) ; - - Assert.assertNotNull(rspInfo); - Assert.assertNotNull(rspInfo.getUserName()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - - /** - * C 2 username type exception test. - * - * @throws Exception the exception - */ - @Test - public void c2_logoutUsernameTypeExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":1,\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * C 2 username empty exception test. - * - * @throws Exception the exception - */ - @Test - public void c3_logoutUsernameEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - /** - * C 3 username null exception test. - * - * @throws Exception the exception - */ - @Test - public void c4_logoutUsernameNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - /** - * C 5 msg empty exception test. - * - * @throws Exception the exception - */ - @Test - public void c5_logoutMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - /** - * C 6 msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void c6_logoutMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"null\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - /** - * C 7 ver json exception test . - * - * @throws Exception the exception - */ - @Test - public void c7_logoutVerJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * C 8 ver null exception test . - * - * @throws Exception the exception - */ - @Test - public void c8_logoutVerNullExceptionTest() throws Exception { - String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * C 9 crypto json exception test . - * - * @throws Exception the exception - */ - @Test - public void c9_logoutCryptoJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * C 10 crypto null exception test . - * - * @throws Exception the exception - */ - @Test - public void c10_logoutCryptoNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * C 11 username not exit exception test . - * - * @throws Exception the exception - */ - @Test - public void c11_logoutUsernameNotExitExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + - "\"msgContent\":\"{\\\"userName\\\":\\\"a\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_USERNOTFOUND.getMsg()); - } -} diff --git a/src/test/java/com/dispose/test/controller/AuthControllerSmokeTest.java b/src/test/java/com/dispose/test/controller/AuthControllerSmokeTest.java deleted file mode 100644 index d84841f2..00000000 --- a/src/test/java/com/dispose/test/controller/AuthControllerSmokeTest.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.auth.LoginRsp; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -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; - -/** - * The type Auth controller smoke test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -public class AuthControllerSmokeTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * A 1 login normal login test. - * - * @throws Exception the exception - */ - @Test - public void a1_loginNormalLoginTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"password\\\"" + - ":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LoginRsp rspInfo = objectMapper.readValue(verifyResp(ret), LoginRsp.class) ; - - Assert.assertNotNull(rspInfo); - Assert.assertNotNull(rspInfo.getUserName()); - Assert.assertNotNull(rspInfo.getLogTime()); - Assert.assertNotNull(rspInfo.getToken()); - Assert.assertNotNull(rspInfo.getExpireTime()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - - /** - * A 2 login username as integer exception test. - * - * @throws Exception the exception - */ - @Test - public void a2_loginUsernameAsIntegerExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + - "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + - "\\\"userName\\\":\\\"123456\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode())); - } - - /** - * A 3 login password empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a3_loginPasswordEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ; - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode())); - } -} diff --git a/src/test/java/com/dispose/test/controller/AuthControllerTest.java b/src/test/java/com/dispose/test/controller/AuthControllerTest.java deleted file mode 100644 index aa643c0d..00000000 --- a/src/test/java/com/dispose/test/controller/AuthControllerTest.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -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.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -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; - -/** - * The type Auth controller test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -public class AuthControllerTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * Login 1. - * - * @throws Exception the exception - */ - @Test - public void a1_login() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName(getUSER_NAME()) - .password(getPASSWORD()) - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - ProtocolRespDTO rspInfo = objectMapper.readValue(ret, ProtocolRespDTO.class); - LoginRsp logRsp = objectMapper.readValue(rspInfo.getMsgContent(), LoginRsp.class); - - Assert.assertEquals(getLogToken(), logRsp.getToken()); - } - - @Test - public void a1_loginBadHead() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName(getUSER_NAME()) - .password(getPASSWORD()) - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(1); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void a1_loginBadUsername() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName(getUSER_NAME() + "123") - .password(getPASSWORD()) - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - /** - * Logout 2. - * - * @throws Exception the exception - */ - @Test - public void b1_logout() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName("admin") - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - } - - /** - * Logout 2. - * - * @throws Exception the exception - */ - @Test - public void b2_logout() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName("admin2") - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(502)) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void b3_logoutBadVersionTest() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName("admin2") - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(1); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void b4_logoutBadAuthHeadTest() throws Exception { - LoginReq logReq = LoginReq.builder() - .userName("admin2") - .build(); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "" + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } -} diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerQATest.java b/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerQATest.java deleted file mode 100644 index 8cda90ca..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerQATest.java +++ /dev/null @@ -1,3584 +0,0 @@ -/* - * Project: phoenix_ddos_handle2 - * - * File Created at 2020/5/8 11:19 - * - * Copyright 2019 CMCC Corporation Limited. - * All rights reserved. - * - * This software is the confidential and proprietary information of - * ZYHY Company. ("Confidential Information"). You shall not - * disclose such Confidential Information and shall use it only in - * accordance with the terms of the license. - */ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.common.DisposeCapacity; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.information.DeviceCapacityData; -import com.dispose.pojo.vo.information.DeviceCapacityRsp; -import com.dispose.pojo.vo.information.DeviceInfoData; -import com.dispose.pojo.vo.information.DeviceInfoRsp; -import com.dispose.pojo.vo.information.DisposeNodeData; -import com.dispose.pojo.vo.information.DisposeNodeListRsp; -import com.dispose.pojo.vo.information.LinkStatusListRsp; -import com.dispose.pojo.vo.information.LinkStatusRsp; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.information.VersionListRsp; -import com.dispose.pojo.vo.information.VersionRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -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.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -/** - * The type Device node info controller smoke test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -public class DeviceNodeInfoControllerQATest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose node manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - - /** - * A 1 get version normal one exist device test. - * - * @throws Exception the exception - */ - @Test - public void a1_getVersionNormalOneExistDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, VersionListRsp.class); - List verList = versionListRsp.getItems(); - Assert.assertEquals(verList.size(), 1); - for (VersionRsp versionRsp : verList - ) { - if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getVersion()); - } else { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNull(versionRsp.getVersion()); - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * A 2 get version normal several device test. - * - * @throws Exception the exception - */ - @Test - public void a2_getVersionNormalSeveralDeviceTest() throws Exception { - // 获取多个节点版本信息 - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"123\\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, VersionListRsp.class); - List verList = versionListRsp.getItems(); -// List verList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - Assert.assertTrue(verList.size() > 1); - for (VersionRsp versionRsp : verList - ) { - if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getVersion()); - } else { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNull(versionRsp.getVersion()); - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * A 3 get version normal one not exist device test. - * - * @throws Exception the exception - */ - @Test - public void a3_getVersionNormalOneNotExistDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, VersionListRsp.class); - List verList = versionListRsp.getItems(); -// List verList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - Assert.assertEquals(verList.size(), 1); - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNull(versionRsp.getVersion()); - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * A 4 get version msg empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a4_getVersionMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), - String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * A 5 get version msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void a5_getVersionMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), - String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * A 6 get version id null exception test. - * - * @throws Exception the exception - */ - @Test - public void a6_getVersionIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - String msgContent = verifyResp(ver); - VersionRsp versionRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), - String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * A 7 get version id character exception test. - * - * @throws Exception the exception - */ - @Test - public void a7_getVersionIdCharacterExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(ver); - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - List verList = versionListRsp.getItems(); - - Assert.assertEquals(verList.size(), 1); - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertEquals(String.valueOf(versionRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * A 8 get version array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void a8_getVersionArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ver), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * A 9 get version Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void a9_getVersionArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - VersionListRsp versionListRsp = objectMapper.readValue(verifyResp(ver), VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - /** - * A 10 get version Array contains repeated elements test. 去重 - * - * @throws Exception the exception - */ - @Test - public void a10_getVersionArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - VersionListRsp versionListRsp = objectMapper.readValue(verifyResp(ver), VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getStatus()); - Assert.assertNotNull(versionRsp.getMessage()); - - if (versionRsp.getStatus() == 0) { - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (versionRsp.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * A 11 get version Array contains character test. - * - * @throws Exception the exception - */ - @Test - public void a11_getVersionArrayContainsCharacterTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"12*a \\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - VersionListRsp versionListRsp = objectMapper.readValue(verifyResp(ver), VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getStatus()); - Assert.assertNotNull(versionRsp.getMessage()); - - if (versionRsp.getStatus() == 0) { - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (versionRsp.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * A 12 get version Array sort test. - * - * @throws Exception the exception - */ - @Test - public void a12_getVersionArraySortTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\", \\\"3\\\", \\\"1\\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - VersionListRsp versionListRsp = objectMapper.readValue(verifyResp(ver), VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getStatus()); - Assert.assertNotNull(versionRsp.getMessage()); - - if (versionRsp.getStatus() == 0) { - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (versionRsp.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * A 13 get version id json exception test. - * - * @throws Exception the exception - */ - @Test - public void a13_getVersionIdJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":}\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - VersionRsp versionRsp = objectMapper.readValue(verifyResp(ver), new TypeReference() {}); - - Assert.assertEquals(String.valueOf(versionRsp.getStatus()),String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - - } - - /** - * B 1 get device info normal one exist device test. - * - * @throws Exception the exception - */ - @Test - public void b1_getDeviceInfoNormalOneExistDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(deviceInfo); - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); - List deviceInfoList = deviceInfoRsp.getItems(); - Assert.assertEquals(deviceInfoList.size(), 1); - for (DeviceInfoData d : deviceInfoList - ) { - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotNull(d.getId()); - Assert.assertNotEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * B 2 get device info normal several device test. - * - * @throws Exception the exception - */ - @Test - public void b2_getDeviceInfoNormalSeveralDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"123\\\"]}\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(deviceInfo); - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); - List deviceInfoList = deviceInfoRsp.getItems(); - Assert.assertTrue(deviceInfoList.size() > 1); - for (DeviceInfoData d : deviceInfoList - ) { - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * B 3 get device info normal one not exist device test. - * - * @throws Exception the exception - */ - @Test - public void b3_getDeviceInfoNormalOneNotExistDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(deviceInfo); - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); - List deviceInfoList = deviceInfoRsp.getItems(); - - Assert.assertEquals(deviceInfoList.size(), 1); - for (DeviceInfoData d : deviceInfoList - ) { - Assert.assertNotNull(d.getId()); - Assert.assertEquals(d.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * B 4 get device info empty msg exception test. - * - * @throws Exception the exception - */ - @Test - public void b4_getDeviceInfoEmptyMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * B 5 get device info msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void b5_getDeviceInfoMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * B 6 get device info id null exception test. - * - * @throws Exception the exception - */ - @Test - public void b6_getDeviceInfoIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * B 7 get device info id character exception test. - * - * @throws Exception the exception - */ - @Test - public void b7_getDeviceInfoIdCharacterExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(deviceInfo); - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - List verList = deviceInfoRsp.getItems(); - - Assert.assertEquals(verList.size(), 1); - for (DeviceInfoData deviceInfoData : verList - ) { - Assert.assertNotNull(deviceInfoData.getId()); - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * B 8 get device info array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void b8_getDeviceInfoArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(deviceInfo), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * b 9 get device info Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void b9_getDeviceInfoArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(verifyResp(deviceInfo), DeviceInfoRsp.class); - List verList = deviceInfoRsp.getItems(); - - for (DeviceInfoData deviceInfoData : verList - ) { - Assert.assertNotNull(deviceInfoData.getId()); - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - /** - * B 10 get device info Array contains repeated elements exception test. - * - * @throws Exception the exception - */ - @Test - public void b10_getDeviceInfoArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"1\\\", \\\"123\\\"]}\"}"; - - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(verifyResp(deviceInfo), DeviceInfoRsp.class); - List verList = deviceInfoRsp.getItems(); - - for (DeviceInfoData deviceInfoData : verList - ) { - Assert.assertNotNull(deviceInfoData.getId()); - Assert.assertNotNull(String.valueOf(deviceInfoData.getStatus())); - Assert.assertNotNull(deviceInfoData.getMessage()); - - if (deviceInfoData.getStatus() == 0) { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * B 11 get device info Array contains character test. - * - * @throws Exception the exception - */ - @Test - public void b11_getDeviceInfoArrayContainsCharacterTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"12*a \\\"]}\"}"; - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(verifyResp(ver), DeviceInfoRsp.class); - List verList = deviceInfoRsp.getItems(); - - for (DeviceInfoData deviceInfoData : verList - ) { - Assert.assertNotNull(deviceInfoData.getId()); - Assert.assertNotNull(String.valueOf(deviceInfoData.getStatus())); - Assert.assertNotNull(deviceInfoData.getMessage()); - - if (deviceInfoData.getStatus() == 0) { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * B 12 get device info Array sort test. - * - * @throws Exception the exception - */ - @Test - public void b12_getDeviceInfoArraySortTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\", \\\"3\\\", \\\"1\\\"]}\"}"; - - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(verifyResp(deviceInfo), DeviceInfoRsp.class); - List verList = deviceInfoRsp.getItems(); - - for (DeviceInfoData deviceInfoData : verList - ) { - Assert.assertNotNull(deviceInfoData.getId()); - Assert.assertNotNull(String.valueOf(deviceInfoData.getStatus())); - Assert.assertNotNull(deviceInfoData.getMessage()); - - if (deviceInfoData.getStatus() == 0) { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * B 13 get device info id json exception test. - * - * @throws Exception the exception - */ - @Test - public void b13_getDeviceInfoIdJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":}\"}"; - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceInfoData deviceInfoData = objectMapper.readValue(verifyResp(ver), new TypeReference() {}); - - Assert.assertEquals(String.valueOf(deviceInfoData.getStatus()),String.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(deviceInfoData.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * C 1 get link status normal one online device test. - * - * @throws Exception the exception - */ - @Test - public void c1_getLinkStatusNormalOneOnlineDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(linkstatus); - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, LinkStatusListRsp.class); - List linkStatusList = linkStatusListRsp.getItems(); -// List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - - Assert.assertEquals(linkStatusList.size(), 1); - for (LinkStatusRsp linkStatusRsp : linkStatusList - ) { - if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - } else { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - } - } - } - - /** - * C 2 get link status normal several device test. - * - * @throws Exception the exception - */ - @Test - public void c2_getLinkStatusNormalSeveralDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"123\\\"]}\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(linkstatus); - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, LinkStatusListRsp.class); - List linkStatusList = linkStatusListRsp.getItems(); -// List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - - for (LinkStatusRsp linkStatusRsp : linkStatusList - ) { - if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - } else { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - } - } - } - - /** - * C 3 get link status normal one not online device test. - * - * @throws Exception the exception - */ - @Test - public void c3_getLinkStatusNormalOneNotOnlineDeviceTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"333\\\"]}\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(linkstatus); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, LinkStatusListRsp.class); - List linkStatusList = linkStatusListRsp.getItems(); -// List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - - Assert.assertEquals(linkStatusList.size(), 1); - for (LinkStatusRsp linkStatusRsp : linkStatusList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - } - } - - /** - * C 4 get link status msg empty exception test. - * - * @throws Exception the exception - */ - @Test - public void c4_getLinkStatusMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * C 5 get link status msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void c5_getLinkStatusMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * C 6 get link status id null exception test. - * - * @throws Exception the exception - */ - @Test - public void c6_getLinkStatusIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * C 7 get link status id character exception test. - * - * @throws Exception the exception - */ - @Test - public void c7_getLinkStatusIdCharacterExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(linkstatus); - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - List linkStatusRspList = linkStatusListRsp.getItems(); - - Assert.assertEquals(linkStatusRspList.size(), 1); - for (LinkStatusRsp linkStatusRsp : linkStatusRspList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * C 8 get link status array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void c8_getLinkStatusArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * C 9 get link status Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void c9_getLinkStatusArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(verifyResp(linkstatus), LinkStatusListRsp.class); - List linkStatusRspList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusRspList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - /** - * C 10 get link status Array contains repeated elements test. - * - * @throws Exception the exception - */ - @Test - public void c10_getLinkStatusArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"1\\\",\\\"123\\\"]}\"}"; - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(verifyResp(linkstatus), LinkStatusListRsp.class); - List linkStatusRspList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusRspList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertNotNull(linkStatusRsp.getStatus()); - Assert.assertNotNull(linkStatusRsp.getMessage()); - - if (linkStatusRsp.getStatus() == 0) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * C 11 get link status Array contains character test. - * - * @throws Exception the exception - */ - @Test - public void c11_getLinkStatusArrayContainsCharacterTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"12*a \\\"]}\"}"; - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(verifyResp(linkstatus), LinkStatusListRsp.class); - List linkStatusRspList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusRspList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertNotNull(linkStatusRsp.getStatus()); - Assert.assertNotNull(linkStatusRsp.getMessage()); - - if (linkStatusRsp.getStatus() == 0) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (linkStatusRsp.getStatus() == 19){ - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * C 12 get link status Array sort test. - * - * @throws Exception the exception - */ - @Test - public void c12_getLinkStatusArraySortTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\", \\\"3\\\", \\\"1\\\"]}\"}"; - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(verifyResp(linkstatus), LinkStatusListRsp.class); - List linkStatusRspList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusRspList - ) { - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertNotNull(linkStatusRsp.getStatus()); - Assert.assertNotNull(linkStatusRsp.getMessage()); - - if (linkStatusRsp.getStatus() == 0) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (linkStatusRsp.getStatus() == 19){ - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - Assert.assertEquals(String.valueOf(linkStatusRsp.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - /** - * C 13 get link status id json exception test. - * - * @throws Exception the exception - */ - @Test - public void c13_getLinkStatusIdJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":}\"}"; - - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(linkstatus), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * d1 get one node capacity . - */ - @Test - public void d1_NormalGetOneNodeCapacityTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> Assert.assertNotNull(k.getType())); - } - }); - } - - /** - * d2 get multiple node capabilities . - */ - @Test - public void d2_NormalGetMultipleNodeCapacityTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> Assert.assertNotNull(k.getType())); - } - }); - } - - /** - * d3 Get a node capability that does not exist . - */ - @Test - public void d3_NormalGetCapacityNodeNotExistTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(200)) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> Assert.assertNotNull(k.getType())); - } - }); - } - - /** - * d4 get capacity msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void d4_getCapacityEmptyMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(521)) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * d5 get capacity msgContent null exception test. - * - * @throws Exception the exception - */ - @Test - public void d5_getCapacityNullMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":null}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(521)) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * d6 get capacity id null exception test. - * - * @throws Exception the exception - */ - @Test - public void d6_getCapacityEmptyMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(521)) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * d7 get capacity id "abc" exception test. - * - * @throws Exception the exception - */ - @Test - public void d7_getCapacityErrIdExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abc\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyResp(capacity); - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(msgContent, new TypeReference() { - }); - - List deviceCapacityDataList = deviceCapacityRsp.getItems(); - - Assert.assertEquals(deviceCapacityDataList.size(), 1); - for (DeviceCapacityData deviceCapacityData : deviceCapacityDataList - ) { - Assert.assertNotNull(deviceCapacityData.getId()); - Assert.assertEquals(String.valueOf(deviceCapacityData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(deviceCapacityData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * d8 get capacity id Integer exception test.该情况不能做判断 数组内部的类型 - * - * @throws Exception the exception - */ - @Test - public void d8_getCapacityIntegerIdExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[1, 2]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> Assert.assertNotNull(k.getType())); - } - }); - } - - /** - * D 9 get capacity array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void d9_getGetCapacityArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * D 10 get capacity Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void d10_getCapacityArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - List deviceCapacityDataList = deviceCapacityRsp.getItems(); - - for (DeviceCapacityData deviceCapacityData : deviceCapacityDataList - ) { - Assert.assertNotNull(deviceCapacityData.getId()); - Assert.assertEquals(String.valueOf(deviceCapacityData.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(deviceCapacityData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - /** - * D 11 get capacity Array contains repeated elements test. - */ - @Test - public void d11_GetMultipleNodeArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"2\\\"]}\"}"; - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(capacity), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> Assert.assertNotNull(k.getType())); - } - }); - } - - /** - * e1 get protection IP a node protection IP that exists exception test. - */ - @Test - public void e1_NormalGetOneNodeProtectionIpTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * e2 get multiple node protection IPs that exists. - */ - @Test - public void e2_NormalGetMultipleNodeProtectionIpsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * e3 get a node protection IP that does not exist . - */ - @Test - public void e3_NormalGetNotExistedNodeProtectionIpTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * e4 get protection IP msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void e4_getIpEmptyMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(protectedIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e5 get protection IP msgContent null exception test. - * - * @throws Exception the exception - */ - @Test - public void e5_getIpNullMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":null}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(protectedIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e6 get protection IP id empty exception test. - * - * @throws Exception the exception - */ - @Test - public void e6_getIpNullMsgExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(protectedIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e7 get protection IP id "abd" exception test. - * - * @throws Exception the exception - */ - @Test - public void e7_getIpErrIdExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":\\\"abd\\\"}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(protectedIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e8 get protection IP id Integer exception test. 数组内"1"和1 不能做判断 - * - * @throws Exception the exception - */ - @Test - public void e8_getIpIntegerIdExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[1, 2]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * e9 get protection IP array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void e9_getIpArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(protectedIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * e10 get protection IP Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void e10_getCapacityArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * e11 e10 get protection IP Array contains repeated elements test. 去重 - */ - @Test - public void e11_getCapacityArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"2\\\"]}\"}"; - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class); - deviceCapacityRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - if (v.getCapacity() != null) { - v.getCapacity().forEach(k -> { - Assert.assertNotNull(k.getType()); - Assert.assertNotNull(k.getDisposeIp()); - }); - } - }); - } - - /** - * F 1 get multiple node run task normal test. - * - * @throws Exception the exception - */ - @Test - public void f1_getRunTaskMultipleNodesNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * F 2 get Node does not exist run task normal test. - * - * @throws Exception the exception - */ - @Test - public void f2_getRunTaskNoExitsNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * F 3 get running task msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void f3_getRunTaskEmptyMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * F 4 get running task msgContent null exception test. - * - * @throws Exception the exception - */ - @Test - public void f4_getRunTaskNullMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":null}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * F 5 get running task id null exception test. - * - * @throws Exception the exception - */ - @Test - public void f5_getRunTaskNullIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * F 6 get running task id does not exist "abc" exception test. - * - * @throws Exception the exception - */ - @Test - public void f6_getRunTaskIdNotExistExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - }); - } - - /** - * F 7 get running task array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void f7_getRunTaskArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * F 8 get running task Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void f8_getRunTaskArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * F 9 get running task Array contains repeated elements test. - * - * @throws Exception the exception - */ - @Test - public void f9_getRunTaskArrayContainsEmptyStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * G 1 get multiple node all task normal test. - * - * @throws Exception the exception - */ - @Test - public void g1_getAllTaskMultipleNodeNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getCurrentStatus()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * G 2 get node does not exits all task normal test. - * - * @throws Exception the exception - */ - @Test - public void g2_getAllTaskNodeNoExitsNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if(v.getStatus() == 19){ - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - }else if(v.getStatus() == 30){ - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - /** - * G 3 get all msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void g3_getAllTaskEmptyMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * G 4 get all msgContent null exception test. - * - * @throws Exception the exception - */ - @Test - public void g4_getAllTaskNullMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":null}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * G 5 get all task id null exception test. - * - * @throws Exception the exception - */ - @Test - public void g5_getAllTaskNullIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * G 6 get all task id "abd" exception test. - * - * @throws Exception the exception - */ - @Test - public void g6_getAllTaskNodeNoExitsNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - if (rspInfo.getItems().size() > 0) { - for (NodeTaskData taskData : rspInfo.getItems() - ) { - Assert.assertNotNull(taskData); - Assert.assertNotNull(taskData.getId()); - Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(taskData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - } - - /** - * G 7 get all task array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void g7_getAllTaskArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * G 8 get all task Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void g8_getAllTaskArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getCurrentStatus()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * G 9 get all task Array contains repeated elements test. - * - * @throws Exception the exception - */ - @Test - public void g9_getAllTaskArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getCurrentStatus()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * H 1 get node list normal test. "abd" - * - * @throws Exception the exception - */ - @Test - public void h1_getNodeListNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getName()); - Assert.assertNotNull(v.getIp()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - }else{ - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * H 2 get multiple node list normal test. "abd" - * - * @throws Exception the exception - */ - @Test - public void h2_getNodeListMultipleNodeNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getName()); - Assert.assertNotNull(v.getIp()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * H 3 get node does not exits list normal test. "abd" - * - * @throws Exception the exception - */ - @Test - public void h3_getNodeListNodeNotExistNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getName()); - Assert.assertNotNull(v.getIp()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * H 4 get node list msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void h4_getNodeListEmptyMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * H 5 get node list msgContent null exception test. - * - * @throws Exception the exception - */ - @Test - public void h5_getNodeListNullMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":null}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - /** - * H 6 get node list id null exception test. - * - * @throws Exception the exception - */ - @Test - public void h6_getNodeListNullIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * H 7 get node list id "abd" exception test. - * - * @throws Exception the exception - */ - @Test - public void h7_getNodeListErrorIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - List disposeNodeDataList = rspInfo.getItems(); - - Assert.assertEquals(disposeNodeDataList.size(), 1); - for (DisposeNodeData disposeNodeData : disposeNodeDataList - ) { - Assert.assertNotNull(disposeNodeData.getId()); - Assert.assertEquals(String.valueOf(disposeNodeData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(disposeNodeData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * H 8 get node list array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void h8_getNodeListArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * H 9 get node list Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void h9_getNodeListArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getName()); - Assert.assertNotNull(v.getIp()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - }); - } - - /** - * H 10 get node list Array contains repeated elements test. - * - * @throws Exception the exception - */ - @Test - public void h9_getNodeListArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getName()); - Assert.assertNotNull(v.getIp()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * I 1 get multiple Node Details Normal Test. - * - * @throws Exception the exception - */ - @Test - public void i1_getNodeDetailsMultipleNodeNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":" + - "\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getIp()); - Assert.assertNotNull(v.getCapacity()); - for (DisposeCapacity disposeCapacity : v.getCapacity() - ) { - Assert.assertNotNull(disposeCapacity.getType()); - Assert.assertNotNull(disposeCapacity.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * I 2 get Node does not exist Details Normal Test. - * - * @throws Exception the exception - */ - @Test - public void i2_getNodeDetailsNodeNotExistNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":" + - "\"{\\\"id\\\":[\\\"2\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getIp()); - Assert.assertNotNull(v.getCapacity()); - for (DisposeCapacity disposeCapacity : v.getCapacity() - ) { - Assert.assertNotNull(disposeCapacity.getType()); - Assert.assertNotNull(disposeCapacity.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * I 3 get Node does not exist Details Normal Test. - * - * @throws Exception the exception - */ - @Test - public void i3_getNodeDetailsNullMsgExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":null}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * I 4 get node details id null exception test. - * - * @throws Exception the exception - */ - @Test - public void i4_getNodeDetailsNullIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":" + - "\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * I 5 get node details id "abd" exception test. - * - * @throws Exception the exception - */ - @Test - public void i5_getNodeDetailsErrorIdExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":" + - "\"{\\\"id\\\":[\\\"abd\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - List disposeNodeDataList = rspInfo.getItems(); - - Assert.assertEquals(disposeNodeDataList.size(), 1); - for (DisposeNodeData disposeNodeData : disposeNodeDataList - ) { - Assert.assertNotNull(disposeNodeData.getId()); - Assert.assertEquals(String.valueOf(disposeNodeData.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(disposeNodeData.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * I 6 get node details array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void i6_getNodeDetailsArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * I 7 get node details Array contains empty string test. - * - * @throws Exception the exception - */ - @Test - public void i7_getNodeDetailsArrayContainsEmptyStringTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getIp()); - - Assert.assertNotNull(v.getCapacity()); - for (DisposeCapacity disposeCapacity : v.getCapacity() - ) { - Assert.assertNotNull(disposeCapacity.getType()); - Assert.assertNotNull(disposeCapacity.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - }); - } - - /** - * I 8 get node details Array contains repeated elements test. - * - * @throws Exception the exception - */ - @Test - public void i8_getNodeDetailsArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":" + - "\"{\\\"id\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - rspInfo.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(v.getType())); - Assert.assertNotNull(v.getIp()); - Assert.assertNotNull(v.getCapacity()); - for (DisposeCapacity disposeCapacity : v.getCapacity() - ) { - Assert.assertNotNull(disposeCapacity.getType()); - Assert.assertNotNull(disposeCapacity.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - }); - } - - /** - * Verify device id exists boolean. - * - * @param deviceId the device id - * @return the boolean - */ - public boolean verifyDeviceIdExists(String deviceId) { - boolean exists = false; - List decs = disposeNodeManager.getAllDisposeDevice(); - - if (decs != null && decs.size() > 0) { - for (DisposeDevice d : decs - ) { - if (String.valueOf(d.getId()).equals(deviceId)) { - exists = true; - break; - } - } - } - - return exists; - } - -} diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerSmokeTest.java b/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerSmokeTest.java deleted file mode 100644 index daf06d4a..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerSmokeTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.pojo.vo.information.DisposeNodeData; -import com.dispose.pojo.vo.information.DisposeNodeListRsp; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * The type Device node info controller smoke test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; - - /** - * A 1 get all task normal test. - * - * @throws Exception the exception - */ - @Test - public void a1_getAllTaskNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class) ; - - Assert.assertNotNull(rspInfo); - Assert.assertNotEquals(rspInfo.getItems().size(), 0); - - List taskList = disposeTaskMapper.getAllTaskByNodeDevId(1L); - Assert.assertEquals(Long.valueOf(rspInfo.getItems().get(0).getTaskArray().size()), Long.valueOf(taskList.size())); - - if(taskList.size() > 0) { - NodeTaskData taskData = rspInfo.getItems().get(0); - - Assert.assertNotNull(taskData); - Assert.assertNotNull(taskData.getId()); - Assert.assertNotNull(taskData.getStatus()); - Assert.assertNotNull(taskData.getMessage()); - - Assert.assertNotNull(taskData.getStatus()); - Assert.assertNotNull(taskData.getMessage()); - Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - - TaskInfoData taskInfoData = taskData.getTaskArray().get(0); - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getCurrentStatus()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - } - - /** - * A 2 get all task id null test. - * - * @throws Exception the exception - */ - @Test - public void a2_getAllTaskIdNullTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * A 3 get run task normal test. - * - * @throws Exception the exception - */ - @Test - public void a3_getRunTaskNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class) ; - - Assert.assertNotNull(rspInfo); - Assert.assertNotEquals(rspInfo.getItems().size(), 0); - - List taskList = disposeTaskMapper.getAllTaskByNodeDevId(1L).stream() - .filter(v -> Objects.equals(v.getCurrentStatus(), DisposeTaskStatus.TASK_RUNNING.getCode())) - .collect(Collectors.toList()); - - Assert.assertEquals(Long.valueOf(rspInfo.getItems().get(0).getTaskArray().size()), Long.valueOf(taskList.size())); - - if(taskList.size() > 0) { - NodeTaskData taskData = rspInfo.getItems().get(0); - - Assert.assertNotNull(taskData); - Assert.assertNotNull(taskData.getId()); - Assert.assertNotNull(taskData.getStatus()); - Assert.assertNotNull(taskData.getMessage()); - Assert.assertNotNull(taskData.getStatus()); - Assert.assertNotNull(taskData.getMessage()); - Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - - TaskInfoData taskInfoData = taskData.getTaskArray().get(0); - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - } - - /** - * C 1 get Node Details Normal Test. - * - * @throws Exception the exception - */ - @Test - public void c1_getNodeDetailsNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class); - - Assert.assertNotNull(rspInfo); - Assert.assertNotEquals(rspInfo.getItems().size(), 0); - - //DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(1L); - DisposeNodeData dpData = rspInfo.getItems().get(0); - - Assert.assertNotNull(dpData); - Assert.assertNotNull(dpData.getId()); - Assert.assertNotNull(dpData.getStatus()); - Assert.assertNotNull(dpData.getMessage()); - } - - /** - * C 2 get node details msg content empty test. - * - * @throws Exception the exception - */ - @Test - public void c2_getNodeDetailsMsgContentEmptyTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - -// DisposeNodeListRsp rspInfo = objectMapper.readValue(verifyResp(ret), DisposeNodeListRsp.class) ; -// List List = rspInfo.getItems(); -// -// for (DisposeNodeData r:List){ -// Assert.assertNotNull(r.getMessage()); -// Assert.assertNotNull(r.getStatus()); -// Assert.assertEquals(Long.valueOf(r.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); -// } - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - - } -} diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerTest.java b/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerTest.java deleted file mode 100644 index a54c863e..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeInfoControllerTest.java +++ /dev/null @@ -1,1173 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.vo.common.DisposeCapacity; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.information.DeviceCapacityData; -import com.dispose.pojo.vo.information.DeviceCapacityRsp; -import com.dispose.pojo.vo.information.DeviceInfoData; -import com.dispose.pojo.vo.information.DeviceInfoRsp; -import com.dispose.pojo.vo.information.DisposeNodeData; -import com.dispose.pojo.vo.information.DisposeNodeListRsp; -import com.dispose.pojo.vo.information.LinkStatusListRsp; -import com.dispose.pojo.vo.information.LinkStatusRsp; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.information.VersionListRsp; -import com.dispose.pojo.vo.information.VersionRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.service.UserAccountService; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -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.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * The type Device node info controller test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DeviceNodeInfoControllerTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - /** - * The User account service. - */ - @Resource - private UserAccountService userAccountService; - - /** - * The Dispose device manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - - - /** - * Gets exists device id. - * - * @return the exists device id - */ - private Long getExistsDeviceId() { - List dp = disposeDeviceMapper.selectAll(); - - if (dp != null && dp.size() > 0) { - return dp.get(0).getId(); - } - - return -1L; - } - - /** - * test Determine whether the Id exists.. - * - * @return boolean true-exists - */ - public boolean verifyDeviceIdExists(String deviceId) { - boolean exists = false; - List decs = disposeNodeManager.getAllDisposeDevice(); - - if (decs != null && decs.size() > 0) { - for (DisposeDevice d : decs - ) { - if (String.valueOf(d.getId()).equals(deviceId)) { - exists = true; - break; - } - } - } - - return exists; - } - - - /** - * T 1 get version. - * - * @throws Exception the exception - */ - @Test - public void t1_getVersion() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String ver = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(ver, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp); - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getStatus()); - Assert.assertNotNull(versionRsp.getMessage()); - - if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - /** - * T 1 get version all. - * - * @throws Exception the exception - */ - @Test - public void t1_getVersionAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String verAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(verAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - VersionListRsp versionListRsp = objectMapper.readValue(msgContent, VersionListRsp.class); - List verList = versionListRsp.getItems(); - - for (VersionRsp versionRsp : verList - ) { - Assert.assertNotNull(versionRsp); - Assert.assertNotNull(versionRsp.getId()); - Assert.assertNotNull(versionRsp.getStatus()); - Assert.assertNotNull(versionRsp.getMessage()); - - if (verifyDeviceIdExists(versionRsp.getId())) { - Assert.assertNotNull(versionRsp.getVersion()); - Assert.assertEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(versionRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(versionRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 2 get device info. - * - * @throws Exception the exception - */ - @Test - public void t2_getDeviceInfo() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String deviceInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(deviceInfo, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); - - List deviceInfoList = deviceInfoRsp.getItems(); - for (DeviceInfoData d : deviceInfoList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * 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(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String deviceInfoAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/deviceinfo") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(deviceInfoAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceInfoRsp deviceInfoRsp = objectMapper.readValue(msgContent, DeviceInfoRsp.class); - - List deviceInfoList = deviceInfoRsp.getItems(); - for (DeviceInfoData d : deviceInfoList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get device capacity. - * - * @throws Exception the exception - */ - @Test - public void t3_getDeviceCapacity() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String capacity = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(capacity, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(msgContent, DeviceCapacityRsp.class); - - List deviceCapacityList = deviceCapacityRsp.getItems(); - for (DeviceCapacityData d : deviceCapacityList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - if (d.getCapacity().size() > 0) { - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - /** - * 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(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String capacityAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/capacity") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(capacityAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(msgContent, DeviceCapacityRsp.class); - - List deviceCapacityList = deviceCapacityRsp.getItems(); - for (DeviceCapacityData d : deviceCapacityList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - if (d.getCapacity().size() > 0) { - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get device protected ip. - * - * @throws Exception the exception - */ - @Test - public void t4_getDeviceProtectedIp() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String protectedIp = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(protectedIp, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(msgContent, DeviceCapacityRsp.class); - - List deviceCapacityList = deviceCapacityRsp.getItems(); - for (DeviceCapacityData d : deviceCapacityList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - if (d.getCapacity().size() > 0) { - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - Assert.assertNotNull(cap.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get device protected ip all. - * - * @throws Exception the exception - */ - @Test - public void t4_getDeviceProtectedIpAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String protectedIpAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(protectedIpAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(msgContent, DeviceCapacityRsp.class); - - List deviceCapacityList = deviceCapacityRsp.getItems(); - for (DeviceCapacityData d : deviceCapacityList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - if (d.getCapacity().size() > 0) { - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - Assert.assertNotNull(cap.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get dispose node list. - * - * @throws Exception the exception - */ - @Test - public void t5_getDisposeNodeList() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String nodeList = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(nodeList, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DisposeNodeListRsp disposeNodeListRsp = objectMapper.readValue(msgContent, DisposeNodeListRsp.class); - - List disposeNodeDataList = disposeNodeListRsp.getItems(); - for (DisposeNodeData d : disposeNodeDataList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(String.valueOf(d.getType())); - Assert.assertNotNull(d.getIp()); - Assert.assertNotNull(d.getName()); - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get dispose node list all. - * - * @throws Exception the exception - */ - @Test - public void t5_getDisposeNodeListAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String nodeListAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_list") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(nodeListAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DisposeNodeListRsp disposeNodeListRsp = objectMapper.readValue(msgContent, DisposeNodeListRsp.class); - - List disposeNodeDataList = disposeNodeListRsp.getItems(); - for (DisposeNodeData d : disposeNodeDataList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(String.valueOf(d.getType())); - Assert.assertNotNull(d.getIp()); - Assert.assertNotNull(d.getName()); - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get dispose node details. - * - * @throws Exception the exception - */ - @Test - public void t6_getDisposeNodeDetails() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String disposeNodeDetails = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(disposeNodeDetails, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DisposeNodeListRsp nodeDetailsRsp = objectMapper.readValue(msgContent, DisposeNodeListRsp.class); - - List disposeNodeDataList = nodeDetailsRsp.getItems(); - for (DisposeNodeData d : disposeNodeDataList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(String.valueOf(d.getType())); - Assert.assertNotNull(d.getIp()); - Assert.assertNotNull(d.getName()); - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - Assert.assertNotNull(cap.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 get dispose node details all. - * - * @throws Exception the exception - */ - @Test - public void t6_getDisposeNodeDetailsAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String disposeNodeDetailsAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/node_details") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(disposeNodeDetailsAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为DeviceInfoRsp类 - DisposeNodeListRsp nodeDetailsRsp = objectMapper.readValue(msgContent, DisposeNodeListRsp.class); - - List disposeNodeDataList = nodeDetailsRsp.getItems(); - for (DisposeNodeData d : disposeNodeDataList - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - Assert.assertNotNull(String.valueOf(d.getType())); - Assert.assertNotNull(d.getIp()); - Assert.assertNotNull(d.getName()); - for (DisposeCapacity cap : d.getCapacity() - ) { - Assert.assertNotNull(cap.getType()); - Assert.assertNotNull(cap.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - @Test - public void t7_getLinkStatus() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String linkstatus = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(linkstatus, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, LinkStatusListRsp.class); - List linkStatusList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusList - ) { - Assert.assertNotNull(linkStatusRsp); - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getStatus())); - Assert.assertNotNull(linkStatusRsp.getMessage()); - - if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(Long.valueOf(linkStatusRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - Assert.assertNotEquals(Long.valueOf(linkStatusRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - @Test - public void t7_getLinkStatusAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String linkStatusAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/linkstatus") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(linkStatusAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - -// List linkStatusList = objectMapper.readValue(msgContent, new TypeReference>() { -// }); - LinkStatusListRsp linkStatusListRsp = objectMapper.readValue(msgContent, LinkStatusListRsp.class); - List linkStatusList = linkStatusListRsp.getItems(); - - for (LinkStatusRsp linkStatusRsp : linkStatusList - ) { - Assert.assertNotNull(linkStatusRsp); - Assert.assertNotNull(linkStatusRsp.getId()); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getOnline())); - Assert.assertNotNull(String.valueOf(linkStatusRsp.getStatus())); - Assert.assertNotNull(linkStatusRsp.getMessage()); - - if (verifyDeviceIdExists(linkStatusRsp.getId())) { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "1"); - Assert.assertEquals(Long.valueOf(linkStatusRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(linkStatusRsp.getOnline()), "0"); - Assert.assertNotEquals(Long.valueOf(linkStatusRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(linkStatusRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - @Test - public void t8_getNodeAllRunTask() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String runTask = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(runTask, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - NodeTaskRsp runTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List nodeTaskData = runTaskRsp.getItems(); - for (NodeTaskData d : nodeTaskData - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - // no task - if (d.getTaskArray().size() == 0) { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - - Assert.assertNotNull(d.getTaskArray()); - for (TaskInfoData task : d.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - @Test - public void t8_getNodeAllRunTaskAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String runTaskAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/run_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(runTaskAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - NodeTaskRsp runTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List nodeTaskData = runTaskRsp.getItems(); - for (NodeTaskData d : nodeTaskData - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - // no task - if (d.getTaskArray().size() == 0) { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - - Assert.assertNotNull(d.getTaskArray()); - for (TaskInfoData task : d.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - @Test - public void t9_getNodeAllTask() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{String.valueOf(getExistsDeviceId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - NodeTaskRsp allTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List allTaskData = allTaskRsp.getItems(); - for (NodeTaskData d : allTaskData - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - // no task - if (d.getTaskArray().size() == 0) { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - - Assert.assertNotNull(d.getTaskArray()); - for (TaskInfoData task : d.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getCurrentStatus()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - @Test - public void t9_getNodeAllTaskAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String allTaskAll = mockMvc.perform(MockMvcRequestBuilders - .post("/information/all_task") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(allTaskAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - NodeTaskRsp allTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List allTaskData = allTaskRsp.getItems(); - for (NodeTaskData d : allTaskData - ) { - Assert.assertNotNull(d); - Assert.assertNotNull(d.getId()); - Assert.assertNotNull(String.valueOf(d.getStatus())); - Assert.assertNotNull(d.getMessage()); - - if (verifyDeviceIdExists(d.getId())) { - // no task - if (d.getTaskArray().size() == 0) { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - - Assert.assertNotNull(d.getTaskArray()); - for (TaskInfoData task : d.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getCurrentStatus()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(d.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } -} diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java b/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java deleted file mode 100644 index 19a72c34..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerQATest.java +++ /dev/null @@ -1,720 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.dispose.pojo.vo.device.AddNodeRetData; -import com.dispose.pojo.vo.device.AddNodeRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -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; - -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class DeviceNodeManagerControllerQATest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose device manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - /** - * A 2 add device node msgContent empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a2_addDeviceNodeMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908,\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 3 add device node msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void a3_addDeviceNodeMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908,\"msgContent\":\"null\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 4 add device node type empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a4_addDeviceNodeTypeEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + - "\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," + - "\\\"type\\\":,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 5 add device node type string exception test. - * - * @throws Exception the exception - */ - @Test - public void a5_addDeviceNodeTypeStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + - "\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," + - "\\\"type\\\":\\\"abcd\\\",\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 6 add device node type null exception test. - * - * @throws Exception the exception - */ - @Test - public void a6_addDeviceNodeTypeNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":null,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRsp retStatus = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); - List r = retStatus.getItems(); - for (AddNodeRetData v : r - ) { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getIpAddr()); - Assert.assertNotNull(v.getDevId()); - Assert.assertNotNull(v.getMessage()); - Assert.assertNotNull(v.getStatus()); - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - } - - /** - * A 7 add device node ipAddr empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a7_addDeviceNodeIpAddrEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 8 add device node ipAddr null exception test. - * - * @throws Exception the exception - */ - @Test - public void a8_addDeviceNodeIpAddrNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":null," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRsp rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); - List r = rspInfo.getItems(); - - for (AddNodeRetData addNodeRetData:r - ) { - Assert.assertNotNull(addNodeRetData.getMessage()); - Assert.assertNotNull(addNodeRetData.getStatus()); - Assert.assertEquals(Long.valueOf(addNodeRetData.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - } - - - } - - /** - * A 10 add device node ver json exception test. - * - * @throws Exception the exception - */ - @Test - public void a10_addDeviceNodeVerJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 11 add device node ver null exception test. - * - * @throws Exception the exception - */ - @Test - public void a11_addDeviceNodeVerNullExceptionTest() throws Exception { - String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 12 add device node ver string exception test. - * - * @throws Exception the exception - */ - @Test - public void a12_addDeviceNodeVerStingChaExceptionTest() throws Exception { - String reqData = "{\"ver\":\"a\",\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 13 add device node ver string exception test. - * - * @throws Exception the exception - */ - @Test - public void a13_addDeviceNodeVerStingNumExceptionTest() throws Exception { - String reqData = "{\"ver\":\"1\",\"cryptoType\":0,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_VERSION.getCode())); - } - /** - * A 14 add device node crypto json exception test. - * - * @throws Exception the exception - */ - @Test - public void a14_addDeviceNodeCryptoJsonExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 15 add device node crypto null exception test. - * - * @throws Exception the exception - */ - @Test - public void a15_addDeviceNodeCryptoNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * A 16 add device node crypto string exception test. - * - * @throws Exception the exception - */ - @Test - public void a16_addDeviceNodeCryptoStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":\"a\",\"timeStamp\":1587628826908," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," + - "\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - /** - * B 2 del device node Msg Empty exception test. - * - * @throws Exception the exception - */ - @Test - public void b2_delDeviceNodeMsgEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * B 3 del device node msg null exception test. - * - * @throws Exception the exception - */ - @Test - public void b3_delDeviceNodeMsgNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":null}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * B 4 del device node id null exception test. - * - * @throws Exception the exception - */ - @Test - public void b4_delDeviceNodeIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - } - - /** - * B 5 del device node id int exception test. - * - * @throws Exception the exception - */ - @Test - public void b5_delDeviceNodeIdIntExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":123}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - IDReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), IDReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * B 6 del device node id empty exception test. - * - * @throws Exception the exception - */ - @Test - public void b6_delDeviceNodeIdEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":[]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - IDReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), IDReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * B 7 del device node id not exit exception test. - * - * @throws Exception the exception - */ - @Test - public void b7_delDeviceNodeIdNotExitExceptionTest() throws Exception { - //String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":[\\\"1\\\",\\\"666\\\"]}\"}"; - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":[\\\"555\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - //.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - List delNodeList = objectMapper.readValue(verifyResp(ret), new TypeReference>() {}); - - for (IDReturnStatus rspInfo : delNodeList) { - Assert.assertNotNull(rspInfo); - Assert.assertNotNull(rspInfo.getId()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - if (verifyDeviceIdExists(rspInfo.getId())) { - Assert.assertEquals(String.valueOf(rspInfo.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(String.valueOf(rspInfo.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - -// if (rspInfo.getStatus() == 0) { -// Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); -// Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_OK.getMsg()); -// } else if (rspInfo.getStatus() == 19) { -// Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); -// Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); -// } - - } - } - - /** - * B 8 del device node id string character exception test. - * - * @throws Exception the exception - */ - @Test - public void b8_delDeviceNodeIdStingChaExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":[\\\"bbb\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - IDReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), IDReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - /** - * Verify device id exists boolean. - * - * @param deviceId the device id - * @return the boolean - */ - public boolean verifyDeviceIdExists(String deviceId) { - boolean exists = false; - List decs = disposeNodeManager.getAllDisposeDevice(); - - if (decs != null && decs.size() > 0) { - for (DisposeDevice d : decs) { - if (String.valueOf(d.getId()).equals(deviceId)) { - exists = true; - break; - } - } - } - return exists; - } -} diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerSmokeTest.java b/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerSmokeTest.java deleted file mode 100644 index 7227e942..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerSmokeTest.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.dispose.pojo.vo.device.AddNodeRetData; -import com.dispose.pojo.vo.device.AddNodeRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -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; - -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class DeviceNodeManagerControllerSmokeTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose device manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - - /** - * test Determine whether the ipAddr exists. - */ - public MulReturnType verifyIpAddr(String ipAddr) { - MulReturnType ret; - boolean result = false; - DisposeDevice disposeDevice = disposeNodeManager.getDisposeDeviceByIp(ipAddr); - if (disposeDevice != null) { - result = true; - } - - ret = new MulReturnType<>(result, ipAddr); - return ret; - } - - /** - * test Determine whether the Id exists. - */ - public MulReturnType verifyId(String id) { - MulReturnType ret; - boolean result = false; - DisposeDevice disposeDevice = disposeNodeManager.getDisposeDeviceById(Long.valueOf(id)); - if (disposeDevice != null) { - result = true; - } - - ret = new MulReturnType<>(result, id); - return ret; - } - - /** - * A 1 add Normal DPTech DeviceNodeManager test. - * - * @throws Exception the exception - */ - @Test - public void a1_addNormalDPTechDeviceNodeManager() throws Exception { - String reqData = "{\"ver\": 2,\"cryptoType\": 0,\"timeStamp\": 1589437275258," + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," + - "\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," + - "\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," + - "\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\",\\\"userName\\\":\\\"admin\\\"," + - "\\\"password\\\":\\\"UMCAdministrator\\\"," + - "\\\"url\\\":\\\"http://%s/UMC/service/AbnormalFlowCleaningService\\\" }]}\"\n" + - "}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRsp retStatus = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); - List r = retStatus.getItems(); - for (AddNodeRetData v : r - ) { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getIpAddr()); - Assert.assertNotNull(v.getDevId()); - Assert.assertNotNull(v.getMessage()); - Assert.assertNotNull(v.getStatus()); - - if (v.getStatus() == 0) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else if (v.getStatus() == 20) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_DEVICEEXISTS.getCode())); - } - } - } - - /** - * A 2 add Normal HaoHan DeviceNodeManager test. - * - * @throws Exception the exception - */ - @Test - public void a2_addNormalHaoHanDeviceNodeManager() throws Exception { - String reqData = "{\n" + - "\"ver\": 2,\n" + - "\"cryptoType\": 0,\n" + - "\"timeStamp\": 1589437275258,\n" + - "\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.88:18080\\\"," + - "\\\"manufacturer\\\":\\\"HaoHan\\\",\\\"model\\\":\\\"Unknown\\\"," + - "\\\"name\\\":\\\"中移杭研实验室浩瀚清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":1," + - "\\\"version\\\":\\\"Unknown\\\",\\\"url\\\":\\\"http://%s/DDoSClean/clean\\\" }]}\"\n" + - "}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - AddNodeRsp retStatus = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class); - List r = retStatus.getItems(); - for (AddNodeRetData v : r - ) { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getIpAddr()); - Assert.assertNotNull(v.getDevId()); - Assert.assertNotNull(v.getMessage()); - Assert.assertNotNull(v.getStatus()); - - if (v.getStatus() == 0) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else if (v.getStatus() == 20) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_DEVICEEXISTS.getCode())); - } - } - } - - /** - * B 1 delete Normal DeviceNodeManager test. - * - * @throws Exception the exception - */ - @Test - public void b1_deleteNormalDeviceNodeManager() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - - List delNodeList = objectMapper.readValue(verifyResp(ret), new TypeReference>() { - }); - for (IDReturnStatus rspInfo : delNodeList) { - Assert.assertNotNull(rspInfo); - Assert.assertNotNull(rspInfo.getId()); - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - - if (rspInfo.getStatus() == 0) { - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else if (rspInfo.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - } - } - - } -} \ No newline at end of file diff --git a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerTest.java b/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerTest.java deleted file mode 100644 index 45c21c10..00000000 --- a/src/test/java/com/dispose/test/controller/DeviceNodeManagerControllerTest.java +++ /dev/null @@ -1,417 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ConstValue; -import com.dispose.common.DisposeDeviceType; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.pojo.po.NewNodeInfo; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.IDReturnStatus; -import com.dispose.pojo.vo.device.AddNodeReq; -import com.dispose.pojo.vo.device.AddNodeRetData; -import com.dispose.pojo.vo.device.AddNodeRsp; -import com.dispose.service.DisposeNodeManager; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * The type Device node manager controller test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class DeviceNodeManagerControllerTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose device manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - - /** - * test Determine whether the ipAddr exists. - */ - public MulReturnType verifyIpAddr(String ipAddr) { - MulReturnType ret; - boolean result = false; - DisposeDevice disposeDevice = disposeNodeManager.getDisposeDeviceByIp(ipAddr); - if (disposeDevice != null) { - result = true; - } - - ret = new MulReturnType<>(result, ipAddr); - return ret; - } - - /** - * test Determine whether the Id exists. - */ - public MulReturnType verifyId(String id) { - MulReturnType ret; - boolean result = false; - DisposeDevice disposeDevice = disposeNodeManager.getDisposeDeviceById(Long.valueOf(id)); - if (disposeDevice != null) { - result = true; - } - - ret = new MulReturnType<>(result, id); - return ret; - } - - /** - * T 1 add device. - * - * @throws Exception the exception - */ - @Test - public void t1_addDevice() throws Exception { - AddNodeReq addReq = AddNodeReq.builder() - .items(new ArrayList<>()) - .build(); - - addReq.getItems().add(NewNodeInfo.builder() - .ipAddr("10.88.77.15") - .type(DisposeDeviceType.DPTECH_UMC.getCode()) - .areaCode(0) - .name("中移杭研实验室清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .readme("实验室测试设备") - .build()); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(addReq)); - - List decsBef = disposeNodeManager.getAllDisposeDevice(); - - String deviceAdd = mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - List decsAfter = disposeNodeManager.getAllDisposeDevice(); - String msgContent = verifyRep(deviceAdd, reqTimeStamp); - System.out.println("msgContent=" + msgContent); - - //将json字符串转为AddNodeRsp类 - AddNodeRsp addNodeRsp = objectMapper.readValue(msgContent, AddNodeRsp.class); - - List addNodeList = addNodeRsp.getItems(); - for (AddNodeRetData d : addNodeList - ) { - //before: no device information after: device information exists - boolean before = false; - if (decsBef != null && decsBef.size() > 0) { - for (DisposeDevice v : decsBef) { - if (v.getIpAddr().equals(d.getIpAddr())) { - before = true; - break; - } - } - } - - boolean after = false; - if (decsAfter != null && decsAfter.size() > 0) { - for (DisposeDevice v : decsAfter) { - if (v.getIpAddr().equals(d.getIpAddr())) { - after = true; - break; - } - } - } - - Assert.assertNotNull(d.getIpAddr()); - Assert.assertNotNull(d.getDevId()); - if ((!before) && after) { - Assert.assertEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertNotEquals(Long.valueOf(d.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - } - } - - /** - * T 2 del device. - * - * @throws Exception the exception - */ - @Test - public void t2_delDevice() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{"1"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); - List decsBef = disposeNodeManager.getAllDisposeDevice(); - - String deviceDel = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - List decsAfter = disposeNodeManager.getAllDisposeDevice(); - - String msgContent = verifyRep(deviceDel, reqTimeStamp); - System.out.println("msgContent=" + msgContent); - - List delNodeList = objectMapper.readValue(msgContent, new TypeReference>() { - }); - - for (IDReturnStatus iDReturnStatus : delNodeList - ) { - //before: device information exists after: no device information - boolean before = false; - if (decsBef != null && decsBef.size() > 0) { - for (DisposeDevice v : decsBef) { - if (String.valueOf(v.getId()).equals(iDReturnStatus.getId())) { - before = true; - break; - } - } - } - - boolean after = false; - if (decsAfter != null && decsAfter.size() > 0) { - for (DisposeDevice v : decsAfter) { - if (String.valueOf(v.getId()).equals(iDReturnStatus.getId())) { - after = true; - break; - } - } - } - - Assert.assertNotNull(iDReturnStatus.getId()); - if (before && (!after)) { - Assert.assertEquals(Long.valueOf(iDReturnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } else { - Assert.assertNotEquals(Long.valueOf(iDReturnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - } - } - } - - /** - * T 3 del device err 1. - * - * @throws Exception the exception - */ - @Test - public void t3_delDeviceErr1() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{"0", "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)); - - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); - - String delAll = mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - System.out.println(delAll); - } - - @Test - public void t4_addDeviceBadHead() throws Exception { - AddNodeReq addReq = AddNodeReq.builder() - .items(new ArrayList<>()) - .build(); - - addReq.getItems().add(NewNodeInfo.builder() - .ipAddr("10.88.77.15") - .type(DisposeDeviceType.DPTECH_UMC.getCode()) - .areaCode(0) - .name("中移杭研实验室清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .readme("实验室测试设备") - .build()); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(1); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(addReq)); - - mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void t5_addDeviceBadAuth() throws Exception { - AddNodeReq addReq = AddNodeReq.builder() - .items(new ArrayList<>()) - .build(); - - addReq.getItems().add(NewNodeInfo.builder() - .ipAddr("10.88.77.15") - .type(DisposeDeviceType.DPTECH_UMC.getCode()) - .areaCode(0) - .name("中移杭研实验室清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .readme("实验室测试设备") - .build()); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(1); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(addReq)); - - mockMvc.perform(MockMvcRequestBuilders - .put("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken() + "dsasdfa") - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().is4xxClientError()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_LOGOUT.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void t6_delDeviceBadAuth() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{"1"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); - - mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken() + "1234") - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().is4xxClientError()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_LOGOUT.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } - - @Test - public void t6_delDeviceBadHead() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .id(new String[]{"1"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(1); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo)); - - mockMvc.perform(MockMvcRequestBuilders - .delete("/manager/device") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - } -} diff --git a/src/test/java/com/dispose/test/controller/TaskControllerQATest.java b/src/test/java/com/dispose/test/controller/TaskControllerQATest.java deleted file mode 100644 index ef9cd5eb..00000000 --- a/src/test/java/com/dispose/test/controller/TaskControllerQATest.java +++ /dev/null @@ -1,2041 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.task.StartTaskRsp; -import com.dispose.pojo.vo.task.TaskInfoRsp; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -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; - -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class TaskControllerQATest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - @Test - public void a1_NormalContainsNonEmptyTaskTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.4\\\", " + - "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + - "\\\"flowBandwidth\\\":1024}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (startTaskRsp.getStatus() == 26) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); - } else if (startTaskRsp.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - /** - * a2 disposeIp empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a2_startTaskDisPoseIpEmptyExceptionTest() throws Exception { - String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNoIp)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a3 disposeIp null exception test. - * - * @throws Exception the exception - */ - @Test - public void a3_startTaskDisposeIpNullExceptionTest() throws Exception { - //disposeIp null - String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNullIp)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a4 disposeIp Integer empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a4_startTaskDisposeIpIntegerExceptionTest() throws Exception { - String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":192345, \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataIntegerIp)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a5 id null exception test. - * - * @throws Exception the exception - */ - @Test - public void a5_startTaskIdNullExceptionTest() throws Exception { - String reqDataNullId = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":null," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNullId)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a6 type empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a6_startTaskTypeEmptyExceptionTest() throws Exception { - String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNoType)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * a7 type null exception test. - * - * @throws Exception the exception - */ - @Test - public void a7_startTaskTypeNullExceptionTest() throws Exception { //null type - String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNullType)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a8 disposeTime empty exception test. - * - * @throws Exception the exception - */ - @Test - public void a8_startTaskDisposeTimeEmptyExceptionTest() throws Exception { - //no disposeTime - String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNoDisposeTime)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * a9 disposeTime null exception test. - * - * @throws Exception the exception - */ - @Test - public void a9_startTaskDisposeTimeNullExceptionTest() throws Exception { - //null disposeTime - String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataNullDisposeTime)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a10 disposeTime String exception test. - * - * @throws Exception the exception - */ - @Test - public void a10_startTaskDisposeTimeStringExceptionTest() throws Exception { - //string disposeTime - String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":\\\"120\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataStringDisposeTime)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a11 id zero test. - * - * @throws Exception the exception - */ - @Test - public void a11_startTaskIdZeroTest() throws Exception { - String reqDataIdZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"0\\\"," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataIdZero)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - - /** - * a12 type error exception test. - * - * @throws Exception the exception - */ - @Test - public void a12_startTaskTypeErrorExceptionTest() throws Exception { - String reqDataTypeError = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":5, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataTypeError)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a13 disposeTime negative exception test. - * - * @throws Exception the exception - */ - @Test - public void a13_startTaskDisposeTimeNegativeExceptionTest() throws Exception { - //string disposeTime - String reqDataDisposeTimeNegative = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":-10}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqDataDisposeTimeNegative)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * a14 start dispose task Broadcast - * - * @throws Exception the exception - */ - @Test - public void a14_BroadcastNormalContainsNonEmptyTaskTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " + - "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + - "\\\"flowBandwidth\\\":1024}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (startTaskRsp.getStatus() == 26) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); - } - } - - /** - * a15 start dispose task Broadcast type negative. -1代表所有任务类型 清洗高防黑洞检测 - * - * @throws Exception the exception - */ - @Test - public void a15_broadCastStartTaskTypeNegativeExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":-1, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " + - "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + - "\\\"flowBandwidth\\\":1024}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (startTaskRsp.getStatus() == 26) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); - } - } - - /** - * a16 start dispose task Broadcast type negative. < -1 - * - * @throws Exception the exception - */ - @Test - public void a16_broadCastStartTaskTypeNegativeExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":-2, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " + - "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + - "\\\"flowBandwidth\\\":1024}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * b1 taskId empty exception test. 停止指定任务的时候必须指定id id不能为空字符串 - * - * @throws Exception the exception - */ - @Test - public void b1_stopTaskTaskIdEmptyStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * b2 taskId null exception test. - * - * @throws Exception the exception - */ - @Test - public void b2_stopTaskTaskIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * b3 stop task array contains null exception test. - * - * @throws Exception the exception - */ - @Test - public void b3_stopTaskArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", \\\"123\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * b4 stop task Array contains empty string exception test. taskId如果是空字符串,则参数错误 - * - * @throws Exception the exception - */ - @Test - public void b4_stopTaskArrayContainsEmptyStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * b5 stop task Array contains repeated elements test. 去重 - * - * @throws Exception the exception - */ - @Test - public void b5_stopTaskArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - /** - * b6 stop task Array sort test. 排序 - * - * @throws Exception the exception - */ - @Test - public void b6_stopTaskArraySortTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1411\\\", \\\"60\\\", \\\"2\\\", \\\"1142\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - /** - * b7 taskId int exception test. - * - * @throws Exception the exception - */ - @Test - public void b7_stopTaskTaskIdIntExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":1142}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * c1 id null exception test. - * - * @throws Exception the exception - */ - @Test - public void c1_stopTaskByIpIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":null,\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c2 id empty exception test. id需要指定 - * - * @throws Exception the exception - */ - @Test - public void c2_stopTaskByIpIdEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c3 disposeIp empty exception test. - * - * @throws Exception the exception - */ - @Test - public void c3_stopTaskByIpDisposeIpEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c4 disposeIp null exception test. - * - * @throws Exception the exception - */ - @Test - public void c4_stopTaskByIpDisposeIpNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0,\\\"disposeIp\\\":null}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c5 disposeIp "abc" exception test. - * - * @throws Exception the exception - */ - @Test - public void c5_stopTaskByIpDisposeIpErrorExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"abc\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c6 disposeIp Integer exception test. - * - * @throws Exception the exception - */ - @Test - public void c6_stopTaskByIpDisposeIpIntegerExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0,\\\"disposeIp\\\":123}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c7 type empty exception test. - * - * @throws Exception the exception - */ - @Test - public void c7_stopTaskByIpTypeEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * c8 type null exception test. - * - * @throws Exception the exception - */ - @Test - public void c8_stopTaskByIpTypeNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":null,\\\"disposeIp\\\":\\\"192.168.5.4\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c9 type negative exception test. - */ - @Test - public void c9_stopTaskByIpTypeNegativeExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":-5,\\\"disposeIp\\\":\\\"192.168.5.8\\\"}]}\"}"; - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopByIp), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * c10 normal stop tasks by dispose ip test. - */ - @Test - public void c10_NormalStopTasksByDisposeIpTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":-1,\\\"disposeIp\\\":\\\"192.168.3.3\\\"}, {\\\"id\\\":\\\"2\\\",\\\"type\\\":2,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}"; - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStopByIp), TaskInfoRsp.class); - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - /** - * d1 stop task by single node test. - */ - @Test - public void d1_NormalStopTaskByNodeTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * d2 stop task by two nodes test. - */ - @Test - public void d2_NormalStopTaskByNodesTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0}, {\\\"id\\\":\\\"471\\\",\\\"type\\\":0}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * d3 id empty exception test. - * - * @throws Exception the exception - */ - @Test - public void d3_stopTaskByNodeIdEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"\\\",\\\"type\\\":0}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * d4 id null exception test. - * - * @throws Exception the exception - */ - @Test - public void d4_stopTaskByNodeIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":null,\\\"type\\\":0}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * d5 type empty exception test. - * - * @throws Exception the exception - */ - @Test - public void d5_stopTaskByNodeTypeEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * d6 type null exception test. - * - * @throws Exception the exception - */ - @Test - public void d6_stopTaskByNodeTypeNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":null}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * d7 type string exception test. - * - * @throws Exception the exception - */ - @Test - public void d7_stopTaskByNodeTypeStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":\\\"abc\\\"}]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e1 stop task all test. - */ - @Test - public void e1_NormalStopAllTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * e2 stop task all test. - */ - @Test - public void e2_NormalStopAllTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":1}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * e3 stop task all test. - */ - @Test - public void e3_NormalStopAllTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":-1}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * e4 type empty exception test. - * - * @throws Exception the exception - */ - @Test - public void e4_stopTaskAllTypeEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * e5 type null exception test. - * - * @throws Exception the exception - */ - @Test - public void e5_stopTaskAllTypeNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * e6 type String exception test. - * - * @throws Exception the exception - */ - @Test - public void e6_stopTaskAllTypeStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":\\\"0\\\"}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * e7 type error exception test. - * - * @throws Exception the exception - */ - @Test - public void e7_stopTaskAllTypeErrorExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":6}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * f1 get node task of node test. - */ - @Test - public void f1_NormalGetNodeTaskInfoTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": [\\\"1\\\",\\\"123\\\"]," + - "\\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(nodeTaskRsp); - nodeTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (v.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } else if (v.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - /** - * f2 get node task id empty exception test.空表示所有能力节点 - */ - @Test - public void f2_NormalGetNodeTaskInfoIdTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": []," + - "\\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(nodeTaskRsp); - nodeTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (v.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } else if (v.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - /** - * f3 get node task type null exception test. - */ - @Test - public void f3_GetNodeTaskInfoTypeNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": [\\\"1\\\"]," + - "\\\"type\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * f4 get node task type empty exception test. - */ - @Test - public void f4_GetNodeTaskInfoTypeEmptyExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": [\\\"1\\\"]," + - "\\\"type\\\":}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - - /** - * f5 get node task Array contains null exception test .数组中有一个元素为null 参数错误 - */ - @Test - public void f5_GetNodeTaskInfoArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": [\\\"1\\\", null]," + - "\\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * f6 get node task Array contains empty string exception test .数组中有一个元素为空字符串表示所有能力节点 - */ - @Test - public void f6_GetNodeTaskInfoArrayContainsEmptyStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": " + - "[\\\"1\\\",\\\"2\\\",\\\"\\\"], \\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(nodeTaskRsp); - nodeTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (v.getStatus() == 19) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } else if (v.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - - /** - * f7 get node task Array contains Array contains repeated elements test . 结果去重 - */ - @Test - public void f7_GetNodeTaskInfoArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": " + - "[\\\"1\\\",\\\"1\\\",\\\"123\\\"], \\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(nodeTaskRsp); - nodeTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskArray()); - for (TaskInfoData taskInfoData : v.getTaskArray() - ) { - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getType()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getDisposeIp()); - } - - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (v.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - /** - * f8 get node task Array contains character test . - */ - @Test - public void f8_GetNodeTaskInfoArrayContainsCharacterTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": " + - "[\\\"1\\\",\\\"ab\\\",\\\"123\\\"], \\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); - - Assert.assertNotNull(nodeTaskRsp); - nodeTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - }); - } - - /** - * g1 get node detailed taskId empty exception test. 空字符串表示所有节点任务 - */ - @Test - public void g1_NormalGetNodeDetailedInfoTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - Assert.assertNotNull(startTaskRsp); - startTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskId()); - Assert.assertNotNull(v.getStartTime()); - Assert.assertNotNull(v.getDisposeTime()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - }); - } - - /** - * g2 get node detailed taskId null exception test . - */ - @Test - public void g2_GetNodeDetailedInfoTaskIdNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":null}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * g3 get node detailed info Array contains null exception test .数组中有一个元素为null 参数错误 - */ - @Test - public void g3_GetNodeDetailedInfoArrayContainsNullExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", null]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); - } - - /** - * g4 get node task Array contains empty string exception test .数组中有一个元素为空字符串表示所有能力节点 - */ - @Test - public void g4_GetNodeDetailedInfoArrayContainsEmptyStringExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", \\\"123\\\", \\\"\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - Assert.assertNotNull(startTaskRsp); - startTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getTaskId()); - Assert.assertNotNull(v.getStartTime()); - Assert.assertNotNull(v.getDisposeTime()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - }); - } - - /** - * g5 get node task Array contains Array contains repeated elements test . - */ - @Test - public void g5_GetNodeDetailedInfoArrayContainsRepeatedElementsTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"1\\\", \\\"1\\\", \\\"123\\\"]}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - Assert.assertNotNull(startTaskRsp); - startTaskRsp.getItems().forEach(v -> { - Assert.assertNotNull(v); - Assert.assertNotNull(v.getTaskId()); - Assert.assertNotNull(v.getStatus()); - Assert.assertNotNull(v.getMessage()); - - if (v.getStatus() == 0) { - Assert.assertNotNull(v.getId()); - Assert.assertNotNull(v.getStartTime()); - Assert.assertNotNull(v.getDisposeTime()); - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (v.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - }); - } - - /** - * g6 get node detailed taskId int exception test . - */ - @Test - public void g6_GetNodeDetailedInfoTaskIdIntExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":60}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(returnStatus.getStatus()); - Assert.assertNotNull(returnStatus.getMessage()); - Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } -} diff --git a/src/test/java/com/dispose/test/controller/TaskControllerSmokeTest.java b/src/test/java/com/dispose/test/controller/TaskControllerSmokeTest.java deleted file mode 100644 index cb4eabbe..00000000 --- a/src/test/java/com/dispose/test/controller/TaskControllerSmokeTest.java +++ /dev/null @@ -1,279 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.task.StartTaskRsp; -import com.dispose.pojo.vo.task.TaskInfoRsp; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -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; - -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class TaskControllerSmokeTest extends InitTestEnvironment { - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - @Test - public void t1_BroadcastNormalTaskTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"id\\\":-1," + - "\\\"type\\\":0, " + - "\\\"disposeIp\\\":\\\"192.168.5.8\\\", " + - "\\\"disposeTime\\\":120}\"}"; - - String taskStart = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStart), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (startTaskRsp.getStatus() == 26) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); - } - } - - @Test - public void t2_DesignatedDeviceNormalTaskTest() throws Exception { - - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"id\\\":1," + - "\\\"type\\\":0, " + - "\\\"disposeIp\\\":\\\"192.168.4.2\\\", " + - "\\\"disposeTime\\\":120}\"}"; - - String taskStart = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStart), StartTaskRsp.class); - - Assert.assertNotNull(startTaskRsp); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - System.out.println(startTaskRsp.getStatus()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (startTaskRsp.getStatus() == 26) { - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); - }else if(startTaskRsp.getStatus() == 19){ - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg()); - } - } - - - @Test - public void t3_NormalStopTaskTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"60\\\", \\\"2\\\" ]}\"}"; - - String taskStop = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStop), TaskInfoRsp.class); - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - - @Test - public void t4_NormalStopTaskByDisposeIpTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" + - "[{\\\"id\\\":\\\"1\\\",\\\"type\\\":0,\\\"disposeIp\\\":\\\"192.168.3.3\\\"}]}\"}"; - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStopByIp), TaskInfoRsp.class); - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - @Test - public void t5_NormalGetNodeDetailedInfoTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + - "\"msgContent\":\"{\\\"taskId\\\":[\\\"60\\\", \\\"2\\\"]}\"}"; - - String getNodeDetailedInfo = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(getNodeDetailedInfo), TaskInfoRsp.class); - - List taskInfoList = startTaskRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeTime()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (task.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - /** - * t6 stop all clean task test. - */ - @Test - public void t6_NormalStopAllCleanTaskTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":0}\"}"; - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(reqData)) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } -} diff --git a/src/test/java/com/dispose/test/controller/TaskControllerTest.java b/src/test/java/com/dispose/test/controller/TaskControllerTest.java deleted file mode 100644 index 9fbf07b9..00000000 --- a/src/test/java/com/dispose/test/controller/TaskControllerTest.java +++ /dev/null @@ -1,1037 +0,0 @@ -package com.dispose.test.controller; - -import com.dispose.common.ConstValue; -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.ErrorCode; -import com.dispose.common.FlowDirection; -import com.dispose.common.GlobalVar; -import com.dispose.common.IPAddrType; -import com.dispose.manager.TaskCacheManager; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.dispose.pojo.vo.common.TaskInfoData; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.pojo.vo.information.NodeTaskData; -import com.dispose.pojo.vo.information.NodeTaskRsp; -import com.dispose.pojo.vo.task.GetTaskReq; -import com.dispose.pojo.vo.task.StartTaskReq; -import com.dispose.pojo.vo.task.StartTaskRsp; -import com.dispose.pojo.vo.task.StopTaskData; -import com.dispose.pojo.vo.task.StopTaskReq; -import com.dispose.pojo.vo.task.TaskInfoRsp; -import com.dispose.service.TaskService; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * The type Task controller test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -@Slf4j -public class TaskControllerTest extends InitTestEnvironment { - @Resource - private MockMvc mockMvc; - - @Resource - private ObjectMapper objectMapper; - - @Resource - private TaskCacheManager taskCacheManager; - - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - @Resource - private TaskService taskService; - - private Long getExistsDeviceId() { - List lt = disposeDeviceMapper.selectAll(); - - if (lt != null && lt.size() > 0) { - return lt.get(0).getId(); - } - - return -1L; - } - - private Long getExistsTaskId() { - List lt = taskCacheManager.getAllRunningTask(); - - if (lt != null && lt.size() > 0) { - return lt.get(0).getId(); - } - - return -1L; - } - - private Long createRunTaskStart() { - TaskInfoDetail taskData = TaskInfoDetail.builder() - .id(-1L) - .deviceId(1L) - .accountId(1L) - .type(DeviceCapacity.CLEANUP.getCode()) - .disposeIp("192.168.5.3") - .attackType("0") - .flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode()) - .currentStatus(DisposeTaskStatus.TASK_NEW.getCode()) - .planEndTime("60") - .build(); - - taskService.createTask(taskData); - taskCacheManager.upgradeTaskStatus(taskData.getId(), DisposeTaskStatus.TASK_RUNNING.getCode()); - - return taskData.getId(); - } - - - /** - * T 1 start task. - * - * @throws Exception the exception - */ - @Test - public void t1_startTask() throws Exception { - StartTaskReq reqData = StartTaskReq.builder() - .id("-1") - .type(DeviceCapacity.CLEANUP.getCode()) - .disposeIp("192.168.3.4") - .disposeTime(60) - .build(); - - Assert.assertTrue(IPAddrType.isIpAddress("1.1.1.1")); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStart = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStart, reqTimeStamp); - System.out.println("msgContent=" + msgContent); - - //将json字符串转为StartTaskRsp类 - StartTaskRsp startTaskRsp = objectMapper.readValue(msgContent, StartTaskRsp.class); - Assert.assertNotNull(startTaskRsp.getStatus()); - Assert.assertNotNull(startTaskRsp.getMessage()); - - if (startTaskRsp.getStatus() == 0) { - Assert.assertNotNull(startTaskRsp.getId()); - Assert.assertNotNull(startTaskRsp.getTaskId()); - Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime())); - Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - /** - * T 2 a stop task. - * - * @throws Exception the exception - */ - @Test - public void t2a_stopTask() throws Exception { - Long taskId = createRunTaskStart(); - - IDArrayReq reqData = IDArrayReq.builder() - .taskId(new String[]{String.valueOf(taskId), "2"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStop = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStop, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 2 b stop task. - * - * @throws Exception the exception - */ - @Test - public void t2b_stopTask() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .taskId(new String[]{String.valueOf(getExistsTaskId()), "2"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStop = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStop, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 stop node ip task. - * - * @throws Exception the exception - */ - @Test - public void t3_stopNodeIpTask() throws Exception { - Long taskId = createRunTaskStart(); - String disposeIp = taskCacheManager.getTaskById(taskId).getDisposeIp(); - Long devId = taskCacheManager.getTaskById(taskId).getDeviceId(); - - StopTaskData itemData = StopTaskData.builder() - .disposeIp(disposeIp) - .type(DeviceCapacity.CLEANUP.getCode()) - .id(String.valueOf(devId)) - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByIp, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 b stop node ip task. - * - * @throws Exception the exception - */ - @Test - public void t3b_stopNodeIpTask() throws Exception { - StopTaskData itemData = StopTaskData.builder() - .disposeIp("192.168.1.1") - .type(DeviceCapacity.CLEANUP.getCode()) - .id("210") - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByIp, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == 0) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 a stop all node ip task. - * - * @throws Exception the exception - */ - @Test - public void t3a_stopAllNodeIpTask() throws Exception { - Long taskId = createRunTaskStart(); - String disposeIp = taskCacheManager.getTaskById(taskId).getDisposeIp(); - - StopTaskData itemData = StopTaskData.builder() - .disposeIp(disposeIp) - .type(DeviceCapacity.CLEANUP.getCode()) - .id("-1") - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByIp, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 3 b stop all node ip task. - * - * @throws Exception the exception - */ - @Test - public void t3b_stopAllNodeIpTask() throws Exception { - String devId; - - List devList = disposeDeviceMapper.selectAll(); - if (devList != null && devList.size() > 0) { - devId = devList.get(0).getId().toString(); - } else { - return; - } - - StopTaskData itemData = StopTaskData.builder() - .disposeIp("192.168.5.2") - .type(DeviceCapacity.CLEANUP.getCode()) - .id(devId) - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByIp, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - - /** - * T 4 a stop node task. - * - * @throws Exception the exception - */ - @Test - public void t4a_stopNodeTask() throws Exception { - Long taskId = createRunTaskStart(); - Long devId = taskCacheManager.getTaskById(taskId).getDeviceId(); - - StopTaskData itemData = StopTaskData.builder() - .type(DeviceCapacity.CLEANUP.getCode()) - .id(String.valueOf(devId)) - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByNode, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 4 b stop node task. - * - * @throws Exception the exception - */ - @Test - public void t4b_stopNodeTask() throws Exception { - StopTaskData itemData = StopTaskData.builder() - .type(DeviceCapacity.CLEANUP.getCode()) - .id("418") - .build(); - - StopTaskReq reqData = new StopTaskReq(); - - reqData.setItems(new ArrayList<>()); - reqData.getItems().add(itemData); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopByNode, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 5 a stop all task. - * - * @throws Exception the exception - */ - @Test - public void t5a_stopAllTask() throws Exception { - createRunTaskStart(); - - StopTaskData reqData = StopTaskData.builder() - .type(DeviceCapacity.CLEANUP.getCode()) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopAll = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 5 b stop all task. - * - * @throws Exception the exception - */ - @Test - public void t5b_stopAllTask() throws Exception { - StopTaskData reqData = StopTaskData.builder() - .type(DeviceCapacity.CLEANUP.getCode()) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String taskStopAll = mockMvc.perform(MockMvcRequestBuilders - .post("/task/stop_all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(taskStopAll, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskStopByIpRsp.getItems(); - for (TaskInfoData task : taskInfoList - ) { - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); - - if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); - Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 6 get node all task. - * - * @throws Exception the exception - */ - @Test - public void t6_getNodeAllTask() throws Exception { - GetTaskReq reqData = new GetTaskReq(); - reqData.setId(new String[]{String.valueOf(getExistsDeviceId()), "123"}); - reqData.setType(0); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - createRunTaskStart(); - - String getTask = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(getTask, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为NodeTaskRsp类 - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List taskInfoList = nodeTaskRsp.getItems(); - for (NodeTaskData taskNode : taskInfoList - ) { - Assert.assertNotNull(taskNode.getStatus()); - Assert.assertNotNull(taskNode.getMessage()); - - if (taskNode.getStatus() == 0) { - Assert.assertNotNull(taskNode.getId()); - Assert.assertNotNull(taskNode.getTaskArray()); - if (taskNode.getTaskArray().size() != 0) { - for (TaskInfoData task : taskNode.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - } - - Assert.assertEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 6 get node all task all. - * - * @throws Exception the exception - */ - @Test - public void t6_getNodeAllTaskAll() throws Exception { - GetTaskReq reqData = new GetTaskReq(); - reqData.setId(new String[]{}); - reqData.setType(0); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String getTask = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get_node") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(getTask, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为NodeTaskRsp类 - NodeTaskRsp nodeTaskRsp = objectMapper.readValue(msgContent, NodeTaskRsp.class); - - List taskInfoList = nodeTaskRsp.getItems(); - for (NodeTaskData taskNode : taskInfoList - ) { - Assert.assertNotNull(taskNode.getStatus()); - Assert.assertNotNull(taskNode.getMessage()); - - if (taskNode.getStatus() == 0) { - Assert.assertNotNull(taskNode.getId()); - Assert.assertNotNull(taskNode.getTaskArray()); - if (taskNode.getTaskArray().size() != 0) { - for (TaskInfoData task : taskNode.getTaskArray() - ) { - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getType()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getStartTime()); - Assert.assertNotNull(task.getDisposeIp()); - } - } - - Assert.assertEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertNotEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - } - - /** - * T 7 get all task. - * - * @throws Exception the exception - */ - @Test - public void t7_getAllTask() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .taskId(new String[]{String.valueOf(getExistsTaskId()), "123"}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String getTask = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(getTask, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskInfoRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskInfoRsp.getItems(); - for (TaskInfoData taskInfoData : taskInfoList - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getStatus()); - Assert.assertNotNull(taskInfoData.getMessage()); - - if (taskInfoData.getStatus() == 0) { - Assert.assertNotNull(taskInfoData.getId()); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } else if (taskInfoData.getStatus() == 30) { - Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); - Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); - } - } - } - - /** - * T 7 get all task all. - * - * @throws Exception the exception - */ - @Test - public void t7_getAllTaskAll() throws Exception { - IDArrayReq reqData = IDArrayReq.builder() - .taskId(new String[]{}) - .build(); - - Long reqTimeStamp = System.currentTimeMillis(); - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(reqTimeStamp); - reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); - - String getTask = mockMvc.perform(MockMvcRequestBuilders - .post("/task/get") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - String msgContent = verifyRep(getTask, reqTimeStamp); - System.out.print("msgContent=" + msgContent); - - //将json字符串转为TaskInfoRsp类 - TaskInfoRsp taskInfoRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class); - - List taskInfoList = taskInfoRsp.getItems(); - for (TaskInfoData taskInfoData : taskInfoList - ) { - Assert.assertNotNull(taskInfoData); - Assert.assertNotNull(taskInfoData.getId()); - Assert.assertNotNull(taskInfoData.getTaskId()); - Assert.assertNotNull(taskInfoData.getStartTime()); - Assert.assertNotNull(taskInfoData.getDisposeTime()); - Assert.assertNotNull(taskInfoData.getStatus()); - Assert.assertNotNull(taskInfoData.getMessage()); - Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); - Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_OK.getMsg()); - } - } - - - /** - * T 8 add task error test. - */ - @Test - public void t8_addTaskErrorTest() { - TaskInfoDetail taskData = TaskInfoDetail.builder() - .id(-1L) - .deviceId(1L) - .accountId(1L) - .type(DeviceCapacity.CLEANUP.getCode()) - .disposeIp("") - .attackType("0") - .flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode()) - .currentStatus(DisposeTaskStatus.TASK_NEW.getCode()) - .planEndTime("60") - .build(); - - Assert.assertEquals(taskCacheManager.addTask(null), ErrorCode.ERR_INPUTMISS); - Assert.assertEquals(taskCacheManager.addTask(taskData), ErrorCode.ERR_INPUTMISS); - - Long taskId = createRunTaskStart(); - taskData.setId(taskId); - taskData.setDisposeIp("1.1.1.1"); - Assert.assertEquals(taskCacheManager.addTask(taskData), ErrorCode.ERR_DEVICEEXISTS); - } - - /** - * T 8 upgrade task status error test. - */ - @Test - public void t8_upgradeTaskStatusErrorTest() { - Assert.assertEquals(taskCacheManager.upgradeTaskStatus(-123L, 3), ErrorCode.ERR_NOSUCHDEVICE); - } -} diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java deleted file mode 100644 index fa530463..00000000 --- a/src/test/java/com/dispose/test/debug/demo.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.dispose.test.debug; - -import com.dispose.common.IPAddrType; -import com.dispose.pojo.vo.common.IDArrayReq; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import inet.ipaddr.AddressStringException; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Test; - -/** - * The type Demo. - * - * @author - */ -@Slf4j -public class demo { - /** - * A 1 idid array req test. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void a1_IDIDArrayReqTest() throws JsonProcessingException { - String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}"; - String json2 = "{\"id\":[\"1\", \"123\", \"1234\"]}"; - String json3 = "{\"id\":[\"\", \"1\", \"123\", \"1234\"]}"; - //String json4 = "{\"id\":[\"1\", \"123\", \"1234\", null]}"; - - - IDArrayReq id = new ObjectMapper().readValue(json3, IDArrayReq.class); - Assert.assertEquals(id.getId().length, 1); - - id = new ObjectMapper().readValue(json2, IDArrayReq.class); - Assert.assertEquals(id.getId().length, 3); - - id = new ObjectMapper().readValue(json, IDArrayReq.class); - Assert.assertEquals(id.getId().length, 3); - - //id = new ObjectMapper().readValue(json4, IDArrayReq.class); - } - - /** - * A 2 ip range test. - * - * @throws AddressStringException the address string exception - */ - @Test - public void a2_ipRangeTest() throws AddressStringException { - Assert.assertTrue(IPAddrType.ipInRange("192.168.0.1-192.168.0.100", "192.168.0.30")); - Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30")); - Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40")); - Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30")); - Assert.assertTrue(IPAddrType.ipInRange("", "192.168.0.30")); - } -} diff --git a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java deleted file mode 100644 index 29efc693..00000000 --- a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.dispose.test.dptech; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DisposeDeviceType; -import com.dispose.common.ErrorCode; -import com.dispose.dispose.DeviceRouter; -import com.dispose.dispose.DisposeEntryManager; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.test.Global.InitTestEnvironment; -import com.dptech.dispose.DetectionObjectDataForService; -import com.dptech.dispose.ProtectionObjectDataForService; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -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 { - @Resource - private ObjectMapper objectMapper; - - /** - * User login. - */ - @Override - public void userLogin() { - } - - /** - * T 1 get all detection object from umc. - */ - @Test - public void t1_getAllDetectionObjectFromUMC() { - - try { - DisposeEntryManager dp = - DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); - - List detDevs = dp.getAllDetectionObject(); - - Assert.assertNotEquals(detDevs.size(), 0); - - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(detDevs)); - - } catch (Exception ex) { - Assert.fail(); - } - } - - /** - * T 2 get all protect devices. - */ - @Test - public void t2_getAllProtectDevices() { - - try { - DisposeEntryManager dp = - DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); - - String proDevs = dp.getProtectDevices(); - - Assert.assertNotEquals(proDevs.length(), 0); - - log.info("Protect Device: " + proDevs); - - } catch (Exception ex) { - Assert.fail(); - } - } - - /** - * T 3 get all protect objects. - */ - @Test - public void t3_getAllProtectObjects() { - - try { - DisposeEntryManager dp = - DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15"); - - List proObjs = dp.getAllProtectionObject(); - - Assert.assertNotEquals(proObjs.size(), 0); - - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(proObjs)); - - } catch (Exception ex) { - Assert.fail(); - } - } - - /** - * T 4 get link status. - */ - @Test - public void t4_getLinkStatus() { - - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), - "10.88.77.15"); - - Assert.assertTrue(dp.getDeviceLinkStatus()); - } - - /** - * T 5 get device capacity. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t5_getDeviceCapacity() throws JsonProcessingException { - - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), - "10.88.77.15"); - - List capList = dp.getDeviceCapacity(); - - Assert.assertNotEquals(capList.size(), 0); - - log.info(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(capList)); - } - - @Test - public void t6_runDisposeTest() { - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), - "10.88.77.15"); - - Assert.assertEquals(dp.runDispose("192.168.3.5", DeviceCapacity.CLEANUP, -1L).getFirstParam(), ErrorCode.ERR_OK); - } - - @Test - public void t7_stopDisposeTest() { - DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), - "10.88.77.15"); - - Assert.assertEquals(dp.stopDispose("192.168.3.5", DeviceCapacity.CLEANUP, -1L).getFirstParam(), ErrorCode.ERR_OK); - } -} diff --git a/src/test/java/com/dispose/test/exception/ExceptionTest.java b/src/test/java/com/dispose/test/exception/ExceptionTest.java deleted file mode 100644 index bebbbee6..00000000 --- a/src/test/java/com/dispose/test/exception/ExceptionTest.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.dispose.test.exception; - -import com.dispose.common.ConstValue; -import com.dispose.common.ErrorCode; -import com.dispose.common.GlobalVar; -import com.dispose.pojo.dto.ProtocolReqDTO; -import com.dispose.pojo.po.ReturnStatus; -import com.dispose.pojo.vo.auth.LoginReq; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -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; -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; - -/** - * The type Exception test. - */ -@AutoConfigureMockMvc -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -public class ExceptionTest extends InitTestEnvironment { - - /** - * The Expected ex. - */ - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - /** - * The Mock mvc. - */ - @Resource - private MockMvc mockMvc; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * T 1 input exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t1_inputException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - LoginReq logReq = null; - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/login") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * T 2 global exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t2_globalException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(null); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/protected_ip") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - - /** - * T 3 global exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t3_globalException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - String reqData = "{\"id\":null}"; - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(reqData); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * T 4 global exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t4_globalException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - String reqData = "{\"id\":1}"; - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(reqData); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/information/version") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - /** - * T 5 input exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t5_inputException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - LoginReq logReq = null; - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/auth/logout") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } - - - /** - * T 6 input exception. - * - * @throws Exception the exception - */ - @Test(expected = Throwable.class) - public void t6_inputException() throws Exception { - expectedEx.expect(Throwable.class); - expectedEx.expectMessage("Expected exception: java.lang.Throwable"); - - LoginReq logReq = null; - - ProtocolReqDTO reqInfo = new ProtocolReqDTO(); - reqInfo.setVer(ConstValue.Protocol.VERSION); - reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); - reqInfo.setTimeStamp(System.currentTimeMillis()); - reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); - - String ret = mockMvc.perform(MockMvcRequestBuilders - .post("/task/start") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) - .content(objectMapper.writeValueAsString(reqInfo))) - .andDo(print()).andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) - .andReturn() - .getResponse() - .getContentAsString(); - - ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); - - Assert.assertNotNull(rspInfo.getMessage()); - Assert.assertNotNull(rspInfo.getStatus()); - Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); - Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); - } -} \ No newline at end of file diff --git a/src/test/java/com/dispose/test/haohan/HaoHanErrorCode.java b/src/test/java/com/dispose/test/haohan/HaoHanErrorCode.java deleted file mode 100644 index f9ff97c7..00000000 --- a/src/test/java/com/dispose/test/haohan/HaoHanErrorCode.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.dispose.test.haohan; -/** - * The enum Error code. - * - * @author - */ -public enum HaoHanErrorCode { - /** - * Err ok error code. - */ - ERR_OK("成功"), - /** - * Err whitelist error code. - */ - ERR_WHITELIST("ip已存在清洗ip白名单中,不允许添加!"), - /** - * Err ip format error code. - */ - ERR_DISPOSEIPFORMAT("IP地址格式有误"), - /** - * Err ip format error code. - */ - ERR_DURATIONFORMAT("清洗时长参数格式不正确,请检查!"), - /** - * Err orderFrom format error code. - */ - ERR_ORDERFROMFORMA("厂家信息参数格式不正确,请检查!"), - /** - * Err cleanTaskId format error code. - */ - ERR_CLEANTASKIDFORMA("清洗任务id参数格式不正确,请检查!"), - /** - * Err no running task error code. - */ - ERR_NORUNNINGTASK("没有正在清洗的ip"), - /** - * Err task does not existed or task is running error code. - */ - ERR_TASKNOEND("请检查清洗任务是否存在或清洗状态是否为结束!"), - /** - * Err task does not existed error code. - */ - ERR_NOTASK("该清洗任务不存在!"), - ; - - private final String errMsg; - - HaoHanErrorCode(String msg) { - this.errMsg = msg; - } - - /** - * Gets msg. - * - * @return the msg - */ - public String getMsg() { - return errMsg; - } -} diff --git a/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java b/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java deleted file mode 100644 index e2069863..00000000 --- a/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java +++ /dev/null @@ -1,328 +0,0 @@ -package com.dispose.test.haohan; - -import com.dispose.common.GlobalVar; -import com.dispose.common.Http; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; - -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class HaoHanInterfaceTestCase extends InitTestEnvironment { - @Resource - private ObjectMapper objectMapper; - - @Override - public void userLogin(){ - } - - @Test - public void a1_sendTowWhitelistTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.1\",\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void a2_sendTowWhitelistContainsDurationTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.1\",\"duration\":20, \"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void a3_normalSendTowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.2\",\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(result.getCleanTaskId()); - } else { - Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - } - } - } - - @Test - public void a4_normalSendTowContainsDurationTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - Assert.assertNotNull(result.getCleanTaskId()); - } else { - Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - } - } - } - - @Test - public void a5_sendTowIpErrorTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.120\",\"duration\":20,\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DISPOSEIPFORMAT.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void a6_sendTowDurationErrorTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":\"20\",\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DURATIONFORMAT.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void a7_sendTowOrderFromErrorTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":123}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - - @Test - public void b1_delTowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - } - } - } - - @Test - public void b2_delTowCleanTaskIdErrorTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":\"105\",\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void b3_delTowOrderFromErrorTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":123}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void c1_allIpFlowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"orderFrom\":\"hangyan\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - for (allIpFlowData data : result.getData() - ) { - Assert.assertNotNull(data.getIp()); - } - } else { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NORUNNINGTASK.getMsg()); - } - } - } - - @Test - public void c2_allIpFlowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"orderFrom\":123}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class); - - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg()); - Assert.assertEquals(result.getState(), Integer.valueOf(1)); - } - } - - @Test - public void d1_cleanTaskFlowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":119}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - for (allIpFlowData data : result.getData() - ) { - Assert.assertNotNull(data.getIp()); - } - } else { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_TASKNOEND.getMsg()); - } - } - } - - @Test - public void d2_cleanTaskFlowTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":\"abc\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class); - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg()); - } - } - - @Test - public void e1_getCleanTaskStateTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":119}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - - Assert.assertNotNull(result); - if (result.getState() == 0) { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg()); - } else { - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NOTASK.getMsg()); - } - } - } - - @Test - public void e2_getCleanTaskStateTest() throws JsonProcessingException { - if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { - String jsonRequest = "{\"cleanTaskId\":\"adb\"}"; - String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class); - Assert.assertNotNull(result); - Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg()); - } - } -} - diff --git a/src/test/java/com/dispose/test/haohan/allIpFlowData.java b/src/test/java/com/dispose/test/haohan/allIpFlowData.java deleted file mode 100644 index 6ffd4860..00000000 --- a/src/test/java/com/dispose/test/haohan/allIpFlowData.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dispose.test.haohan; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class allIpFlowData { - String ip; //ip地址 - Double inFlow; //输入流量 - Integer inPackets; //输入包数 - Double outFlow; //输出流量 - Integer outPackets; //输出包数 -} diff --git a/src/test/java/com/dispose/test/haohan/allIpFlowResult.java b/src/test/java/com/dispose/test/haohan/allIpFlowResult.java deleted file mode 100644 index c42de6ce..00000000 --- a/src/test/java/com/dispose/test/haohan/allIpFlowResult.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dispose.test.haohan; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -public class allIpFlowResult { - private Integer state; - private String msg; - private List data; -} - diff --git a/src/test/java/com/dispose/test/haohan/sendTowResult.java b/src/test/java/com/dispose/test/haohan/sendTowResult.java deleted file mode 100644 index 9b88a354..00000000 --- a/src/test/java/com/dispose/test/haohan/sendTowResult.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dispose.test.haohan; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class sendTowResult { - private Integer state; - private String msg; - private Integer cleanTaskId; - private Integer cleanTaskState; -} diff --git a/src/test/java/com/dispose/test/huawei/ATICInterfaceTestCase.java b/src/test/java/com/dispose/test/huawei/ATICInterfaceTestCase.java deleted file mode 100644 index 6e8b6cdd..00000000 --- a/src/test/java/com/dispose/test/huawei/ATICInterfaceTestCase.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.dispose.test.huawei; - -import com.dispose.common.Http; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ATICInterfaceTestCase { - @Test - public void a1_authRequestTest() { - String jsonRequest = "{\"username\":\"test\",\"password\":\"BeiJing01@Lab3\"}"; - String svrReturn = Http.postJson("https://106.38.75.154:43443/rest/openapi/ddos/auth", - null, - jsonRequest); - - log.info("Server Return: [{}]", svrReturn); - Assert.assertNotNull(svrReturn); - Assert.assertNotEquals(svrReturn.length(), 0); - } -} diff --git a/src/test/java/com/dispose/test/manager/TaskInfoMapperTest.java b/src/test/java/com/dispose/test/manager/TaskInfoMapperTest.java deleted file mode 100644 index 28023b59..00000000 --- a/src/test/java/com/dispose/test/manager/TaskInfoMapperTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.dispose.test.manager; - -import com.dispose.common.ErrorCode; -import com.dispose.mapper.TaskInfoMapper; -import com.dispose.test.Global.InitTestEnvironment; -import lombok.extern.slf4j.Slf4j; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class TaskInfoMapperTest extends InitTestEnvironment { - @Resource - private TaskInfoMapper taskInfoMapper; - - @Override - public void userLogin() { - } - - @Test - public void a1_addNewTaskInfoTest() { - taskInfoMapper.addNewTaskInfo(152L, 1L, null, (long) ErrorCode.ERR_OK.getCode()); - taskInfoMapper.addNewTaskInfo(152L, 2L, 12L, (long) ErrorCode.ERR_OK.getCode()); - } -} diff --git a/src/test/java/com/dispose/test/manager/UserAccountManagerTest.java b/src/test/java/com/dispose/test/manager/UserAccountManagerTest.java deleted file mode 100644 index f8a5cb32..00000000 --- a/src/test/java/com/dispose/test/manager/UserAccountManagerTest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.dispose.test.manager; - -import com.dispose.common.ErrorCode; -import com.dispose.manager.UserAccountCacheManager; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.service.UserAccountService; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.security.NoSuchAlgorithmException; - -/** - * The type User account manager test. - */ -@RunWith(SpringRunner.class) -@Slf4j -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class UserAccountManagerTest extends InitTestEnvironment { - /** - * The constant userToken. - */ - private static String userToken; - /** - * The User account cache manager. - */ - @Resource - private UserAccountCacheManager userAccountCacheManager; - /** - * The User account service. - */ - @Resource - private UserAccountService userAccountService; - - /** - * User login. - * - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @Before - public void userLogin() throws NoSuchAlgorithmException { - MulReturnType ret = userAccountService.loginService(getUSER_NAME(), getPASSWORD()); - - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); - userToken = ret.getSecondParam(); - - Assert.assertNotNull(userToken); - Assert.assertNotEquals(userToken.length(), 0); - ret = userAccountService.loginService("xajhuang", "123456"); - - Assert.assertNotEquals(ret.getFirstParam(), ErrorCode.ERR_OK); - } - - /** - * T 1 permission test. - */ - @Test - public void t1_permissionTest() { - Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken), ErrorCode.ERR_OK); - Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken + "12345"), ErrorCode.ERR_LOGOUT); - } - - /** - * T 2 get username by token test. - */ - @Test - public void t2_getUsernameByTokenTest() { - Assert.assertEquals(userAccountCacheManager.getUsernameByToken(userToken), getUSER_NAME()); - Assert.assertNull(userAccountCacheManager.getUsernameByToken(userToken + "12345")); - } - - /** - * 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); - Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME() + "3213", userToken), - ErrorCode.ERR_LOGOUT); - Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken + "13245"), - ErrorCode.ERR_TOKENNOTFOUND); - Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME() + "3213", userToken + "13245"), - ErrorCode.ERR_LOGOUT); - } - - /** - * T 5 get cache user. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t5_getCacheUser() throws JsonProcessingException { - String userInfo = userAccountCacheManager.getCacheUser(); - - Assert.assertNotNull(userInfo); - 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); - Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME() + "abc"), 0); - } - - /** - * T 6 set usr pwd err times test. - */ - @Test - public void t6_setUsrPwdErrTimesTest() { - for (int i = 0; i < 6; i++) { - userAccountCacheManager.setUserPwdErrTimes(getUSER_NAME(), i); - Assert.assertEquals(userAccountCacheManager.getUsrPwdErrTimes(getUSER_NAME()), i); - } - - userAccountCacheManager.setUserPwdErrTimes(getUSER_NAME(), 0); - 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()); - userAccountCacheManager.cleanUserToken(getUSER_NAME() + "234"); - Assert.assertEquals(userAccountCacheManager.verifyToken(userToken), ErrorCode.ERR_LOGOUT); - } -} diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java deleted file mode 100644 index d60ef000..00000000 --- a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.dispose.test.mapper; - -import com.dispose.common.DisposeDeviceType; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.po.DisposeDeviceCapacity; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - -/** - * The type Dispose device mapper test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class DisposeDeviceMapperTest extends InitTestEnvironment { - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The Dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - /** - * T 1 add new dispose device. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t1_addNewDisposeDevice() throws JsonProcessingException { - Long devId = -1L; - DisposeDevice dev = new DisposeDevice(); - List devCaps = new ArrayList<>(); - dev.setId(devId); - dev.setIpAddr("10.88.77.15"); - dev.setType(DisposeDeviceType.DPTECH_UMC.getCode()); - dev.setName("中移杭研实验室清洗设备"); - dev.setManufacturer("DPTech"); - dev.setModel("UMC"); - dev.setVersion("5.7.13"); - dev.setReadme("实验室测试设备"); - dev.setAreaCode(0); - dev.setDevCaps(devCaps); - - disposeDeviceMapper.addNewDisposeDevice(dev); - - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); - - Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(dev.getIpAddr()), 0); - - List dp = disposeDeviceMapper.selectAll(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - } - - /** - * T 2 is device exists by ip. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t2_isDeviceExistsByIp() throws JsonProcessingException { - List dp = disposeDeviceMapper.selectAll(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - - dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0)); - } - - /** - * T 3 is device exists by id. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t3_isDeviceExistsById() throws JsonProcessingException { - List dp = disposeDeviceMapper.selectAll(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - - dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0)); - } - - /** - * T 4 get device exists by ip. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t4_getDeviceExistsByIp() throws JsonProcessingException { - List dp = disposeDeviceMapper.selectAll(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - - dp.forEach(v -> { - DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(v.getIpAddr()); - Assert.assertNotNull(dp); - Assert.assertEquals(dev.getIpAddr(), v.getIpAddr()); - }); - } - - /** - * T 5 get device exists by id. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t5_getDeviceExistsById() throws JsonProcessingException { - List dp = disposeDeviceMapper.selectAll(); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); - - dp.forEach(v -> { - DisposeDevice dev = disposeDeviceMapper.getDeviceById(v.getId()); - Assert.assertNotNull(dp); - Assert.assertEquals(dev.getId(), v.getId()); - }); - } - - -// @Test -// public void t0_delDisposeDeviceByIp() throws JsonProcessingException { -// String ipAddr = "10.88.77.15"; -// disposeDeviceMapper.delDisposeDeviceByIp(ipAddr); -// -// List dp = disposeDeviceMapper.selectAll(); -// log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp)); -// dp.forEach(v -> { -// if (v.getIpAddr().equals(ipAddr)) { -// Assert.fail(); -// } -// }); -// } - - /** - * T 6 get dispose device by ip is not existed. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t6_getDeviceNotExistsByIp() throws JsonProcessingException { - String ipAddr = "10.88.77.16"; - DisposeDevice dev = disposeDeviceMapper.getDeviceByIp(ipAddr); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); - Assert.assertNull(dev); - } - - /** - * T 7 get device exists by id is not existed. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t7_getDeviceNotExistsById() throws JsonProcessingException { - Long devId = -1L; - DisposeDevice dev = disposeDeviceMapper.getDeviceById(devId); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev)); - Assert.assertNull(dev); - } - - /** - * T 8 is device exists by ip is not existed. - */ - @Test - public void t8_isDeviceNotExistsByIp() { - String ipAddr = "10.88.77.16"; - Assert.assertEquals(disposeDeviceMapper.isDeviceExistsByIp(ipAddr), 0); - } - - /** - * T 9 is device exists by id is not existed. - */ - @Test - public void t9_isDeviceNotExistsById() { - Long devId = -1L; - Assert.assertEquals(disposeDeviceMapper.isDeviceExistsById(devId), 0); - } -} - - - diff --git a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java deleted file mode 100644 index 01a7b840..00000000 --- a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java +++ /dev/null @@ -1,278 +0,0 @@ -package com.dispose.test.mapper; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.FlowDirection; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.mapper.UserAccountMapper; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -/** - * The type Dispose task mapper test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Slf4j -@Transactional -@Rollback -public class DisposeTaskMapperTest extends InitTestEnvironment { - /** - * The Obj mapper. - */ - @Resource - private ObjectMapper objMapper; - - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; - - /** - * The User account mapper. - */ - @Resource - private UserAccountMapper userAccountMapper; - - /** - * The Dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - /** - * The Device id. - */ - private Long deviceId; - - /** - * The Account id. - */ - private Long accountId; - - - /** - * User login. - */ - @Override - public void userLogin() { - deviceId = disposeDeviceMapper.selectAll().get(0).getId(); - accountId = userAccountMapper.selectAll().get(0).getId(); - } - - /** - * Add new task test. - */ - @Test - public void t1_addNewTaskTest() { - TaskInfoDetail taskData = TaskInfoDetail.builder() - .id(-1L) - .deviceId(deviceId) - .accountId(accountId) - .type(DeviceCapacity.CLEANUP.getCode()) - .disposeIp("192.168.0.1") - .attackType("0") - .flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode()) - .currentStatus(DisposeTaskStatus.TASK_NEW.getCode()) - .planEndTime("60") - .build(); - - disposeTaskMapper.addNewTask(taskData); - - Assert.assertNotEquals(java.util.Optional.ofNullable(taskData.getId()), -1L); - Assert.assertNotNull(disposeTaskMapper.getTaskById(taskData.getId())); - } - -// @Test -// public void t99_removeTaskTest() { -// disposeTaskMapper.selectAll().forEach(v -> { -// disposeTaskMapper.removeTaskById(v.getId()); -// Assert.assertNull(disposeTaskMapper.getTaskById(v.getId())); -// }); -// } - - /** - * T 2 change task status test. - */ - @Test - public void t2_changeTaskStatusTest() { - disposeTaskMapper.selectAll().forEach(v -> { - for (DisposeTaskStatus k : DisposeTaskStatus.values()) { - disposeTaskMapper.changeTaskCurrentStatus(v.getId(), k.getCode()); - Assert.assertEquals(disposeTaskMapper.getTaskCurrentStatus(v.getId()), k.getCode()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - } - }); - } - - /** - * T 3 get task info by id test. - */ - @Test - public void t3_getTaskInfoByIdTest() { - disposeTaskMapper.selectAll().forEach(v -> { - TaskInfoDetail taskInfo = disposeTaskMapper.getTaskById(v.getId()); - Assert.assertNotNull(taskInfo); - Assert.assertEquals(taskInfo.getId(), v.getId()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfo)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - }); - } - - /** - * T 4 get all task by dispose ip test. - */ - @Test - public void t4_getAllTaskByDisposeIpTest() { - Assert.assertNotNull(disposeTaskMapper.selectAll()); - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getAllTaskByDisposeIp(v.getDisposeIp()) - .forEach(k -> { - Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 5 get all task by node dev id test. - */ - @Test - public void t5_getAllTaskByNodeDevIdTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getAllTaskByNodeDevId(v.getDeviceId()) - .forEach(k -> { - Assert.assertEquals(k.getDeviceId(), v.getDeviceId()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 6 get node all task by user id test. - */ - @Test - public void t6_getNodeAllTaskByUserIdTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getNodeAllTaskByUserId(v.getAccountId()) - .forEach(k -> { - Assert.assertEquals(k.getAccountId(), v.getAccountId()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 7 get node task by ip and status test. - */ - @Test - public void t7_getNodeTaskByIpAndStatusTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getNodeTaskByIpAndStatus(v.getDeviceId(), v.getDisposeIp(), v.getCurrentStatus()) - .forEach(k -> { - Assert.assertEquals(k.getAccountId(), v.getAccountId()); - Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp()); - Assert.assertEquals(k.getCurrentStatus(), v.getCurrentStatus()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 8 get all task by status test. - */ - @Test - public void t8_getAllTaskByStatusTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getAllTaskByStatus(v.getCurrentStatus()) - .forEach(k -> { - Assert.assertEquals(k.getCurrentStatus(), v.getCurrentStatus()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 9 get task by task information test. - */ - @Test - public void t9_getTaskByTaskInfoTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getTaskByTaskDetail(v.getDeviceId(),v.getAccountId(),v.getDisposeIp(),v.getType()) - .forEach(k -> { - Assert.assertEquals(k.getDeviceId(), v.getDeviceId()); - Assert.assertEquals(k.getAccountId(), v.getAccountId()); - Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp()); - Assert.assertEquals(k.getType(),v.getType()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } - - /** - * T 10 get task by type test. - */ - @Test - public void t10_getTaskByTypeTest() { - disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper - .getAllTaskByType(v.getType()) - .forEach(k -> { - Assert.assertEquals(k.getType(),v.getType()); - try { - log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k)); - } catch (JsonProcessingException e) { - e.printStackTrace(); - Assert.fail(); - } - })); - } -} diff --git a/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java b/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java deleted file mode 100644 index 890aa7f6..00000000 --- a/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.dispose.test.mapper; - -import com.dispose.common.DeviceCapacity; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.mapper.TaskInfoMapper; -import com.dispose.pojo.entity.DisposeDevice; -import com.dispose.pojo.vo.common.TaskInfo; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.List; - -/** - * The type task information mapper test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class TaskInfoMapperTest extends InitTestEnvironment { - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - - /** - * The task information mapper. - */ - @Resource - private TaskInfoMapper taskInfoMapper; - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; - /** - * The Dispose device mapper. - */ - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - /** - * T 1 add new task information. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t1_addNewTaskInfo() throws JsonProcessingException { - Long beginTime = null; - Long endTime = null; - Long taskId = null; - - DisposeDevice dev = disposeDeviceMapper.getDeviceByIp("10.88.77.15"); - List taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode()); - for (TaskInfoDetail task : taskInfoDetailList - ) { - if (task.getDeviceId().equals(dev.getId())) { - taskId = task.getId(); - log.info("taskId:{}", taskId); - break; - } - } - - TaskInfo taskInfo = TaskInfo.builder() - .id(-1L) - .taskId(taskId) - .deviceId(dev.getId()) - .externId(null) - .status(0L) - .beginTime(String.valueOf(beginTime)) - .endTime(String.valueOf(endTime)) - .build(); - - taskInfoMapper.addNewTaskInfo(taskInfo.getTaskId(), taskInfo.getDeviceId(), taskInfo.getExternId(), taskInfo.getStatus()); - - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfo)); - - List taskInfoList = taskInfoMapper.getTaskInfoByTaskId(taskInfo.getTaskId()); - - if (taskInfoList.size() > 0) { - Assert.assertNotEquals(taskInfoList.size(), 0); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfoList)); - } - } - - /** - * T 2 get task information by taskId. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t2_getTaskInfoByTaskId() throws JsonProcessingException { - List taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode()); - if (taskInfoDetailList.size() > 0) { - for (TaskInfoDetail task : taskInfoDetailList - ) { - log.info("taskId:{}", task.getId()); - List taskInfoList = taskInfoMapper.getTaskInfoByTaskId(task.getId()); - if (taskInfoList.size() > 0) { - Assert.assertNotEquals(taskInfoList.size(), 0); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfoList)); - } - } - } - } - - /** - * T 3 get task information by taskId and deviceId. - * - * @throws JsonProcessingException the json processing exception - */ - @Test - public void t3_getTaskInfo() throws JsonProcessingException { - List taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode()); - if (taskInfoDetailList.size() > 0) { - for (TaskInfoDetail task : taskInfoDetailList - ) { - log.info("taskId-->{}, deviceId-->{}", task.getId(), task.getDeviceId()); - TaskInfo taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId()); - if (taskInfo != null) { - Assert.assertNotNull(taskInfo); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfo)); - } - } - } - } - - /** - * T 4 change Task Information Status. - */ - @Test - public void t4_changeTaskInfoStatus() { - List taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode()); - - if (taskInfoDetailList.size() > 0) { - for (TaskInfoDetail task : taskInfoDetailList - ) { - log.info("taskId-->{}", task.getId()); - List taskInfoList = taskInfoMapper.getTaskInfoByTaskId(task.getId()); - - if (taskInfoList.size() > 0) { - Assert.assertNotEquals(taskInfoList.size(), 0); - - for (TaskInfo taskInfo : taskInfoList - ) { - Assert.assertNotNull(taskInfo.getStatus()); - Long beforeStatus = taskInfo.getStatus(); - long changeStatus = 0; - if (beforeStatus == 0) { - changeStatus = 1L; - } - - log.info("task_info table Id-->{}, before Status-->{}, change Stauts-->{}", - taskInfo.getId(), taskInfo.getStatus(), changeStatus); - - taskInfoMapper.changeTaskInfoStatus(taskInfo.getId(), changeStatus); - Assert.assertNotEquals(beforeStatus, new Long(taskInfoMapper.getTaskInfoCurrentStatus(taskInfo.getId()))); - } - } - } - } - } - - - /** - * T 5 del task information by deviceId. - */ - @Test - public void t5_removeTaskInfoById() { - List taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode()); - if (taskInfoDetailList.size() > 0) { - for (TaskInfoDetail task : taskInfoDetailList - ) { - log.info("taskId:{}", task.getId()); - TaskInfo taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId()); - if (taskInfo != null) { - Assert.assertNotNull(taskInfo); - - taskInfoMapper.removeTaskInfoById(task.getDeviceId()); - taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId()); - Assert.assertNull(taskInfo); - } - } - } - } -} - - - - - diff --git a/src/test/java/com/dispose/test/service/DisposeNodeManagerTest.java b/src/test/java/com/dispose/test/service/DisposeNodeManagerTest.java deleted file mode 100644 index 1c95e748..00000000 --- a/src/test/java/com/dispose/test/service/DisposeNodeManagerTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.dispose.test.service; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.ErrorCode; -import com.dispose.mapper.DisposeDeviceMapper; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.service.DisposeNodeManager; -import com.dispose.test.Global.InitTestEnvironment; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -/** - * The type Dispose node manager test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class DisposeNodeManagerTest extends InitTestEnvironment { - /** - * The Used ip addr. - */ - private final String[] usedIpAddr = new String[]{"192.168.3.2", "192.168.3.4", - "192.168.5.8", "192.168.5.10", - "192.168.4.2", "192.168.4.5"}; - /** - * The Un used ip addr. - */ - private final String[] unUsedIpAddr = new String[]{"192.168.3.1", "192.168.3.6", - "192.168.6.8", "192.168.6.10", "255.255.255.255"}; - /** - * The Object mapper. - */ - @Resource - private ObjectMapper objectMapper; - /** - * The Dispose node manager. - */ - @Resource - private DisposeNodeManager disposeNodeManager; - - @Resource - private DisposeDeviceMapper disposeDeviceMapper; - - /** - * User login. - */ - @Override - public void userLogin() { - disposeNodeManager.loadDisposeNodeFromDatabase(); - } - - /** - * T 1 get dispose device test. - */ - @Test - public void t1_getDisposeDeviceTest() throws JsonProcessingException { - - for (String s : usedIpAddr) { - log.info("Test:{} --> {}", s, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( - disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP) - )); - - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( - disposeNodeManager.getAllDisposeDevice() - )); - Assert.assertNotNull(disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP)); - } - - for (String s : unUsedIpAddr) { - log.info("Test:{} --> {}", s, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( - disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP) - )); - Assert.assertEquals(disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP).size(), 0); - } - } - - /** - * T 2 load dispose node from db test. - */ - @Test - public void t2_loadDisposeNodeFromDbTest() { - Assert.assertNotEquals(disposeNodeManager.getAllDisposeDevice().size(), 0); - } - - @Test - public void t3_addNewDisposeDeviceTest() { - disposeDeviceMapper.selectAll().forEach(v -> { - MulReturnType ret = disposeNodeManager.addNewDisposeDevice(v); - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_DEVICEEXISTS); - }); - } - - @Test - public void t4_cleanupDisposeNodeCacheTest() { - if(disposeDeviceMapper.selectAll().size() > 0) { - Assert.assertNotEquals(disposeNodeManager.getAllDisposeDevice().size(), 0); - disposeNodeManager.cleanupDisposeNodeCache(); - Assert.assertEquals(disposeNodeManager.getAllDisposeDevice().size(), 0); - } else { - Assert.assertEquals(disposeNodeManager.getAllDisposeDevice().size(), 0); - disposeNodeManager.cleanupDisposeNodeCache(); - } - } - - @Test - public void t5_delDisposeDeviceByIpTest() { - disposeDeviceMapper.selectAll().forEach(v -> { - ErrorCode ret = disposeNodeManager.delDisposeDeviceByIp(v.getIpAddr()); - Assert.assertEquals(ret, ErrorCode.ERR_OK); - }); - } - - @Test - public void t6_delDisposeDeviceErrorTest() { - ErrorCode ret = disposeNodeManager.delDisposeDeviceById(-133L); - Assert.assertEquals(ret, ErrorCode.ERR_NOSUCHDEVICE); - - ret = disposeNodeManager.delDisposeDeviceByIp("255.255.255.255"); - Assert.assertEquals(ret, ErrorCode.ERR_NOSUCHDEVICE); - } - - @Test - public void t7_getDisposeDeviceByIpTest() { - disposeDeviceMapper.selectAll().forEach(v -> Assert.assertNotNull(disposeNodeManager.getDisposeDeviceByIp(v.getIpAddr()))); - } -} diff --git a/src/test/java/com/dispose/test/service/TaskServiceTest.java b/src/test/java/com/dispose/test/service/TaskServiceTest.java deleted file mode 100644 index 9b53b9c2..00000000 --- a/src/test/java/com/dispose/test/service/TaskServiceTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.dispose.test.service; - -import com.dispose.common.DeviceCapacity; -import com.dispose.common.DisposeTaskStatus; -import com.dispose.common.ErrorCode; -import com.dispose.common.FlowDirection; -import com.dispose.mapper.DisposeTaskMapper; -import com.dispose.pojo.vo.common.TaskInfoDetail; -import com.dispose.service.TaskService; -import com.dispose.test.Global.InitTestEnvironment; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -/** - * The type Task service test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@Transactional -@Rollback -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TaskServiceTest extends InitTestEnvironment { - /** - * The Task service. - */ - @Resource - private TaskService taskService; - - /** - * The Dispose task mapper. - */ - @Resource - private DisposeTaskMapper disposeTaskMapper; - - /** - * User login. - */ - @Override - public void userLogin() throws Exception { - super.userLogin(); - - TaskInfoDetail taskData = TaskInfoDetail.builder() - .id(-1L) - .deviceId(1L) - .accountId(1L) - .type(DeviceCapacity.CLEANUP.getCode()) - .disposeIp("192.168.5.3") - .attackType("0") - .flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode()) - .currentStatus(DisposeTaskStatus.TASK_NEW.getCode()) - .planEndTime("60") - .build(); - - taskService.createTask(taskData); - } - - /** - * T 2 start task test. - */ - @Test - public void t1_startTaskTest() { - disposeTaskMapper.getAllTaskByStatus(DisposeTaskStatus.TASK_NEW.getCode()).forEach(v -> { - ErrorCode err = taskService.startTask(v.getId()); - Assert.assertEquals(err, ErrorCode.ERR_OK); - - int currentStatus = disposeTaskMapper.getTaskCurrentStatus(v.getId()); - log.info("current status:{}", currentStatus); - Assert.assertEquals(currentStatus, DisposeTaskStatus.TASK_RUNNING.getCode()); - }); - } - - /** - * T 2 stop task test. - */ - @Test - public void t2_stopTaskTest() { - t1_startTaskTest(); - disposeTaskMapper.getAllTaskByStatus(DisposeTaskStatus.TASK_RUNNING.getCode()).forEach(v -> { - ErrorCode err = taskService.stopTask(v.getId()); - Assert.assertEquals(err, ErrorCode.ERR_OK); - - int currentStatus = disposeTaskMapper.getTaskCurrentStatus(v.getId()); - log.info("current status:{}", currentStatus); - Assert.assertEquals(currentStatus, DisposeTaskStatus.TASK_FINISH.getCode()); - - taskService.finishTask(v.getId()); - Assert.assertNotNull(taskService.getNodeAllTask(v.getDeviceId())); - }); - - } - - @Test - public void t3_startTaskErrorTest() { - ErrorCode err = taskService.startTask(-133L); - Assert.assertEquals(err, ErrorCode.ERR_NOSUCHDEVICE); - } - - @Test - public void t4_stopTaskErrorTest() { - ErrorCode err = taskService.stopTask(-133L); - Assert.assertEquals(err, ErrorCode.ERR_NOSUCHTASK); - } -} diff --git a/src/test/java/com/dispose/test/service/UserAccountServiceTest.java b/src/test/java/com/dispose/test/service/UserAccountServiceTest.java deleted file mode 100644 index 19b918c1..00000000 --- a/src/test/java/com/dispose/test/service/UserAccountServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.dispose.test.service; - -import com.dispose.common.ErrorCode; -import com.dispose.pojo.entity.UserAccount; -import com.dispose.pojo.po.MulReturnType; -import com.dispose.service.UserAccountService; -import com.dispose.test.Global.InitTestEnvironment; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.security.NoSuchAlgorithmException; - -/** - * The type User account service test. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class UserAccountServiceTest extends InitTestEnvironment { - /** - * The constant token. - */ - private static String token = ""; - /** - * The User account service. - */ - @Resource - private UserAccountService userAccountService; - - /** - * User login test. - * - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @Before - public void userLoginTest() throws NoSuchAlgorithmException { - MulReturnType ret = userAccountService.loginService(getUSER_NAME(), - getPASSWORD()); - - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - UserAccountServiceTest.token = ret.getSecondParam(); - } - } - - /** - * T 1 log service test. - * - * @throws NoSuchAlgorithmException the no such algorithm exception - */ - @Test - public void t1_logServiceTest() throws NoSuchAlgorithmException { - MulReturnType ret = userAccountService.loginService(getUSER_NAME(), - getPASSWORD()); - - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); - Assert.assertNotNull(ret.getSecondParam()); - Assert.assertEquals(ret.getSecondParam(), UserAccountServiceTest.token); - - ret = userAccountService.loginService(null, null); - - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_USERNOTFOUND); - - ret = userAccountService.loginService(getUSER_NAME(), "12345"); - Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_PASSWORD); - } - - /** - * T 2 logout service test. - */ - @Test - public void t2_logoutServiceTest() { - ErrorCode err = userAccountService.logoutService(getUSER_NAME(), token); - Assert.assertEquals(err, ErrorCode.ERR_OK); - - err = userAccountService.logoutService(getUSER_NAME(), token + "1235"); - Assert.assertEquals(err, ErrorCode.ERR_LOGOUT); - } - - /** - * T 3 get user by token test. - */ - @Test - public void t3_getUserByTokenTest() { - UserAccount username = userAccountService.getUserByToken(UserAccountServiceTest.token); - Assert.assertEquals(username.getUsername(), getUSER_NAME()); - Assert.assertNull(userAccountService.getUserByToken(UserAccountServiceTest.token + "1235")); - } - - /** - * T 4 auth token check test. - */ - @Test - public void t4_authTokenCheckTest() { - Assert.assertEquals(userAccountService.authTokenCheck(token), ErrorCode.ERR_OK); - Assert.assertEquals(userAccountService.authTokenCheck(token + "1235"), ErrorCode.ERR_LOGOUT); - } -}