Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
76b60095
提交
76b60095
authored
1月 25, 2022
作者:
Matrix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(SQL执行器): 调用http与用例的方式变为了注入方式
上级
b9e78ad7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
6 行增加
和
8 行删除
+6
-8
SqlExpActuator.java
...rc/main/java/org/matrix/actuators/sql/SqlExpActuator.java
+6
-8
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/sql/SqlExpActuator.java
浏览文件 @
76b60095
...
@@ -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
http
Client
.
sendHttpRequest
(
httpRequestDetail
).
getResponseBody
();
return
http
Actuator
.
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论