提交 021bdf60 authored 作者: Matrix's avatar Matrix

fix(用例执行器): 用例执行器现在可以同时使用path和body了

上级 38411ad4
......@@ -276,7 +276,8 @@ public class HttpClientActuator implements Actuator {
public String initUrlString(HttpRequestDetail httpRequestDetail,Long envId, Long projectId) {
String url = httpRequestDetail.getUrl();
try {
if (httpRequestDetail.getRequestType() == HttpRequestType.QUERY) {
for (RequestParam param : httpRequestDetail.getRequestParams()) {
if (param.getRequestType() == HttpRequestType.QUERY) {
if (httpRequestDetail.getMethod().equals(HttpMethod.GET)) {
URIBuilder uriBuilder;
uriBuilder = new URIBuilder(url);
......@@ -292,12 +293,14 @@ public class HttpClientActuator implements Actuator {
}
url = uriBuilder.build().toString();
}
}else if(httpRequestDetail.getRequestType() == HttpRequestType.PATH){
List<RequestBody> requestBodies = httpRequestDetail.getRequestBodies();
}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);
}
}
} catch (URISyntaxException e) {
throw new HttpRequestException(String.format("URL格式不正确,不正确的URL为: %s",url));
}
......
......@@ -32,9 +32,11 @@ public class HttpRequestDetail {
@ApiModelProperty("键值对入参")
private List<RequestBody> requestBodies = new ArrayList<>();
@ApiModelProperty("复合参数组")
private List<RequestParam> requestParams = new ArrayList<>();
/**
* 增加键值对入参
*/
private Boolean addRequestBody(RequestBody requestBody) {
return requestBodies.add(requestBody);
......
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<>();
}
......@@ -66,7 +66,7 @@ public class SqlExpActuator implements Actuator {
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 envId 环境id
......
......@@ -6,22 +6,20 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.httpclient.*;
import org.matrix.config.HttpRequestConfig;
import org.matrix.database.entity.ExecutionRecord;
import org.matrix.database.service.IExecutionRecordService;
import org.matrix.exception.GlobalException;
import org.matrix.socket.enums.TestExecuteType;
import org.matrix.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
import org.testng.collections.Lists;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import static java.util.stream.Collectors.groupingBy;
......@@ -41,10 +39,16 @@ class HttpClientActuatorTest {
JSONObject stringValue = new JSONObject();
stringValue.put("account","hxh");
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("requestType","JSON");
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" +
......@@ -58,7 +62,7 @@ class HttpClientActuatorTest {
// "}";
HttpRequestDetail httpRequestDetail1 = JSON.parseObject(JSONObject.toJSONString(jsonObject), HttpRequestDetail.class);
HttpRequestDetail httpRequestDetail = JSON.parseObject(JSONObject.toJSONString(jsonObject), HttpRequestDetail.class);
HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail,1l,1l);
HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail,10l,1l);
System.out.println(httpResponseDetail);
}
@Test
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论