Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
a398b171
提交
a398b171
authored
1月 21, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(base): 修复了httprequest的BUG
上级
55c57ba4
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
133 行增加
和
55 行删除
+133
-55
CheckPoint.java
...main/java/org/matrix/actuators/checkpoint/CheckPoint.java
+4
-3
CheckPointActuator.java
...a/org/matrix/actuators/checkpoint/CheckPointActuator.java
+43
-43
CheckPointResult.java
...ava/org/matrix/actuators/checkpoint/CheckPointResult.java
+4
-0
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+1
-1
CaseActuator.java
.../main/java/org/matrix/actuators/usecase/CaseActuator.java
+17
-2
TestCase.java
...se/src/main/java/org/matrix/database/entity/TestCase.java
+2
-2
CaseActuatorTest.java
.../test/java/org/matrix/actuators/sql/CaseActuatorTest.java
+54
-0
HttpClientActuatorTest.java
...java/org/matrix/actuators/sql/HttpClientActuatorTest.java
+8
-4
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/checkpoint/CheckPoint.java
浏览文件 @
a398b171
...
...
@@ -2,6 +2,7 @@ package org.matrix.actuators.checkpoint;
import
lombok.Data
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -24,17 +25,17 @@ public class CheckPoint {
/**
* 包含检测
*/
private
ContainCheckPoint
containCheckPoints
;
private
String
containCheckPoint
;
/**
* 不包含检测
*/
private
NoContainCheckPoint
noContainCheckPoint
;
private
String
noContainCheckPoint
;
/**
* JsonPath检查点
*/
private
List
<
JsonPathCheckPoint
>
jsonPathCheckPoints
;
private
JsonPathCheckPoint
jsonPathCheckPoint
;
...
...
kt-base/src/main/java/org/matrix/actuators/checkpoint/CheckPointActuator.java
浏览文件 @
a398b171
...
...
@@ -7,17 +7,13 @@ import com.alibaba.fastjson.JSONException;
import
com.alibaba.fastjson.JSONObject
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.DocumentContext
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.PathNotFoundException
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.matrix.actuators.Actuator
;
import
org.matrix.actuators.httpclient.HttpResponseDetail
;
import
org.matrix.actuators.sql.SqlExpActuator
;
import
org.matrix.actuators.util.CompleteExpressionUtil
;
import
org.matrix.exception.CheckPointException
;
import
org.matrix.util.SpringUtils
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -25,10 +21,6 @@ import javax.script.ScriptEngine;
import
javax.script.ScriptException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.function.BiFunction
;
import
java.util.function.Function
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
...
...
@@ -57,7 +49,6 @@ public class CheckPointActuator implements Actuator {
}
public
CheckPointResult
httpCheck
(
HttpResponseDetail
httpResponseDetail
,
CheckPoint
checkPoint
)
{
CheckPointResult
checkPointResult
=
new
CheckPointResult
();
//根据checkPoint里的细节数据开始检测
...
...
@@ -70,24 +61,34 @@ public class CheckPointActuator implements Actuator {
checkPointResult
.
addCheckPointResultDetail
(
nullCheck
(
httpResponseDetail
.
getResponseBody
()));
}
//包含检查点检测
checkPointResult
.
addCheckPointResultDetail
(
containCheck
(
checkPoint
.
getContainCheckPoints
(),
httpResponseDetail
.
getResponseBody
()));
if
(!
StringUtils
.
isEmpty
(
checkPoint
.
getContainCheckPoint
())){
checkPointResult
.
addCheckPointResultDetail
(
containCheck
(
checkPoint
.
getContainCheckPoint
(),
httpResponseDetail
.
getResponseBody
()));
}
//不包含检查点检测
checkPointResult
.
addCheckPointResultDetail
(
noContainCheck
(
checkPoint
.
getNoContainCheckPoint
(),
httpResponseDetail
.
getResponseBody
()));
if
(!
StringUtils
.
isEmpty
(
checkPoint
.
getNoContainCheckPoint
())){
checkPointResult
.
addCheckPointResultDetail
(
noContainCheck
(
checkPoint
.
getNoContainCheckPoint
(),
httpResponseDetail
.
getResponseBody
()));
}
//JsonPath检查点检测
if
(
checkPoint
.
getJsonPathCheckPoint
s
().
size
()
>
0
)
{
if
(
checkPoint
.
getJsonPathCheckPoint
()!=
null
)
{
Object
jsonObject
=
Configuration
.
defaultConfiguration
().
jsonProvider
().
parse
(
httpResponseDetail
.
getResponseBody
());
for
(
JsonPathCheckPoint
jsonPathCheckPoint
:
checkPoint
.
getJsonPathCheckPoints
())
{
checkPointResult
.
addCheckPointResultDetail
(
jsonPathCheck
(
jsonPathCheckPoint
,
jsonObject
));
}
checkPointResult
.
addCheckPointResultDetail
(
jsonPathCheck
(
checkPoint
.
getJsonPathCheckPoint
(),
jsonObject
));
}
return
checkPointResult
;
}
public
CheckPointResultDetail
jsonPathCheck
(
JsonPathCheckPoint
jsonPathCheckPoint
,
Object
jsonObject
)
{
String
expression
;
String
expression
=
jsonPathCheckPoint
.
getExpression
()
;
try
{
expression
=
CompleteExpressionUtil
.
completeDynamicVariable
(
expression
,
envId
,
projectId
)
;
//todo 李迪凡 先将result中的动态变量都还原出来 (先后顺序不能乱)得先还原动态变量
expression
=
CompleteExpressionUtil
.
completeJsonPathExpression
(
jsonPathCheckPoint
.
getExpression
(),
jsonObject
);
expression
=
CompleteExpressionUtil
.
completeJsonPathExpression
(
expression
,
jsonObject
);
}
catch
(
IllegalArgumentException
e
)
{
return
new
CheckPointResultDetail
(
false
,
...
...
@@ -102,19 +103,19 @@ public class CheckPointActuator implements Actuator {
try
{
ScriptEngine
jsEngine
=
getScriptEngine
();
Object
eval
=
jsEngine
.
eval
(
expression
);
if
(
eval
instanceof
Boolean
){
if
((
Boolean
)
eval
){
if
(
eval
instanceof
Boolean
)
{
if
((
Boolean
)
eval
)
{
return
new
CheckPointResultDetail
(
true
,
String
.
format
(
"JsonPath检查点,检查通过,表达式为:%s"
,
expression
)
);
}
else
{
}
else
{
return
new
CheckPointResultDetail
(
false
,
String
.
format
(
"JsonPath检查点,检查未通过,计算结果为false,错误的表达式为:%s"
,
expression
)
);
}
}
else
{
}
else
{
return
new
CheckPointResultDetail
(
false
,
String
.
format
(
"JsonPath检查点,检查未通过,JsonPath的返回值不是一个布尔类型,错误的表达式为:%s"
,
expression
)
...
...
@@ -132,12 +133,14 @@ public class CheckPointActuator implements Actuator {
}
public
CheckPointResultDetail
containCheck
(
ContainCheckPoint
containCheckPoint
,
String
responseBody
)
{
if
(
responseBody
.
contains
(
containCheckPoint
.
getValue
()))
{
public
CheckPointResultDetail
containCheck
(
String
containCheckPoint
,
String
responseBody
)
{
containCheckPoint
=
CompleteExpressionUtil
.
completeDynamicVariable
(
containCheckPoint
,
envId
,
projectId
)
;
String
[]
split
=
containCheckPoint
.
split
(
","
);
if
(
responseBody
.
contains
(
containCheckPoint
))
{
return
new
CheckPointResultDetail
(
true
,
"包含检查点,检查通过"
...
...
@@ -145,23 +148,23 @@ public class CheckPointActuator implements Actuator {
}
else
{
return
new
CheckPointResultDetail
(
false
,
String
.
format
(
"包含检查点,检查未通过,结果:%s 中,不包含值:%s"
,
responseBody
,
containCheckPoint
.
getValue
()
)
String
.
format
(
"包含检查点,检查未通过,结果:%s 中,不包含值:%s"
,
responseBody
,
containCheckPoint
)
);
}
}
public
CheckPointResultDetail
noContainCheck
(
NoContainCheckPoint
noContainCheckPoint
,
String
responseBody
)
{
if
(
responseBody
.
contains
(
noContainCheckPoint
.
getValue
()
))
{
return
new
CheckPointResultDetail
(
false
,
String
.
format
(
"不包含检查点,检查未通过,结果:%s 中,包含值:%s"
,
responseBody
,
noContainCheckPoint
.
getValue
()
)
);
}
else
{
return
new
CheckPointResultDetail
(
true
,
"不包含检查点,检查通过"
);
}
public
CheckPointResultDetail
noContainCheck
(
String
noContainCheckPoint
,
String
responseBody
)
{
if
(
responseBody
.
contains
(
noContainCheckPoint
))
{
return
new
CheckPointResultDetail
(
false
,
String
.
format
(
"不包含检查点,检查未通过,结果:%s 中,包含值:%s"
,
responseBody
,
noContainCheckPoint
)
);
}
else
{
return
new
CheckPointResultDetail
(
true
,
"不包含检查点,检查通过"
);
}
}
...
...
@@ -210,7 +213,4 @@ public class CheckPointActuator implements Actuator {
}
}
kt-base/src/main/java/org/matrix/actuators/checkpoint/CheckPointResult.java
浏览文件 @
a398b171
...
...
@@ -25,4 +25,8 @@ public class CheckPointResult {
public
Boolean
addCheckPointResultDetail
(
CheckPointResultDetail
checkPointResultDetail
){
return
checkPointResultDetails
.
add
(
checkPointResultDetail
);
}
public
Boolean
addCheckPointResultDetail
(
List
<
CheckPointResultDetail
>
checkPointResultDetail
){
return
checkPointResultDetails
.
addAll
(
checkPointResultDetail
);
}
}
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
a398b171
...
...
@@ -107,7 +107,7 @@ public class HttpClientActuator implements Actuator {
projectId
)
);
}
if
(
StringUtils
.
isEmpty
(
httpRequestDetail
.
getStringValue
())){
if
(
!
StringUtils
.
isEmpty
(
httpRequestDetail
.
getStringValue
())){
//todo 李迪凡 将httpRequestDetail的stringValue 动态变量补全
httpRequestDetail
.
setStringValue
(
CompleteExpressionUtil
.
completeDynamicVariable
(
...
...
kt-base/src/main/java/org/matrix/actuators/usecase/CaseActuator.java
浏览文件 @
a398b171
...
...
@@ -3,6 +3,7 @@ package org.matrix.actuators.usecase;
import
com.alibaba.fastjson.JSON
;
import
org.matrix.actuators.Actuator
;
import
org.matrix.actuators.checkpoint.CheckPointActuator
;
import
org.matrix.actuators.checkpoint.JsonPathCheckPoint
;
import
org.matrix.actuators.httpclient.HttpClientActuator
;
import
org.matrix.config.HttpRequestConfig
;
import
org.matrix.database.entity.TestCase
;
...
...
@@ -27,7 +28,7 @@ public class CaseActuator implements Actuator {
private
HttpClientActuator
httpClientActuator
;
private
final
String
baseJsPath
=
"
baseJs
.js"
;
private
final
String
baseJsPath
=
"
syntaxCheck
.js"
;
public
CaseActuator
(
Long
envId
,
Long
projectId
)
{
this
.
projectId
=
projectId
;
...
...
@@ -58,7 +59,21 @@ public class CaseActuator implements Actuator {
}
private
CheckPoint
getCheckPointEntity
(
TestCase
testCase
)
{
return
new
CheckPoint
();
CheckPoint
checkPoint
=
new
CheckPoint
();
if
(
testCase
.
getAbnormalCheckpoint
()==
0
){
checkPoint
.
setUseExceptionCheck
(
false
);
}
else
{
checkPoint
.
setUseExceptionCheck
(
true
);
}
if
(
testCase
.
getNoEmptyCheckpoint
()==
0
){
checkPoint
.
setUseNullCheck
(
false
);
}
else
{
checkPoint
.
setUseNullCheck
(
true
);
}
checkPoint
.
setContainCheckPoint
(
testCase
.
getContainCheckpoint
());
checkPoint
.
setNoContainCheckPoint
(
testCase
.
getNoContainCheckpoint
());
checkPoint
.
setJsonPathCheckPoint
(
JSON
.
parseObject
(
testCase
.
getJsonpathCheckpoint
(),
JsonPathCheckPoint
.
class
));
return
checkPoint
;
}
...
...
kt-base/src/main/java/org/matrix/database/entity/TestCase.java
浏览文件 @
a398b171
...
...
@@ -40,10 +40,10 @@ public class TestCase extends BaseEntity {
private
String
moveAferTest
;
@ApiModelProperty
(
"是否进行异常检验,0为否,1为是"
)
private
Integer
abnormalCheckpoint
;
private
Integer
abnormalCheckpoint
=
0
;
@ApiModelProperty
(
"是否进行非空检验,0为否,1为是"
)
private
Integer
noEmptyCheckpoint
;
private
Integer
noEmptyCheckpoint
=
0
;
@ApiModelProperty
(
"包含某字段检验(例如 张三,李四) 则对检查结果中是否包含张三或者李四"
)
private
String
containCheckpoint
;
...
...
kt-base/src/test/java/org/matrix/actuators/sql/CaseActuatorTest.java
0 → 100644
浏览文件 @
a398b171
package
org
.
matrix
.
actuators
.
sql
;
import
com.alibaba.fastjson.JSON
;
import
org.checkerframework.checker.units.qual.A
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.matrix.actuators.httpclient.HttpClientActuator
;
import
org.matrix.actuators.httpclient.HttpRequestDetail
;
import
org.matrix.actuators.httpclient.HttpResponseDetail
;
import
org.matrix.actuators.usecase.CaseActuator
;
import
org.matrix.actuators.usecase.TestCaseExecuteResult
;
import
org.matrix.config.HttpRequestConfig
;
import
org.matrix.database.entity.TestCase
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
CaseActuatorTest
{
@Test
public
void
test
(){
CaseActuator
httpClientActuator
=
new
CaseActuator
(
1
l
,
1
l
);
String
json
=
"{\n"
+
" \"url\":\"http://127.0.0.1:13245/test/sayHelloJson\",\n"
+
" \"method\":\"POST\",\n"
+
" \"requestType\":\"JSON\",\n"
+
" \"stringValue\":\"{\\\"name\\\":\\\"${componentName}[0]\\\"}\",\n"
+
" \"headers\":[\n"
+
" {\n"
+
" \"name\":\"cookie\",\n"
+
" \"value\":\"123456\"\n"
+
" }\n"
+
" ]\n"
+
"}"
;
TestCase
testCase
=
new
TestCase
();
testCase
.
setName
(
"name"
);
testCase
.
setType
(
1
);
testCase
.
setDetail
(
json
);
testCase
.
setAbnormalCheckpoint
(
1
);
testCase
.
setContainCheckpoint
(
"xxxxxxx"
);
TestCaseExecuteResult
testCaseExecuteResult
=
httpClientActuator
.
executeTestCase
(
testCase
);
System
.
out
.
println
(
testCaseExecuteResult
);
}
}
kt-base/src/test/java/org/matrix/actuators/sql/HttpClientActuatorTest.java
浏览文件 @
a398b171
package
org
.
matrix
.
actuators
.
sql
;
import
com.alibaba.fastjson.JSON
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.matrix.actuators.httpclient.HttpClientActuator
;
import
org.matrix.actuators.httpclient.HttpRequestDetail
;
import
org.matrix.actuators.httpclient.HttpResponseDetail
;
import
org.matrix.config.HttpRequestConfig
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
...
...
@@ -12,17 +14,18 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
public
class
HttpClientActuatorTest
{
@Test
public
void
test
(){
HttpClientActuator
httpClientActuator
=
new
HttpClientActuator
(
new
HttpRequestConfig
(),
0
l
,
0
l
1
l
,
1
l
);
String
json
=
"{\n"
+
" \"url\":\"http://127.0.0.1:13245/test/sayHelloJson\",\n"
+
" \"method\":\"POST\",\n"
+
" \"requestType\":\"JSON\",\n"
+
" \"stringValue\":\"{\\\"name\\\":\\\"
李四
\\\"}\",\n"
+
" \"stringValue\":\"{\\\"name\\\":\\\"
${componentName}[0]
\\\"}\",\n"
+
" \"headers\":[\n"
+
" {\n"
+
" \"name\":\"cookie\",\n"
+
...
...
@@ -31,7 +34,8 @@ public class HttpClientActuatorTest {
" ]\n"
+
"}"
;
HttpRequestDetail
httpRequestDetail
=
JSON
.
parseObject
(
json
,
HttpRequestDetail
.
class
);
httpClientActuator
.
sendHttpRequest
(
httpRequestDetail
);
HttpResponseDetail
httpResponseDetail
=
httpClientActuator
.
sendHttpRequest
(
httpRequestDetail
);
System
.
out
.
println
(
httpResponseDetail
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论