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

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

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