Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
kt-keystone
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
kt-keystone
Commits
021bdf60
提交
021bdf60
authored
4月 27, 2022
作者:
Matrix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(用例执行器): 用例执行器现在可以同时使用path和body了
上级
38411ad4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
65 行增加
和
28 行删除
+65
-28
HttpClientActuator.java
...a/org/matrix/actuators/httpclient/HttpClientActuator.java
+21
-18
HttpRequestDetail.java
...va/org/matrix/actuators/httpclient/HttpRequestDetail.java
+3
-1
RequestParam.java
...in/java/org/matrix/actuators/httpclient/RequestParam.java
+28
-0
SqlExpActuator.java
...rc/main/java/org/matrix/actuators/sql/SqlExpActuator.java
+1
-1
HttpClientActuatorTest.java
...ava/org/matrix/actuators/http/HttpClientActuatorTest.java
+12
-8
没有找到文件。
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpClientActuator.java
浏览文件 @
021bdf60
...
@@ -276,28 +276,31 @@ public class HttpClientActuator implements Actuator {
...
@@ -276,28 +276,31 @@ public class HttpClientActuator implements Actuator {
public
String
initUrlString
(
HttpRequestDetail
httpRequestDetail
,
Long
envId
,
Long
projectId
)
{
public
String
initUrlString
(
HttpRequestDetail
httpRequestDetail
,
Long
envId
,
Long
projectId
)
{
String
url
=
httpRequestDetail
.
getUrl
();
String
url
=
httpRequestDetail
.
getUrl
();
try
{
try
{
if
(
httpRequestDetail
.
getRequestType
()
==
HttpRequestType
.
QUERY
)
{
for
(
RequestParam
param
:
httpRequestDetail
.
getRequestParams
())
{
if
(
httpRequestDetail
.
getMethod
().
equals
(
HttpMethod
.
GET
))
{
if
(
param
.
getRequestType
()
==
HttpRequestType
.
QUERY
)
{
URIBuilder
uriBuilder
;
if
(
httpRequestDetail
.
getMethod
().
equals
(
HttpMethod
.
GET
))
{
uriBuilder
=
new
URIBuilder
(
url
);
URIBuilder
uriBuilder
;
for
(
RequestBody
requestBody
:
httpRequestDetail
.
getRequestBodies
())
{
uriBuilder
=
new
URIBuilder
(
url
);
switch
(
requestBody
.
getType
())
{
for
(
RequestBody
requestBody
:
httpRequestDetail
.
getRequestBodies
())
{
case
TEXT:
switch
(
requestBody
.
getType
())
{
uriBuilder
.
setParameter
(
requestBody
.
getKey
(),
requestBody
.
getValue
());
case
TEXT:
break
;
uriBuilder
.
setParameter
(
requestBody
.
getKey
(),
requestBody
.
getValue
());
case
FILE:
break
;
throw
new
NullPointerException
(
"QUERY请求不能传入文件流"
);
case
FILE:
default
:
throw
new
NullPointerException
(
"QUERY请求不能传入文件流"
);
default
:
}
}
}
url
=
uriBuilder
.
build
().
toString
();
}
}
url
=
uriBuilder
.
build
().
toString
();
}
else
if
(
param
.
getRequestType
()
==
HttpRequestType
.
PATH
){
List
<
RequestBody
>
requestBodies
=
param
.
getRequestBodies
();
Map
<
String
,
String
>
requestMap
=
requestBodies
.
stream
().
collect
(
Collectors
.
toMap
(
RequestBody:
:
getKey
,
RequestBody:
:
getValue
));
url
=
completeExpressionUtil
.
completePathVariable
(
url
,
requestMap
,
envId
,
projectId
);
}
}
}
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
,
envId
,
projectId
);
}
}
}
catch
(
URISyntaxException
e
)
{
}
catch
(
URISyntaxException
e
)
{
throw
new
HttpRequestException
(
String
.
format
(
"URL格式不正确,不正确的URL为: %s"
,
url
));
throw
new
HttpRequestException
(
String
.
format
(
"URL格式不正确,不正确的URL为: %s"
,
url
));
}
}
...
...
kt-base/src/main/java/org/matrix/actuators/httpclient/HttpRequestDetail.java
浏览文件 @
021bdf60
...
@@ -32,9 +32,11 @@ public class HttpRequestDetail {
...
@@ -32,9 +32,11 @@ public class HttpRequestDetail {
@ApiModelProperty
(
"键值对入参"
)
@ApiModelProperty
(
"键值对入参"
)
private
List
<
RequestBody
>
requestBodies
=
new
ArrayList
<>();
private
List
<
RequestBody
>
requestBodies
=
new
ArrayList
<>();
@ApiModelProperty
(
"复合参数组"
)
private
List
<
RequestParam
>
requestParams
=
new
ArrayList
<>();
/**
/**
* 增加键值对入参
* 增加键值对入参
*/
*/
private
Boolean
addRequestBody
(
RequestBody
requestBody
)
{
private
Boolean
addRequestBody
(
RequestBody
requestBody
)
{
return
requestBodies
.
add
(
requestBody
);
return
requestBodies
.
add
(
requestBody
);
...
...
kt-base/src/main/java/org/matrix/actuators/httpclient/RequestParam.java
0 → 100644
浏览文件 @
021bdf60
package
org
.
matrix
.
actuators
.
httpclient
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* RequestParam. 用于复合参数
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2022/4/24 at 4:48 PM
* Suffering is the most powerful teacher of life.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
RequestParam
{
@ApiModelProperty
(
"请求类型"
)
private
HttpRequestType
requestType
=
HttpRequestType
.
NONE
;
@ApiModelProperty
(
"键值对入参"
)
private
List
<
RequestBody
>
requestBodies
=
new
ArrayList
<>();
}
kt-base/src/main/java/org/matrix/actuators/sql/SqlExpActuator.java
浏览文件 @
021bdf60
...
@@ -66,7 +66,7 @@ public class SqlExpActuator implements Actuator {
...
@@ -66,7 +66,7 @@ public class SqlExpActuator implements Actuator {
private
final
ITestDataService
dataService
;
private
final
ITestDataService
dataService
;
/**
/**
* 解析并运行SQL语句,可以包含别的SQL变量,例如 'select * from user where user.id = ${user_id}
'
* 解析并运行SQL语句,可以包含别的SQL变量,例如 'select * from user where user.id = ${user_id}'
*
*
* @param sqlDetail sql的poolId与sql语句的对象
* @param sqlDetail sql的poolId与sql语句的对象
* @param envId 环境id
* @param envId 环境id
...
...
kt-base/src/test/java/org/matrix/actuators/http/HttpClientActuatorTest.java
浏览文件 @
021bdf60
...
@@ -6,22 +6,20 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -6,22 +6,20 @@ import com.alibaba.fastjson.JSONObject;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.matrix.actuators.httpclient.HttpClientActuator
;
import
org.matrix.actuators.httpclient.*
;
import
org.matrix.actuators.httpclient.HttpRequestDetail
;
import
org.matrix.actuators.httpclient.HttpResponseDetail
;
import
org.matrix.config.HttpRequestConfig
;
import
org.matrix.config.HttpRequestConfig
;
import
org.matrix.database.entity.ExecutionRecord
;
import
org.matrix.database.entity.ExecutionRecord
;
import
org.matrix.database.service.IExecutionRecordService
;
import
org.matrix.database.service.IExecutionRecordService
;
import
org.matrix.exception.GlobalException
;
import
org.matrix.exception.GlobalException
;
import
org.matrix.socket.enums.TestExecuteType
;
import
org.matrix.socket.enums.TestExecuteType
;
import
org.matrix.util.JsonUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.testng.collections.Lists
;
import
java.util.List
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.Optional
;
import
static
java
.
util
.
stream
.
Collectors
.
groupingBy
;
import
static
java
.
util
.
stream
.
Collectors
.
groupingBy
;
...
@@ -41,10 +39,16 @@ class HttpClientActuatorTest {
...
@@ -41,10 +39,16 @@ class HttpClientActuatorTest {
JSONObject
stringValue
=
new
JSONObject
();
JSONObject
stringValue
=
new
JSONObject
();
stringValue
.
put
(
"account"
,
"hxh"
);
stringValue
.
put
(
"account"
,
"hxh"
);
stringValue
.
put
(
"password"
,
"hxh1234567"
);
stringValue
.
put
(
"password"
,
"hxh1234567"
);
jsonObject
.
put
(
"url"
,
"http://127.0.0.1:8765/user/
login
"
);
jsonObject
.
put
(
"url"
,
"http://127.0.0.1:8765/user/
{id}
"
);
jsonObject
.
put
(
"method"
,
"POST"
);
jsonObject
.
put
(
"method"
,
"POST"
);
jsonObject
.
put
(
"requestType"
,
"JSON"
);
jsonObject
.
put
(
"requestType"
,
"JSON"
);
jsonObject
.
put
(
"stringValue"
,
JSONObject
.
toJSON
(
stringValue
));
jsonObject
.
put
(
"stringValue"
,
JSONObject
.
toJSON
(
stringValue
));
JSONArray
array
=
new
JSONArray
();
JSONObject
jsonObject1
=
new
JSONObject
();
jsonObject1
.
put
(
"requestType"
,
HttpRequestType
.
PATH
);
jsonObject1
.
put
(
"requestBodies"
,
new
RequestBody
(
"id"
,
MultiPartRequestBodyType
.
TEXT
,
"login"
));
array
.
add
(
jsonObject1
);
jsonObject
.
put
(
"requestParams"
,
array
);
// String json = "{\n" +
// String json = "{\n" +
...
@@ -58,7 +62,7 @@ class HttpClientActuatorTest {
...
@@ -58,7 +62,7 @@ class HttpClientActuatorTest {
// "}";
// "}";
HttpRequestDetail
httpRequestDetail1
=
JSON
.
parseObject
(
JSONObject
.
toJSONString
(
jsonObject
),
HttpRequestDetail
.
class
);
HttpRequestDetail
httpRequestDetail1
=
JSON
.
parseObject
(
JSONObject
.
toJSONString
(
jsonObject
),
HttpRequestDetail
.
class
);
HttpRequestDetail
httpRequestDetail
=
JSON
.
parseObject
(
JSONObject
.
toJSONString
(
jsonObject
),
HttpRequestDetail
.
class
);
HttpRequestDetail
httpRequestDetail
=
JSON
.
parseObject
(
JSONObject
.
toJSONString
(
jsonObject
),
HttpRequestDetail
.
class
);
HttpResponseDetail
httpResponseDetail
=
httpClientActuator
.
sendHttpRequest
(
httpRequestDetail
,
1
l
,
1
l
);
HttpResponseDetail
httpResponseDetail
=
httpClientActuator
.
sendHttpRequest
(
httpRequestDetail
,
1
0
l
,
1
l
);
System
.
out
.
println
(
httpResponseDetail
);
System
.
out
.
println
(
httpResponseDetail
);
}
}
@Test
@Test
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论