Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
beb34e41
提交
beb34e41
authored
3月 21, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(base): HTTP执行器中HTTP执行时假如URL不存在协议://域名 时,会自动根据当前的环境进行 URL的拼接了
上级
a59c40b8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
15 行删除
+43
-15
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+24
-6
CaseActuator.java
.../main/java/org/matrix/actuators/usecase/CaseActuator.java
+13
-8
ExecutionSocketHandler.java
...c/main/java/org/matrix/socket/ExecutionSocketHandler.java
+6
-1
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
beb34e41
...
...
@@ -20,7 +20,10 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.matrix.database.entity.Environment
;
import
org.matrix.database.service.IEnvironmentService
;
import
org.matrix.exception.HttpRequestException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
...
...
@@ -35,6 +38,7 @@ import java.time.ZoneOffset;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -44,15 +48,24 @@ import java.util.stream.Collectors;
@Component
public
class
HttpClientActuator
implements
Actuator
{
/**
* 正则表达式,匹配 URL 是否符合HTTP协议
*/
private
static
final
String
PATTERN_URL
=
"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"
;
final
CloseableHttpClient
client
;
final
CompleteExpressionUtil
completeExpressionUtil
;
public
HttpClientActuator
(
CloseableHttpClient
client
,
CompleteExpressionUtil
completeExpressionUtil
)
{
final
IEnvironmentService
environmentService
;
public
HttpClientActuator
(
CloseableHttpClient
client
,
CompleteExpressionUtil
completeExpressionUtil
,
IEnvironmentService
environmentService
)
{
this
.
client
=
client
;
this
.
completeExpressionUtil
=
completeExpressionUtil
;
this
.
environmentService
=
environmentService
;
}
/**
...
...
@@ -100,6 +113,11 @@ public class HttpClientActuator implements Actuator {
httpRequestDetail
.
getUrl
(),
envId
,
projectId
));
boolean
urlMatch
=
Pattern
.
matches
(
PATTERN_URL
,
httpRequestDetail
.
getUrl
());
if
(!
urlMatch
){
Environment
environment
=
environmentService
.
getById
(
envId
);
httpRequestDetail
.
setUrl
(
environment
.
getIp
()+
httpRequestDetail
.
getUrl
());
}
}
/**
...
...
@@ -253,12 +271,12 @@ public class HttpClientActuator implements Actuator {
}
}
url
=
uriBuilder
.
build
().
toString
();
}
else
if
(
httpRequestDetail
.
getRequestType
()
==
HttpRequestType
.
PATH
){
List
<
RequestBody
>
requestBodies
=
httpRequestDetail
.
getRequestBodies
();
Map
<
String
,
String
>
requestMap
=
requestBodies
.
stream
().
collect
(
Collectors
.
toMap
(
RequestBody:
:
getKey
,
RequestBody:
:
getValue
));
url
=
completeExpressionUtil
.
completePathVariable
(
url
,
requestMap
);
}
}
else
if
(
httpRequestDetail
.
getRequestType
()
==
HttpRequestType
.
PATH
){
List
<
RequestBody
>
requestBodies
=
httpRequestDetail
.
getRequestBodies
();
Map
<
String
,
String
>
requestMap
=
requestBodies
.
stream
().
collect
(
Collectors
.
toMap
(
RequestBody:
:
getKey
,
RequestBody:
:
getValue
));
url
=
completeExpressionUtil
.
completePathVariable
(
url
,
requestMap
);
}
}
catch
(
URISyntaxException
e
)
{
throw
new
HttpRequestException
(
String
.
format
(
"URL格式不正确,不正确的URL为: %s"
,
url
));
...
...
kt-base/src/main/java/org/matrix/actuators/usecase/CaseActuator.java
浏览文件 @
beb34e41
...
...
@@ -290,14 +290,8 @@ public class CaseActuator implements Actuator {
throw
new
GlobalException
(
"本次执行中,存在非相同项目的测试用例"
);
}
}
//建立执行历史(ExecutionHistory)
if
(
caseExecuteVo
.
getJobId
()
!=
-
1L
)
{
if
(!
LogQueueRuntime
.
checkJobIsInRun
(
caseExecuteVo
.
getJobId
(),
caseExecuteVo
.
getUserId
(),
caseExecuteVo
.
getType
()))
{
insertExecutionHistory
(
uniqueKey
,
caseExecuteVo
);
}
}
else
{
insertExecutionHistory
(
uniqueKey
,
caseExecuteVo
);
}
Boolean
hasInit
=
false
;
for
(
TestCaseListDataBto
testCaseListDataBto
:
testCaseListDataBtoList
)
{
LocalDateTime
caseStartTime
=
LocalDateTime
.
now
();
try
{
...
...
@@ -309,6 +303,17 @@ public class CaseActuator implements Actuator {
,
caseExecuteVo
.
getType
()
,
uniqueKey
);
if
(!
hasInit
){
//建立执行历史(ExecutionHistory)
if
(
caseExecuteVo
.
getJobId
()
!=
-
1L
)
{
if
(!
LogQueueRuntime
.
checkJobIsInRun
(
caseExecuteVo
.
getJobId
(),
caseExecuteVo
.
getUserId
(),
caseExecuteVo
.
getType
()))
{
insertExecutionHistory
(
uniqueKey
,
caseExecuteVo
);
}
}
else
{
insertExecutionHistory
(
uniqueKey
,
caseExecuteVo
);
}
hasInit
=
true
;
}
//执行测试用例
if
(
testCaseListDataBto
.
getTestDataList
()
!=
null
&&
testCaseListDataBto
.
getTestDataList
().
size
()
>
0
)
{
List
<
TestDataExecuteResult
>
resultList
=
...
...
kt-base/src/main/java/org/matrix/socket/ExecutionSocketHandler.java
浏览文件 @
beb34e41
...
...
@@ -140,7 +140,12 @@ public class ExecutionSocketHandler extends TextWebSocketHandler {
//执行总时间
String
allTime
=
caseResult
.
getDurationTimeStr
();
//用例通过率
Integer
probability
=
BigDecimal
.
valueOf
(
passNum
).
divide
(
BigDecimal
.
valueOf
(
total
),
2
,
RoundingMode
.
UP
).
multiply
(
BigDecimal
.
valueOf
(
100
)).
intValue
();
Integer
probability
;
if
(
total
==
0L
){
probability
=
0
;
}
else
{
probability
=
BigDecimal
.
valueOf
(
passNum
).
divide
(
BigDecimal
.
valueOf
(
total
),
2
,
RoundingMode
.
UP
).
multiply
(
BigDecimal
.
valueOf
(
100
)).
intValue
();
}
DataBean
dataBean
=
new
DataBean
(
total
,
passNum
,
failNum
,
allTime
,
probability
);
List
<
DataBeansMoveVo
>
dataBeansMoveVos
=
new
ArrayList
<>();
for
(
TestCaseReport
caseReport
:
caseResult
.
getCaseReports
())
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论