提交 76b60095 authored 作者: Matrix's avatar Matrix

fix(SQL执行器): 调用http与用例的方式变为了注入方式

上级 b9e78ad7
...@@ -12,7 +12,6 @@ import org.matrix.actuators.httpclient.HttpClientActuator; ...@@ -12,7 +12,6 @@ import org.matrix.actuators.httpclient.HttpClientActuator;
import org.matrix.actuators.httpclient.HttpRequestDetail; import org.matrix.actuators.httpclient.HttpRequestDetail;
import org.matrix.actuators.httpclient.HttpResponseDetail; import org.matrix.actuators.httpclient.HttpResponseDetail;
import org.matrix.actuators.usecase.CaseActuator; import org.matrix.actuators.usecase.CaseActuator;
import org.matrix.config.HttpRequestConfig;
import org.matrix.database.entity.DynamicVariable; import org.matrix.database.entity.DynamicVariable;
import org.matrix.database.entity.TestCase; import org.matrix.database.entity.TestCase;
import org.matrix.database.service.IConnectService; import org.matrix.database.service.IConnectService;
...@@ -55,6 +54,8 @@ public class SqlExpActuator implements Actuator { ...@@ -55,6 +54,8 @@ public class SqlExpActuator implements Actuator {
public static final String REPLACE_VAR_EXP = "\\$\\{%s}(\\[\\w*])?"; public static final String REPLACE_VAR_EXP = "\\$\\{%s}(\\[\\w*])?";
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final CaseActuator caseActuator;
private final HttpClientActuator httpActuator;
private final EnvironmentActuator envActuator; private final EnvironmentActuator envActuator;
private final IDynamicVariableService varService; private final IDynamicVariableService varService;
private final IConnectService connectService; private final IConnectService connectService;
...@@ -132,11 +133,11 @@ public class SqlExpActuator implements Actuator { ...@@ -132,11 +133,11 @@ public class SqlExpActuator implements Actuator {
* @return 解析后的字符串 * @return 解析后的字符串
*/ */
private String caseHandler(Long envId, Long projectId, DynamicVariable dynamicVar) { private String caseHandler(Long envId, Long projectId, DynamicVariable dynamicVar) {
CaseActuator caseActuator = new CaseActuator(envId, projectId);
long caseId = Long.parseLong(dynamicVar.getDetail()); long caseId = Long.parseLong(dynamicVar.getDetail());
TestCase testCase = Optional.of(caseService.getById(caseId)) TestCase testCase = Optional.of(caseService.getById(caseId))
.orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的TestCase", caseId))); .orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的TestCase", caseId)));
HttpResponseDetail responseDetail = (HttpResponseDetail) caseActuator.executeTestCase(testCase).getBaseTestCaseRequestDetail(); HttpResponseDetail responseDetail = (HttpResponseDetail) caseActuator.executeTestCase(testCase, envId, projectId)
.getBaseTestCaseRequestDetail();
return responseDetail.getResponseBody(); return responseDetail.getResponseBody();
} }
...@@ -149,9 +150,8 @@ public class SqlExpActuator implements Actuator { ...@@ -149,9 +150,8 @@ public class SqlExpActuator implements Actuator {
* @return 解析后的字符串 * @return 解析后的字符串
*/ */
private String httpVarHandler(Long envId, Long projectId, DynamicVariable dynamicVar) { private String httpVarHandler(Long envId, Long projectId, DynamicVariable dynamicVar) {
HttpClientActuator httpClient = new HttpClientActuator(new HttpRequestConfig(), envId, projectId);
HttpRequestDetail httpRequestDetail = JSON.parseObject(dynamicVar.getDetail(), HttpRequestDetail.class); HttpRequestDetail httpRequestDetail = JSON.parseObject(dynamicVar.getDetail(), HttpRequestDetail.class);
return httpClient.sendHttpRequest(httpRequestDetail).getResponseBody(); return httpActuator.sendHttpRequest(httpRequestDetail, envId, projectId).getResponseBody();
} }
/** /**
...@@ -177,7 +177,7 @@ public class SqlExpActuator implements Actuator { ...@@ -177,7 +177,7 @@ public class SqlExpActuator implements Actuator {
.orElseThrow(() -> new GlobalException( .orElseThrow(() -> new GlobalException(
String.format("没有找到项目id = %d 下,name = %s的变量", projectId, sqlRegular.getVarName()))); String.format("没有找到项目id = %d 下,name = %s的变量", projectId, sqlRegular.getVarName())));
String calculatedValue = parseVar(envId, sqlRegular.getIndex(), projectId, recVar); String calculatedValue = parseVar(envId, sqlRegular.getIndex(), projectId, recVar);
log.info("[SQL执行器] 正在进行SQL变量计算 变量名: {} 计算后的替换值: {}",sqlRegular.getVarName(),calculatedValue); log.info("[SQL执行器] 正在进行SQL变量计算 变量名: {} 计算后的替换值: {}", sqlRegular.getVarName(), calculatedValue);
sqlExp = sqlExp.replaceAll(String.format(REPLACE_VAR_EXP, sqlRegular.getVarName()), calculatedValue); sqlExp = sqlExp.replaceAll(String.format(REPLACE_VAR_EXP, sqlRegular.getVarName()), calculatedValue);
dynamicVar.getSqlExpDetail().setSqlExp(sqlExp); dynamicVar.getSqlExpDetail().setSqlExp(sqlExp);
} }
...@@ -203,7 +203,6 @@ public class SqlExpActuator implements Actuator { ...@@ -203,7 +203,6 @@ public class SqlExpActuator implements Actuator {
return Optional.of(resultMap.get(takenField)) return Optional.of(resultMap.get(takenField))
.orElseThrow(() -> new GlobalException(String.format("%s 数据集中不存在属性名为 %s 的字段", .orElseThrow(() -> new GlobalException(String.format("%s 数据集中不存在属性名为 %s 的字段",
JSON.toJSON(resultMap), takenField))).toString(); JSON.toJSON(resultMap), takenField))).toString();
} }
...@@ -233,7 +232,6 @@ public class SqlExpActuator implements Actuator { ...@@ -233,7 +232,6 @@ public class SqlExpActuator implements Actuator {
dataSourceService.switchMainDataSource(); dataSourceService.switchMainDataSource();
return resultMap; return resultMap;
} else { } else {
throw new GlobalException(String.format("动态变量的类型必须要是SQL类型且DETAIL内的SQL语句必须为元SQL语句,当前type : %s , 当前detail : %s", throw new GlobalException(String.format("动态变量的类型必须要是SQL类型且DETAIL内的SQL语句必须为元SQL语句,当前type : %s , 当前detail : %s",
dynamicVar.getType(), sqlExp)); dynamicVar.getType(), sqlExp));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论