提交 d60c375e authored 作者: 黄夏豪's avatar 黄夏豪

refactor(base): 修改了ContainCheckPoint对象使结构更加合理了

上级 954c9de0
package org.matrix.util; package org.matrix.actuator;
import cn.hutool.script.ScriptUtil; import cn.hutool.script.ScriptUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -31,17 +31,23 @@ import java.util.regex.Pattern; ...@@ -31,17 +31,23 @@ import java.util.regex.Pattern;
* *
* @author huangxiahao * @author huangxiahao
*/ */
public class CheckPointUtil { public class CheckPointActuator {
private String baseJs; private final String baseJs;
CheckPointUtil(String path) { private int projectId;
ClassPathResource cpr = new ClassPathResource(path);
private String env;
CheckPointActuator(String baseJsPath, String env, int projectId) {
ClassPathResource cpr = new ClassPathResource(baseJsPath);
try { try {
this.baseJs = IOUtils.toString(cpr.getInputStream(), StandardCharsets.UTF_8); this.baseJs = IOUtils.toString(cpr.getInputStream(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
throw new CheckPointException("初始JS加载失败"); throw new CheckPointException("初始JS加载失败");
} }
this.projectId = projectId;
this.env = env;
} }
public void httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) { public void httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) {
...@@ -56,9 +62,9 @@ public class CheckPointUtil { ...@@ -56,9 +62,9 @@ public class CheckPointUtil {
checkPointResult.addCheckPointResultDetail(nullCheck(httpResponseDetail.getResponseBody())); checkPointResult.addCheckPointResultDetail(nullCheck(httpResponseDetail.getResponseBody()));
} }
//包含检查点检测 //包含检查点检测
for (ContainCheckPoint containCheckPoint : checkPoint.getContainCheckPoints()) { checkPointResult.addCheckPointResultDetail(containCheck(checkPoint.getContainCheckPoints(), httpResponseDetail.getResponseBody()));
checkPointResult.addCheckPointResultDetail(containCheck(containCheckPoint, httpResponseDetail.getResponseBody())); //不包含检查点检测
} checkPointResult.addCheckPointResultDetail(noContainCheck(checkPoint.getNoContainCheckPoint(), httpResponseDetail.getResponseBody()));
//JsonPath检查点检测 //JsonPath检查点检测
if (checkPoint.getJsonPathCheckPoints().size() > 0) { if (checkPoint.getJsonPathCheckPoints().size() > 0) {
Object jsonObject = Configuration.defaultConfiguration().jsonProvider().parse(httpResponseDetail.getResponseBody()); Object jsonObject = Configuration.defaultConfiguration().jsonProvider().parse(httpResponseDetail.getResponseBody());
...@@ -131,7 +137,6 @@ public class CheckPointUtil { ...@@ -131,7 +137,6 @@ public class CheckPointUtil {
} }
public CheckPointResultDetail containCheck(ContainCheckPoint containCheckPoint, String responseBody) { public CheckPointResultDetail containCheck(ContainCheckPoint containCheckPoint, String responseBody) {
if (containCheckPoint.getIsContain()) {
if (responseBody.contains(containCheckPoint.getValue())) { if (responseBody.contains(containCheckPoint.getValue())) {
return new CheckPointResultDetail( return new CheckPointResultDetail(
true, true,
...@@ -143,11 +148,13 @@ public class CheckPointUtil { ...@@ -143,11 +148,13 @@ public class CheckPointUtil {
String.format("包含检查点,检查未通过,结果:%s 中,不包含值:%s", responseBody, containCheckPoint.getValue()) String.format("包含检查点,检查未通过,结果:%s 中,不包含值:%s", responseBody, containCheckPoint.getValue())
); );
} }
} else { }
if (responseBody.contains(containCheckPoint.getValue())) {
public CheckPointResultDetail noContainCheck(NoContainCheckPoint noContainCheckPoint, String responseBody) {
if (responseBody.contains(noContainCheckPoint.getValue())) {
return new CheckPointResultDetail( return new CheckPointResultDetail(
false, false,
String.format("不包含检查点,检查未通过,结果:%s 中,包含值:%s", responseBody, containCheckPoint.getValue()) String.format("不包含检查点,检查未通过,结果:%s 中,包含值:%s", responseBody, noContainCheckPoint.getValue())
); );
} else { } else {
return new CheckPointResultDetail( return new CheckPointResultDetail(
...@@ -156,7 +163,6 @@ public class CheckPointUtil { ...@@ -156,7 +163,6 @@ public class CheckPointUtil {
); );
} }
} }
}
public CheckPointResultDetail nullCheck(String responseBody) { public CheckPointResultDetail nullCheck(String responseBody) {
......
package org.matrix.util; package org.matrix.actuator;
import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaderValues;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -40,7 +40,7 @@ import java.util.List; ...@@ -40,7 +40,7 @@ import java.util.List;
* todo 打印LOG * todo 打印LOG
* @author HuangXiahao * @author HuangXiahao
**/ **/
public class HttpClientUtil { public class HttpClientActuator {
HttpRequestConfig config; HttpRequestConfig config;
...@@ -49,7 +49,7 @@ public class HttpClientUtil { ...@@ -49,7 +49,7 @@ public class HttpClientUtil {
CloseableHttpClient client; CloseableHttpClient client;
public HttpClientUtil(HttpRequestConfig config) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { public HttpClientActuator(HttpRequestConfig config) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
this.config = config; this.config = config;
this.cookieStore = config.cookieStore(); this.cookieStore = config.cookieStore();
this.client = config.client(); this.client = config.client();
......
...@@ -22,9 +22,14 @@ public class CheckPoint { ...@@ -22,9 +22,14 @@ public class CheckPoint {
private Boolean useNullCheck = false; private Boolean useNullCheck = false;
/** /**
* 是否包含检测 * 包含检测
*/ */
private List<ContainCheckPoint> containCheckPoints; private ContainCheckPoint containCheckPoints;
/**
* 不包含检测
*/
private NoContainCheckPoint noContainCheckPoint;
/** /**
* JsonPath检查点 * JsonPath检查点
......
...@@ -9,11 +9,6 @@ import lombok.Data; ...@@ -9,11 +9,6 @@ import lombok.Data;
@Data @Data
public class ContainCheckPoint { public class ContainCheckPoint {
/**
* false为不包含检测,ture为包含检测
*/
private Boolean isContain = false;
private String value; private String value;
} }
package org.matrix.entity.checkPoint;
import lombok.Data;
/**
* 是否包含检查点
* @author Administrator
*/
@Data
public class NoContainCheckPoint {
private String value;
}
...@@ -7,10 +7,10 @@ function equal(a, b) { ...@@ -7,10 +7,10 @@ function equal(a, b) {
//数组类型 //数组类型
switch (bType) { switch (bType) {
case "[object Array]": case "[object Array]":
return JSON.stringify(a) == JSON.stringify(b); return JSON.stringify(a) === JSON.stringify(b);
default: default:
for (var i = 0; i < a.length; i++) { for (var i = 0; i < a.length; i++) {
if (JSON.stringify(a[i]) != JSON.stringify(b)) { if (JSON.stringify(a[i]) !== JSON.stringify(b)) {
return false; return false;
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论