Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
49108091
提交
49108091
authored
2月 14, 2022
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(base): 美化了一下代码排版
上级
02654234
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
58 行增加
和
25 行删除
+58
-25
CheckPointActuator.java
...a/org/matrix/actuators/checkpoint/CheckPointActuator.java
+9
-5
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+12
-15
CompleteExpressionUtil.java
...ava/org/matrix/actuators/util/CompleteExpressionUtil.java
+10
-3
application.yml
kt-script/src/main/resources/application.yml
+2
-0
pom.xml
kt-web/pom.xml
+5
-0
PageQueryTest.java
kt-web/src/main/java/org/matrix/PageQueryTest.java
+12
-0
application.yml
kt-web/src/main/resources/application.yml
+4
-2
AppTest.java
kt-web/src/test/java/org/matrix/AppTest.java
+4
-0
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/checkpoint/CheckPointActuator.java
浏览文件 @
49108091
...
@@ -38,7 +38,11 @@ public class CheckPointActuator implements Actuator {
...
@@ -38,7 +38,11 @@ public class CheckPointActuator implements Actuator {
String
baseJsString
;
String
baseJsString
;
public
CheckPointActuator
(
@Value
(
"${baseJsPath}"
)
String
baseJs
)
{
final
CompleteExpressionUtil
completeExpressionUtil
;
public
CheckPointActuator
(
@Value
(
"${baseJsPath}"
)
String
baseJs
,
CompleteExpressionUtil
completeExpressionUtil
)
{
this
.
completeExpressionUtil
=
completeExpressionUtil
;
ClassPathResource
cpr
=
new
ClassPathResource
(
baseJs
);
ClassPathResource
cpr
=
new
ClassPathResource
(
baseJs
);
try
{
try
{
this
.
baseJsString
=
IOUtils
.
toString
(
cpr
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
this
.
baseJsString
=
IOUtils
.
toString
(
cpr
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
...
@@ -78,13 +82,13 @@ public class CheckPointActuator implements Actuator {
...
@@ -78,13 +82,13 @@ public class CheckPointActuator implements Actuator {
public
CheckPointResultDetail
jsonPathCheck
(
String
jsonPathCheckPoint
,
Object
jsonObject
,
Long
envId
,
Long
projectId
)
{
public
CheckPointResultDetail
jsonPathCheck
(
String
jsonPathCheckPoint
,
Object
jsonObject
,
Long
envId
,
Long
projectId
)
{
String
expression
=
jsonPathCheckPoint
;
String
expression
=
jsonPathCheckPoint
;
try
{
try
{
expression
=
C
ompleteExpressionUtil
.
completeDynamicVariable
(
expression
=
c
ompleteExpressionUtil
.
completeDynamicVariable
(
expression
,
expression
,
envId
,
envId
,
projectId
)
projectId
)
;
;
//todo 李迪凡 先将result中的动态变量都还原出来 (先后顺序不能乱)得先还原动态变量
//todo 李迪凡 先将result中的动态变量都还原出来 (先后顺序不能乱)得先还原动态变量
expression
=
C
ompleteExpressionUtil
.
completeJsonPathExpression
(
expression
=
c
ompleteExpressionUtil
.
completeJsonPathExpression
(
expression
,
expression
,
jsonObject
jsonObject
);
);
...
@@ -151,7 +155,7 @@ public class CheckPointActuator implements Actuator {
...
@@ -151,7 +155,7 @@ public class CheckPointActuator implements Actuator {
List
<
CheckPointResultDetail
>
resultDetails
=
new
ArrayList
<>();
List
<
CheckPointResultDetail
>
resultDetails
=
new
ArrayList
<>();
String
[]
split
=
containCheckPoint
.
split
(
","
);
String
[]
split
=
containCheckPoint
.
split
(
","
);
for
(
String
containExpression
:
split
)
{
for
(
String
containExpression
:
split
)
{
String
parseContainExpression
=
C
ompleteExpressionUtil
.
completeDynamicVariable
(
String
parseContainExpression
=
c
ompleteExpressionUtil
.
completeDynamicVariable
(
containExpression
,
containExpression
,
envId
,
envId
,
projectId
)
projectId
)
...
@@ -181,7 +185,7 @@ public class CheckPointActuator implements Actuator {
...
@@ -181,7 +185,7 @@ public class CheckPointActuator implements Actuator {
List
<
CheckPointResultDetail
>
resultDetails
=
new
ArrayList
<>();
List
<
CheckPointResultDetail
>
resultDetails
=
new
ArrayList
<>();
String
[]
split
=
noContainCheckPoint
.
split
(
","
);
String
[]
split
=
noContainCheckPoint
.
split
(
","
);
for
(
String
noContainExpression
:
split
)
{
for
(
String
noContainExpression
:
split
)
{
String
parseNoContainExpression
=
C
ompleteExpressionUtil
.
completeDynamicVariable
(
String
parseNoContainExpression
=
c
ompleteExpressionUtil
.
completeDynamicVariable
(
noContainExpression
,
noContainExpression
,
envId
,
envId
,
projectId
)
projectId
)
...
...
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
49108091
...
@@ -5,12 +5,10 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -5,12 +5,10 @@ import org.apache.commons.lang3.StringUtils;
import
org.apache.http.conn.HttpHostConnectException
;
import
org.apache.http.conn.HttpHostConnectException
;
import
org.matrix.actuators.Actuator
;
import
org.matrix.actuators.Actuator
;
import
org.matrix.actuators.util.CompleteExpressionUtil
;
import
org.matrix.actuators.util.CompleteExpressionUtil
;
import
org.matrix.config.HttpRequestConfig
;
import
org.apache.http.Consts
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHeaders
;
import
org.apache.http.HttpHeaders
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.*
;
import
org.apache.http.client.methods.*
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.client.utils.URIBuilder
;
...
@@ -22,7 +20,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
...
@@ -22,7 +20,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.http.util.EntityUtils
;
import
org.matrix.exception.HttpRequestException
;
import
org.matrix.exception.HttpRequestException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -32,16 +29,12 @@ import java.io.FileInputStream;
...
@@ -32,16 +29,12 @@ import java.io.FileInputStream;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.net.URISyntaxException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* HttpClient调用封装
* HttpClient调用封装
* todo 打印LOG
* @author HuangXiahao
* @author HuangXiahao
**/
**/
@Component
@Component
...
@@ -50,8 +43,12 @@ public class HttpClientActuator implements Actuator {
...
@@ -50,8 +43,12 @@ public class HttpClientActuator implements Actuator {
final
final
CloseableHttpClient
client
;
CloseableHttpClient
client
;
public
HttpClientActuator
(
CloseableHttpClient
client
)
{
final
CompleteExpressionUtil
completeExpressionUtil
;
public
HttpClientActuator
(
CloseableHttpClient
client
,
CompleteExpressionUtil
completeExpressionUtil
)
{
this
.
client
=
client
;
this
.
client
=
client
;
this
.
completeExpressionUtil
=
completeExpressionUtil
;
}
}
/**
/**
...
@@ -62,13 +59,13 @@ public class HttpClientActuator implements Actuator {
...
@@ -62,13 +59,13 @@ public class HttpClientActuator implements Actuator {
//todo 李迪凡 将header中的key和value里的 动态变量补全
//todo 李迪凡 将header中的key和value里的 动态变量补全
//获取动态变量,并将动态变量替换进去
//获取动态变量,并将动态变量替换进去
header
.
setName
(
header
.
setName
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
header
.
getName
(),
header
.
getName
(),
envId
,
envId
,
projectId
)
projectId
)
);
);
header
.
setValue
(
header
.
setValue
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
header
.
getValue
(),
header
.
getValue
(),
envId
,
envId
,
projectId
)
projectId
)
...
@@ -77,13 +74,13 @@ public class HttpClientActuator implements Actuator {
...
@@ -77,13 +74,13 @@ public class HttpClientActuator implements Actuator {
for
(
RequestBody
requestBody
:
httpRequestDetail
.
getRequestBodies
())
{
for
(
RequestBody
requestBody
:
httpRequestDetail
.
getRequestBodies
())
{
//todo 李迪凡 将requestBody中的key和value里的 动态变量补全
//todo 李迪凡 将requestBody中的key和value里的 动态变量补全
requestBody
.
setKey
(
requestBody
.
setKey
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
requestBody
.
getKey
(),
requestBody
.
getKey
(),
envId
,
envId
,
projectId
)
projectId
)
);
);
requestBody
.
setValue
(
requestBody
.
setValue
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
requestBody
.
getValue
(),
requestBody
.
getValue
(),
envId
,
envId
,
projectId
)
projectId
)
...
@@ -92,14 +89,14 @@ public class HttpClientActuator implements Actuator {
...
@@ -92,14 +89,14 @@ public class HttpClientActuator implements Actuator {
if
(!
StringUtils
.
isEmpty
(
httpRequestDetail
.
getStringValue
())){
if
(!
StringUtils
.
isEmpty
(
httpRequestDetail
.
getStringValue
())){
//todo 李迪凡 将httpRequestDetail的stringValue 动态变量补全
//todo 李迪凡 将httpRequestDetail的stringValue 动态变量补全
httpRequestDetail
.
setStringValue
(
httpRequestDetail
.
setStringValue
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
httpRequestDetail
.
getStringValue
(),
httpRequestDetail
.
getStringValue
(),
envId
,
envId
,
projectId
)
projectId
)
);
);
}
}
//todo 李迪凡 将httpRequestDetail的url 动态变量补全
//todo 李迪凡 将httpRequestDetail的url 动态变量补全
httpRequestDetail
.
setUrl
(
C
ompleteExpressionUtil
.
completeDynamicVariable
(
httpRequestDetail
.
setUrl
(
c
ompleteExpressionUtil
.
completeDynamicVariable
(
httpRequestDetail
.
getUrl
(),
httpRequestDetail
.
getUrl
(),
envId
,
envId
,
projectId
));
projectId
));
...
@@ -301,7 +298,7 @@ public class HttpClientActuator implements Actuator {
...
@@ -301,7 +298,7 @@ public class HttpClientActuator implements Actuator {
response
.
close
();
response
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
HttpRequestException
(
String
.
format
(
"关闭返回流失败"
)
);
throw
new
HttpRequestException
(
"关闭返回流失败"
);
}
}
}
}
}
}
...
...
kt-base/src/main/java/org/matrix/actuators/util/CompleteExpressionUtil.java
浏览文件 @
49108091
...
@@ -6,6 +6,8 @@ import com.jayway.jsonpath.JsonPath;
...
@@ -6,6 +6,8 @@ import com.jayway.jsonpath.JsonPath;
import
org.matrix.actuators.checkpoint.JsonPathCheckPoint
;
import
org.matrix.actuators.checkpoint.JsonPathCheckPoint
;
import
org.matrix.actuators.sql.SqlExpActuator
;
import
org.matrix.actuators.sql.SqlExpActuator
;
import
org.matrix.util.SpringUtils
;
import
org.matrix.util.SpringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.function.BiFunction
;
import
java.util.function.BiFunction
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
...
@@ -15,6 +17,7 @@ import java.util.regex.Pattern;
...
@@ -15,6 +17,7 @@ import java.util.regex.Pattern;
* 补全http和检验点中的表达式的一些公共方法
* 补全http和检验点中的表达式的一些公共方法
* @author huangxiahao
* @author huangxiahao
*/
*/
@Component
public
class
CompleteExpressionUtil
{
public
class
CompleteExpressionUtil
{
public
static
final
String
JSON_PATH_REG
=
"\\{(\\s)*\\$.*?}"
;
public
static
final
String
JSON_PATH_REG
=
"\\{(\\s)*\\$.*?}"
;
...
@@ -25,7 +28,8 @@ public class CompleteExpressionUtil {
...
@@ -25,7 +28,8 @@ public class CompleteExpressionUtil {
public
static
final
String
DYNAMIC_VARIABLE_REG
=
"\\$\\{(((?!pre\\.).)*?)}(\\[(.*?)])?"
;
public
static
final
String
DYNAMIC_VARIABLE_REG
=
"\\$\\{(((?!pre\\.).)*?)}(\\[(.*?)])?"
;
public
static
String
completeDynamicVariable
(
String
expression
,
Long
envId
,
Long
projectId
)
{
public
String
completeDynamicVariable
(
String
expression
,
Long
envId
,
Long
projectId
)
{
String
result
=
expression
;
String
result
=
expression
;
result
=
regexExpression
(
result
,
DYNAMIC_VARIABLE_REG
,
null
,
(
o
,
s
)
->
getSqlExpActuator
().
parseVarByName
(
s
,
envId
,
projectId
));
result
=
regexExpression
(
result
,
DYNAMIC_VARIABLE_REG
,
null
,
(
o
,
s
)
->
getSqlExpActuator
().
parseVarByName
(
s
,
envId
,
projectId
));
return
result
;
return
result
;
...
@@ -36,13 +40,13 @@ public class CompleteExpressionUtil {
...
@@ -36,13 +40,13 @@ public class CompleteExpressionUtil {
* @param jsonObject 这个Object 是由 Configuration.defaultConfiguration().jsonProvider().parse(“json字符串”); 这个方法转换过来的 请不要乱传
* @param jsonObject 这个Object 是由 Configuration.defaultConfiguration().jsonProvider().parse(“json字符串”); 这个方法转换过来的 请不要乱传
* @return
* @return
*/
*/
public
static
String
completeJsonPathExpression
(
String
expression
,
Object
jsonObject
)
{
public
String
completeJsonPathExpression
(
String
expression
,
Object
jsonObject
)
{
String
result
=
expression
;
String
result
=
expression
;
result
=
regexExpression
(
result
,
JSON_PATH_REG
,
jsonObject
,
(
o
,
s
)
->
JSON
.
toJSONString
(
JsonPath
.
read
(
o
,
s
.
substring
(
1
,
s
.
length
()
-
1
))));
result
=
regexExpression
(
result
,
JSON_PATH_REG
,
jsonObject
,
(
o
,
s
)
->
JSON
.
toJSONString
(
JsonPath
.
read
(
o
,
s
.
substring
(
1
,
s
.
length
()
-
1
))));
return
result
;
return
result
;
}
}
public
static
String
regexExpression
(
String
expression
,
String
regex
,
Object
sourceContent
,
BiFunction
<
Object
,
String
,
String
>
biFunction
){
public
String
regexExpression
(
String
expression
,
String
regex
,
Object
sourceContent
,
BiFunction
<
Object
,
String
,
String
>
biFunction
){
String
result
=
expression
;
String
result
=
expression
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Matcher
mat
=
pattern
.
matcher
(
result
);
Matcher
mat
=
pattern
.
matcher
(
result
);
...
@@ -57,4 +61,7 @@ public class CompleteExpressionUtil {
...
@@ -57,4 +61,7 @@ public class CompleteExpressionUtil {
private
static
SqlExpActuator
getSqlExpActuator
(){
private
static
SqlExpActuator
getSqlExpActuator
(){
return
SpringUtils
.
getBean
(
"sqlExpActuator"
);
return
SpringUtils
.
getBean
(
"sqlExpActuator"
);
}
}
}
}
kt-script/src/main/resources/application.yml
浏览文件 @
49108091
...
@@ -14,5 +14,6 @@ spring:
...
@@ -14,5 +14,6 @@ spring:
mybatis-plus
:
mybatis-plus
:
type-enums-package
:
org.matrix.enums
type-enums-package
:
org.matrix.enums
baseJsPath
:
syntaxCheck.js
baseJsPath
:
syntaxCheck.js
baseJsPath
:
syntaxCheck.js
\ No newline at end of file
kt-web/pom.xml
浏览文件 @
49108091
...
@@ -24,6 +24,11 @@
...
@@ -24,6 +24,11 @@
<artifactId>
mybatis-plus-generator
</artifactId>
<artifactId>
mybatis-plus-generator
</artifactId>
<version>
3.5.1
</version>
<version>
3.5.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
...
...
kt-web/src/main/java/org/matrix/PageQueryTest.java
0 → 100644
浏览文件 @
49108091
package
org
.
matrix
;
import
lombok.Data
;
@Data
public
class
PageQueryTest
{
int
id
;
int
pageNum
;
int
size
;
}
kt-web/src/main/resources/application.yml
浏览文件 @
49108091
...
@@ -15,6 +15,9 @@ spring:
...
@@ -15,6 +15,9 @@ spring:
password
:
root
password
:
root
mybatis-plus
:
mybatis-plus
:
configuration
:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
type-enums-package
:
org.matrix.enums
type-enums-package
:
org.matrix.enums
baseJsPath
:
syntaxCheck.js
baseJsPath
:
syntaxCheck.js
\ No newline at end of file
kt-web/src/test/java/org/matrix/AppTest.java
浏览文件 @
49108091
package
org
.
matrix
;
package
org
.
matrix
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
/**
/**
* Unit test for simple App.
* Unit test for simple App.
*/
*/
@SpringBootTest
public
class
AppTest
{
public
class
AppTest
{
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论