Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
86ce261b
提交
86ce261b
authored
3月 23, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(base): 加了一些日志
上级
37f686cb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
32 行增加
和
4 行删除
+32
-4
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+15
-2
CaseActuator.java
.../main/java/org/matrix/actuators/usecase/CaseActuator.java
+13
-2
CompleteExpressionUtil.java
...ava/org/matrix/actuators/util/CompleteExpressionUtil.java
+4
-0
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
86ce261b
...
...
@@ -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
();
...
...
kt-base/src/main/java/org/matrix/actuators/usecase/CaseActuator.java
浏览文件 @
86ce261b
...
...
@@ -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
(
"不支持当前测试用例的类型"
);
}
...
...
kt-base/src/main/java/org/matrix/actuators/util/CompleteExpressionUtil.java
浏览文件 @
86ce261b
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论