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

fix(base): 加了一些日志

上级 37f686cb
......@@ -40,12 +40,13 @@ import org.matrix.database.entity.Environment;
import org.matrix.database.service.IEnvironmentService;
import org.matrix.exception.GlobalException;
import org.matrix.exception.HttpRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.matrix.socket.queue.LogQueueRuntime;
import org.matrix.util.JsonFormatUtil;
import org.matrix.util.JsonUtil;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......@@ -61,6 +62,9 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.matrix.enums.ModuleType.CASE_ACTUATOR;
import static org.matrix.enums.ModuleType.HTTP_ACTUATOR;
/**
* HttpClient调用封装
* @author HuangXiahao
......@@ -156,12 +160,21 @@ public class HttpClientActuator implements Actuator {
CloseableHttpResponse response = null;
Long startTime = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
String url = initUrlString(httpRequestDetail);
HttpRequestBase requestBase = initHttpRequestBase(url, httpRequestDetail.getMethod());
if (requestBase instanceof HttpEntityEnclosingRequestBase) {
HttpEntity httpRequestBase = initHttpEntity(httpRequestDetail);
((HttpEntityEnclosingRequestBase) requestBase).setEntity(httpRequestBase);
}
requestBase.setHeaders(httpRequestDetail.getHeadersArray());
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次发送请求URL: %s",url));
if (!StringUtils.isEmpty(httpRequestDetail.getStringValue())){
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次发送请求参数: %s", JsonUtil.toJsonPretty(httpRequestDetail.getStringValue())));
}else if (httpRequestDetail.getRequestBodies()!=null&&httpRequestDetail.getRequestBodies().size()>0){
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次发送请求参数: %s", JsonFormatUtil.formatJson(JSONObject.toJSONString(httpRequestDetail.getRequestBodies()))));
}else {
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次发送请求无参数"));
}
try {
response = httpRequestConfig.getClient().execute(requestBase);
Long endTime = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
......
......@@ -41,6 +41,7 @@ import java.time.LocalDateTime;
import java.util.*;
import static org.matrix.enums.ModuleType.CASE_ACTUATOR;
import static org.matrix.enums.ModuleType.HTTP_ACTUATOR;
/**
* 测试用例执行器
......@@ -163,7 +164,7 @@ public class CaseActuator implements Actuator {
checkPointResult
);
resultList.add(testDataExecuteResult);
LogQueueRuntime.addNewLog(this.getClass(), CASE_ACTUATOR, "用例执行结果:" + JsonFormatUtil.formatJson(JSONObject.toJSONString(testDataExecuteResult)));
LogQueueRuntime.addNewLog(this.getClass(), CASE_ACTUATOR, "[用例执行器] 用例执行结果:" + JsonFormatUtil.formatJson(JSONObject.toJSONString(testDataExecuteResult)));
//执行后置动作
executeMove(testCaseBto.getTestCase().getMoveAfterCase()
, envId, projectId, baseTestCaseResponseDetail != null ? baseTestCaseResponseDetail.getResponseBody() : null, MoveStrategy.AFT_MOVE);
......@@ -255,11 +256,21 @@ public class CaseActuator implements Actuator {
private HttpResponseDetail executionCaseDetail(
Long envId, Long projectId, TestCase testCase, TestData testData) {
if (testCase.getType().equals(TestCaseTypeEnum.HTTP.getValue())) {
HttpRequestDetail httpRequestDetail = JSON.parseObject(testData.getDetail(), HttpRequestDetail.class);
if (httpRequestDetail == null || httpRequestDetail.getMethod() == null || httpRequestDetail.getRequestType() == null) {
throw new GlobalException("HTTP请求发送失败,测试数据组中不存在请求数据");
}
return httpClientActuator.sendHttpRequest(httpRequestDetail, envId, projectId);
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, "[HTTP执行器] 开始准备发送HTTP请求");
HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail, envId, projectId);
String responseBody = httpResponseDetail.getResponseBody();
if (StringUtils.isEmpty(responseBody)){
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次请求结果为空"));
}else {
LogQueueRuntime.addNewLog(this.getClass(), HTTP_ACTUATOR, String.format("[HTTP执行器] 本次请求结果:%s",JsonFormatUtil.formatJson(responseBody)));
}
return httpResponseDetail;
} else {
throw new GlobalException("不支持当前测试用例的类型");
}
......
......@@ -37,6 +37,10 @@ public class CompleteExpressionUtil {
result, DYNAMIC_VARIABLE_REG,
null, (o, s) ->
getSqlExpActuator().parseVarByName(s,envId,projectId));
result = regexExpression(
result, ENV_VARIABLE_REG,
null, (o, s) ->
getSqlExpActuator().parseVarByName(s,envId,projectId));
return result;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论