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

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

上级 3022de6c
...@@ -50,7 +50,7 @@ public class CheckPointActuator { ...@@ -50,7 +50,7 @@ public class CheckPointActuator {
this.env = env; this.env = env;
} }
public void httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) { public CheckPointResult httpCheck(HttpResponseDetail httpResponseDetail, CheckPoint checkPoint) {
CheckPointResult checkPointResult = new CheckPointResult(); CheckPointResult checkPointResult = new CheckPointResult();
//根据checkPoint里的细节数据开始检测 //根据checkPoint里的细节数据开始检测
//异常检查点检测 //异常检查点检测
...@@ -72,6 +72,7 @@ public class CheckPointActuator { ...@@ -72,6 +72,7 @@ public class CheckPointActuator {
checkPointResult.addCheckPointResultDetail(jsonPathCheck(jsonPathCheckPoint, jsonObject)); checkPointResult.addCheckPointResultDetail(jsonPathCheck(jsonPathCheckPoint, jsonObject));
} }
} }
return checkPointResult;
} }
public CheckPointResultDetail jsonPathCheck(JsonPathCheckPoint jsonPathCheckPoint, Object jsonObject) { public CheckPointResultDetail jsonPathCheck(JsonPathCheckPoint jsonPathCheckPoint, Object jsonObject) {
......
...@@ -48,11 +48,17 @@ public class HttpClientActuator { ...@@ -48,11 +48,17 @@ public class HttpClientActuator {
CloseableHttpClient client; 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.config = config;
this.cookieStore = config.cookieStore(); this.cookieStore = config.cookieStore();
this.client = config.client(); this.client = config.client();
this.projectId = projectId;
this.env = env;
} }
public CloseableHttpClient getClient() { public CloseableHttpClient getClient() {
...@@ -62,7 +68,7 @@ public class HttpClientActuator { ...@@ -62,7 +68,7 @@ public class HttpClientActuator {
/** /**
* 初始化请求内数据并补全动态变量 * 初始化请求内数据并补全动态变量
*/ */
public void completeHttpRequestDetail(HttpRequestDetail httpRequestDetail){ private void completeHttpRequestDetail(HttpRequestDetail httpRequestDetail){
for (RequestHeader header : httpRequestDetail.getHeaders()) { for (RequestHeader header : httpRequestDetail.getHeaders()) {
//获取动态变量,并将动态变量替换进去 //获取动态变量,并将动态变量替换进去
//todo 李迪凡 将header中的key和value里的 动态变量补全 //todo 李迪凡 将header中的key和value里的 动态变量补全
...@@ -81,7 +87,7 @@ public class HttpClientActuator { ...@@ -81,7 +87,7 @@ public class HttpClientActuator {
* 发起Http请求 * 发起Http请求
* *
*/ */
private HttpResponseDetail sendHttpRequest(HttpRequestDetail httpRequestDetail) { public HttpResponseDetail sendHttpRequest(HttpRequestDetail httpRequestDetail) {
completeHttpRequestDetail(httpRequestDetail); completeHttpRequestDetail(httpRequestDetail);
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
Date startTime = new Date(); 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 { ...@@ -67,5 +67,4 @@ public class TestCase extends BaseEntity {
@ApiModelProperty("详细参数") @ApiModelProperty("详细参数")
private String detail; private String detail;
} }
...@@ -14,7 +14,6 @@ import java.util.List; ...@@ -14,7 +14,6 @@ import java.util.List;
@Data @Data
public class HttpRequestDetail { public class HttpRequestDetail {
@ApiModelProperty("请求头") @ApiModelProperty("请求头")
private List<RequestHeader> headers = new ArrayList<>(); private List<RequestHeader> headers = new ArrayList<>();
......
...@@ -5,12 +5,16 @@ import lombok.AllArgsConstructor; ...@@ -5,12 +5,16 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.matrix.entity.testCase.BaseTestCaseResponseDetail;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
/**
* @author huangxiahao
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class HttpResponseDetail { public class HttpResponseDetail extends BaseTestCaseResponseDetail {
@ApiModelProperty("HttpClient响应体") @ApiModelProperty("HttpClient响应体")
private CloseableHttpResponse response; private CloseableHttpResponse response;
......
...@@ -5,6 +5,9 @@ import lombok.Data; ...@@ -5,6 +5,9 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
/**
* @author huangxiahao
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @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 @@ ...@@ -72,6 +72,14 @@
<version>2.4.5</version> <version>2.4.5</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.79</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论