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

feat(base): 新增了TestCase执行器

上级 3022de6c
......@@ -50,7 +50,7 @@ public class CheckPointActuator {
this.env = env;
}
public void httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) {
public CheckPointResult httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) {
CheckPointResult checkPointResult = new CheckPointResult();
//根据checkPoint里的细节数据开始检测
//异常检查点检测
......@@ -72,6 +72,7 @@ public class CheckPointActuator {
checkPointResult.addCheckPointResultDetail(jsonPathCheck(jsonPathCheckPoint, jsonObject));
}
}
return checkPointResult;
}
public CheckPointResultDetail jsonPathCheck(JsonPathCheckPoint jsonPathCheckPoint, Object jsonObject) {
......
......@@ -48,11 +48,17 @@ public class HttpClientActuator {
CloseableHttpClient client;
private int projectId;
public HttpClientActuator(HttpRequestConfig config) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
private String env;
public HttpClientActuator(HttpRequestConfig config, String env, int projectId) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
this.config = config;
this.cookieStore = config.cookieStore();
this.client = config.client();
this.projectId = projectId;
this.env = env;
}
public CloseableHttpClient getClient() {
......@@ -62,7 +68,7 @@ public class HttpClientActuator {
/**
* 初始化请求内数据并补全动态变量
*/
public void completeHttpRequestDetail(HttpRequestDetail httpRequestDetail){
private void completeHttpRequestDetail(HttpRequestDetail httpRequestDetail){
for (RequestHeader header : httpRequestDetail.getHeaders()) {
//获取动态变量,并将动态变量替换进去
//todo 李迪凡 将header中的key和value里的 动态变量补全
......@@ -81,7 +87,7 @@ public class HttpClientActuator {
* 发起Http请求
*
*/
private HttpResponseDetail sendHttpRequest(HttpRequestDetail httpRequestDetail) {
public HttpResponseDetail sendHttpRequest(HttpRequestDetail httpRequestDetail) {
completeHttpRequestDetail(httpRequestDetail);
CloseableHttpResponse response = null;
Date startTime = new Date();
......
package org.matrix.actuator;
import com.alibaba.fastjson.JSON;
import org.matrix.config.HttpRequestConfig;
import org.matrix.database.entity.TestCase;
import org.matrix.entity.checkPoint.CheckPoint;
import org.matrix.entity.checkPoint.CheckPointResult;
import org.matrix.entity.httpRequest.HttpRequestDetail;
import org.matrix.entity.httpRequest.HttpResponseDetail;
import org.matrix.entity.testCase.BaseTestCaseResponseDetail;
import org.matrix.entity.testCase.TestCaseExecuteResult;
import org.matrix.entity.testCase.TestCaseTypeEnum;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.function.Function;
/**
* 测试用例执行器
* todo 打印LOG
*
* @author huangxiahao
*/
public class TestCaseActuator {
private int projectId;
private String env;
private CheckPointActuator checkPointActuator;
private HttpClientActuator httpClientActuator;
private final String baseJsPath = "baseJs.js";
public TestCaseActuator(String env, int projectId) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
this.projectId = projectId;
this.env = env;
checkPointActuator = new CheckPointActuator(baseJsPath, env, projectId);
httpClientActuator = new HttpClientActuator(new HttpRequestConfig(), env, projectId);
}
/**
* 执行测试用例
*/
public TestCaseExecuteResult executeTestCase(TestCase testCase) {
//todo 李迪凡 执行前置动作
//执行测试用例的本体内容
BaseTestCaseResponseDetail baseTestCaseResponseDetail = null;
if (testCase.getType().equals(TestCaseTypeEnum.HTTP.getValue())) {
HttpRequestDetail httpRequestDetail = JSON.parseObject(testCase.getDetail(), HttpRequestDetail.class);
baseTestCaseResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail);
}
//todo 李迪凡 执行测试后动作
//进行检验
CheckPointResult checkPointResult = null;
if (testCase.getType().equals(TestCaseTypeEnum.HTTP.getValue())) {
checkPointResult = checkPointActuator.httpCheck((HttpResponseDetail) baseTestCaseResponseDetail, getCheckPointEntity(testCase));
}
//todo 李迪凡 执行后置动作
return new TestCaseExecuteResult(baseTestCaseResponseDetail, checkPointResult);
}
private CheckPoint getCheckPointEntity(TestCase testCase) {
return new CheckPoint();
}
}
......@@ -67,5 +67,4 @@ public class TestCase extends BaseEntity {
@ApiModelProperty("详细参数")
private String detail;
}
......@@ -14,7 +14,6 @@ import java.util.List;
@Data
public class HttpRequestDetail {
@ApiModelProperty("请求头")
private List<RequestHeader> headers = new ArrayList<>();
......
......@@ -5,12 +5,16 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.matrix.entity.testCase.BaseTestCaseResponseDetail;
import org.springframework.http.HttpStatus;
/**
* @author huangxiahao
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HttpResponseDetail {
public class HttpResponseDetail extends BaseTestCaseResponseDetail {
@ApiModelProperty("HttpClient响应体")
private CloseableHttpResponse response;
......
......@@ -5,6 +5,9 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.http.message.BasicHeader;
/**
* @author huangxiahao
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
......
package org.matrix.entity.testCase;
import lombok.Data;
/**
* @author huangxiahao
*/
@Data
public class BaseTestCaseResponseDetail {
}
package org.matrix.entity.testCase;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.matrix.entity.checkPoint.CheckPointResult;
/**
* @author huangxiahao
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TestCaseExecuteResult {
BaseTestCaseResponseDetail baseTestCaseRequestDetail;
CheckPointResult checkPointResult;
}
package org.matrix.entity.testCase;
/**
* @author huangxiahao
*/
public enum TestCaseTypeEnum {
/**
* Http类型
*/
HTTP(1);
private Integer value;
TestCaseTypeEnum(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
}
......@@ -72,6 +72,14 @@
<version>2.4.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.79</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论