refactor(接口测试): 优化接口插件获取环境参数
This commit is contained in:
parent
c7b0e9f8f7
commit
b1a48dcd94
|
@ -3,6 +3,8 @@ package io.metersphere.plugin.api.dto;
|
||||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: jianxing
|
* @Author: jianxing
|
||||||
* @CreateTime: 2023-10-27 17:30
|
* @CreateTime: 2023-10-27 17:30
|
||||||
|
@ -21,5 +23,5 @@ public abstract class ParameterConfig {
|
||||||
* @param msTestElement 当前 AbstractMsTestElement 的实现类对象
|
* @param msTestElement 当前 AbstractMsTestElement 的实现类对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract Object getProtocolEnvConfig(AbstractMsTestElement msTestElement);
|
public abstract Map<String, Object> getProtocolEnvConfig(AbstractMsTestElement msTestElement);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class ApiParamConfig extends ParameterConfig {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getProtocolEnvConfig(AbstractMsTestElement msTestElement) {
|
public Map<String, Object> getProtocolEnvConfig(AbstractMsTestElement msTestElement) {
|
||||||
return getProtocolEnvConfig(msTestElement, getEnvConfig());
|
return getProtocolEnvConfig(msTestElement, getEnvConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class ApiParamConfig extends ParameterConfig {
|
||||||
* @param envConfig 当前的环境配置信息
|
* @param envConfig 当前的环境配置信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Object getProtocolEnvConfig(AbstractMsTestElement msTestElement,
|
public Map<String, Object> getProtocolEnvConfig(AbstractMsTestElement msTestElement,
|
||||||
EnvironmentInfoDTO envConfig) {
|
EnvironmentInfoDTO envConfig) {
|
||||||
if (envConfig == null
|
if (envConfig == null
|
||||||
|| envConfig.getConfig() == null
|
|| envConfig.getConfig() == null
|
||||||
|
@ -49,7 +49,7 @@ public class ApiParamConfig extends ParameterConfig {
|
||||||
|| testElementClassPluginIdMap.get(msTestElement.getClass()) == null) {
|
|| testElementClassPluginIdMap.get(msTestElement.getClass()) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, Object> pluginConfigMap = envConfig.getConfig().getPluginConfigMap();
|
Map<String, Map<String, Object>> pluginConfigMap = envConfig.getConfig().getPluginConfigMap();
|
||||||
String pluginId = testElementClassPluginIdMap.get(msTestElement.getClass());
|
String pluginId = testElementClassPluginIdMap.get(msTestElement.getClass());
|
||||||
return pluginConfigMap.get(pluginId);
|
return pluginConfigMap.get(pluginId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class ApiScenarioParamConfig extends ApiParamConfig {
|
||||||
private Boolean grouped;
|
private Boolean grouped;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getProtocolEnvConfig(AbstractMsTestElement msTestElement) {
|
public Map<String, Object> getProtocolEnvConfig(AbstractMsTestElement msTestElement) {
|
||||||
if (BooleanUtils.isTrue(grouped)) {
|
if (BooleanUtils.isTrue(grouped)) {
|
||||||
return getProtocolEnvConfig(msTestElement, projectEnvMap.get(msTestElement.getProjectId()));
|
return getProtocolEnvConfig(msTestElement, projectEnvMap.get(msTestElement.getProjectId()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -680,7 +680,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
envRequest.setProjectId(DEFAULT_PROJECT_ID);
|
envRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
envRequest.setName("test scenario debug");
|
envRequest.setName("test scenario debug");
|
||||||
// 添加插件的环境配置,供后续测试使用
|
// 添加插件的环境配置,供后续测试使用
|
||||||
Map<String, Object> pluginConfigMap = new HashMap<>();
|
Map<String, Map<String, Object>> pluginConfigMap = new HashMap<>();
|
||||||
pluginConfigMap.put("tcpp-sampler", new HashMap<>());
|
pluginConfigMap.put("tcpp-sampler", new HashMap<>());
|
||||||
EnvironmentConfig environmentConfig = new EnvironmentConfig();
|
EnvironmentConfig environmentConfig = new EnvironmentConfig();
|
||||||
environmentConfig.setPluginConfigMap(pluginConfigMap);
|
environmentConfig.setPluginConfigMap(pluginConfigMap);
|
||||||
|
|
Binary file not shown.
|
@ -38,7 +38,7 @@ public class EnvironmentConfig implements Serializable {
|
||||||
@Schema(description = "全局断言")
|
@Schema(description = "全局断言")
|
||||||
private MsEnvAssertionConfig assertionConfig;
|
private MsEnvAssertionConfig assertionConfig;
|
||||||
@Schema(description = "插件自定义的配置项,key为插件ID,value 为对应配置")
|
@Schema(description = "插件自定义的配置项,key为插件ID,value 为对应配置")
|
||||||
private Map<String, Object> pluginConfigMap;
|
private Map<String, Map<String, Object>> pluginConfigMap;
|
||||||
|
|
||||||
|
|
||||||
public EnvironmentConfig() {
|
public EnvironmentConfig() {
|
||||||
|
|
Loading…
Reference in New Issue