fix(接口测试): 场景执行添加自定义请求参数
This commit is contained in:
parent
665e09df41
commit
9c868f8097
|
@ -557,7 +557,7 @@ CREATE TABLE IF NOT EXISTS api_test_case_blob(
|
|||
CREATE TABLE IF NOT EXISTS api_file_resource(
|
||||
`resource_id` VARCHAR(50) NOT NULL COMMENT '资源ID(接口用例等)' ,
|
||||
`file_id` VARCHAR(50) NOT NULL COMMENT '文件ID' ,
|
||||
`file_name` VARCHAR(50) NOT NULL COMMENT '文件名称' ,
|
||||
`file_name` VARCHAR(255) NOT NULL COMMENT '文件名称' ,
|
||||
`resource_type` VARCHAR(50) NOT NULL COMMENT '资源类型(API_DEBUG,API,API_CASE,API_SCENARIO)' ,
|
||||
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
|
||||
`project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' ,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package io.metersphere.plugin.api.spi;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 协议组件的抽象类
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2023-10-30 15:08
|
||||
*/
|
||||
@Data
|
||||
public abstract class AbstractMsProtocolTestElement extends AbstractMsTestElement {
|
||||
/**
|
||||
* 是否是自定义请求
|
||||
*/
|
||||
private Boolean customizeRequest = false;
|
||||
/**
|
||||
* 自定义请求是否启用环境
|
||||
*/
|
||||
private Boolean customizeRequestEnvEnable = false;
|
||||
}
|
|
@ -2,7 +2,7 @@ package io.metersphere.api.dto.request.http;
|
|||
|
||||
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig;
|
||||
import io.metersphere.api.dto.request.http.body.Body;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.system.valid.EnumValue;
|
||||
import jakarta.validation.Valid;
|
||||
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MsHTTPElement extends AbstractMsTestElement {
|
||||
public class MsHTTPElement extends AbstractMsProtocolTestElement {
|
||||
/**
|
||||
* 完整请求地址
|
||||
* 自定义请求时,使用该字段
|
||||
|
|
|
@ -70,8 +70,8 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
}
|
||||
|
||||
ApiParamConfig apiParamConfig = (ApiParamConfig) config;
|
||||
HttpConfig httpConfig = getHttpConfig(msHTTPElement, apiParamConfig);
|
||||
EnvironmentInfoDTO envConfig = apiParamConfig.getEnvConfig(msHTTPElement.getProjectId());
|
||||
EnvironmentInfoDTO envConfig = isEnvEnable(msHTTPElement) ? apiParamConfig.getEnvConfig(msHTTPElement.getProjectId()) : null;
|
||||
HttpConfig httpConfig = getHttpConfig(msHTTPElement, envConfig);
|
||||
|
||||
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
|
||||
sampler.setName(msHTTPElement.getName());
|
||||
|
@ -98,6 +98,7 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
// 处理请求头
|
||||
HeaderManager httpHeader = getHttpHeader(msHTTPElement, apiParamConfig, httpConfig);
|
||||
Optional.ofNullable(httpHeader).ifPresent(httpTree::add);
|
||||
|
||||
//处理host
|
||||
DNSCacheManager dnsCacheManager = getEnvDns(msHTTPElement.getName(), envConfig, httpConfig);
|
||||
Optional.ofNullable(dnsCacheManager).ifPresent(httpTree::add);
|
||||
|
@ -111,6 +112,21 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
parseChild(httpTree, msHTTPElement, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否启用环境
|
||||
* 非自定义请求启用
|
||||
* 自定义请求需要判断是否启用
|
||||
* @param httpElement
|
||||
* @return
|
||||
*/
|
||||
private boolean isEnvEnable(MsHTTPElement httpElement) {
|
||||
if (BooleanUtils.isTrue(httpElement.getCustomizeRequest())) {
|
||||
return BooleanUtils.isTrue(httpElement.getCustomizeRequestEnvEnable());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置超时时间等配置
|
||||
|
@ -341,12 +357,10 @@ public class MsHTTPElementConverter extends AbstractJmeterElementConverter<MsHTT
|
|||
* 获取环境 http 配置
|
||||
*
|
||||
* @param msHTTPElement
|
||||
* @param config
|
||||
* @param envConfig
|
||||
* @return
|
||||
*/
|
||||
private HttpConfig getHttpConfig(MsHTTPElement msHTTPElement, ApiParamConfig config) {
|
||||
ApiParamConfig apiParamConfig = config;
|
||||
EnvironmentInfoDTO envConfig = apiParamConfig.getEnvConfig();
|
||||
private HttpConfig getHttpConfig(MsHTTPElement msHTTPElement, EnvironmentInfoDTO envConfig) {
|
||||
if (envConfig == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue