diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index b0ae06627b..4f321bdca7 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -189,7 +189,7 @@ public class MsScenario extends MsTestElement { } }); } - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null + if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index bac961dde6..261b52098b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -47,8 +47,10 @@ import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; import java.io.ByteArrayOutputStream; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type") @@ -166,7 +168,7 @@ public abstract class MsTestElement { } public Arguments addArguments(ParameterConfig config) { - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null + if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { Arguments arguments = new Arguments(); arguments.setEnabled(true); @@ -181,11 +183,14 @@ public abstract class MsTestElement { return null; } - protected EnvironmentConfig getEnvironmentConfig(String environmentId) { + protected Map getEnvironmentConfig(String environmentId) { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId); if (environment != null && environment.getConfig() != null) { - return JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + // 单独接口执行 + Map map = new HashMap<>(); + map.put(this.getProjectId(), JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class)); + return map; } return null; } @@ -269,7 +274,7 @@ public abstract class MsTestElement { getFullPath(element.getParent(), path); } - protected String getParentName(MsTestElement parent, ParameterConfig config) { + protected String getParentName(MsTestElement parent) { if (parent != null) { if (MsTestElementConstants.LoopController.name().equals(parent.getType())) { MsLoopController loopController = (MsLoopController) parent; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java index 6de3bd6d23..e5117db258 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java @@ -30,4 +30,11 @@ public class ParameterConfig { * 项目ID,支持单接口执行 */ private String projectId; -} + + public boolean isEffective(String projectId) { + if (this.config != null && this.config.get(projectId) != null) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java index 440c8572bd..718df9b625 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java @@ -36,7 +36,7 @@ public class MsJSR223Processor extends MsTestElement { } else { processor.setName("JSR223Processor"); } - String name = this.getParentName(this.getParent(), config); + String name = this.getParentName(this.getParent()); if (StringUtils.isNotEmpty(name) && !config.isOperating()) { processor.setName(this.getName() + "<->" + name); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 177698749e..75800b50ad 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -76,7 +76,7 @@ public class MsDubboSampler extends MsTestElement { DubboSample sampler = new DubboSample(); sampler.setEnabled(this.isEnable()); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent(), config); + String name = this.getParentName(this.getParent()); if (StringUtils.isNotEmpty(name) && !config.isOperating()) { sampler.setName(this.getName() + "<->" + name); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 726df485fe..68dae3948e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -8,7 +8,6 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager; import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.scenario.KeyValue; -import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ScriptEngineUtils; @@ -101,7 +100,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { HTTPSamplerProxy sampler = new HTTPSamplerProxy(); sampler.setEnabled(this.isEnable()); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent(), config); + String name = this.getParentName(this.getParent()); if (StringUtils.isNotEmpty(name) && !config.isOperating()) { sampler.setName(this.getName() + "<->" + name); } @@ -114,14 +113,10 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setFollowRedirects(this.isFollowRedirects()); sampler.setUseKeepAlive(true); sampler.setDoMultipart(this.isDoMultipartPost()); - if (config != null && config.getConfig() != null) { - config.setConfig(config.getConfig()); - } else { + if (config.getConfig() == null) { // 单独接口执行 this.setProjectId(config.getProjectId()); - Map map = new HashMap<>(); - map.put(this.getProjectId(), getEnvironmentConfig(useEnvironment)); - config.setConfig(map); + config.setConfig(getEnvironmentConfig(useEnvironment)); } // 添加环境中的公共变量 @@ -130,7 +125,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { tree.add(arguments); } try { - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null) { + if (config.isEffective(this.getProjectId())) { String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket(); // 补充如果是完整URL 则用自身URL boolean isUrl = false; @@ -219,13 +214,13 @@ public class MsHTTPSamplerProxy extends MsTestElement { } // 通用请求Headers - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getHttpConfig() != null + if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getHttpConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders())) { setHeader(httpSamplerTree, config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders()); } //判断是否要开启DNS - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null + if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) { MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId())); MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId())); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index b3fa3b2f9d..baf4ea93a4 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -113,7 +113,7 @@ public class MsJDBCSampler extends MsTestElement { JDBCSampler sampler = new JDBCSampler(); sampler.setEnabled(this.isEnable()); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent(), config); + String name = this.getParentName(this.getParent()); if (StringUtils.isNotEmpty(name) && !config.isOperating()) { sampler.setName(this.getName() + "<->" + name); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 20583aca7b..bc9d4be3bd 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -23,9 +23,7 @@ import org.apache.jmeter.testelement.property.StringProperty; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import java.util.*; @Data @EqualsAndHashCode(callSuper = true) @@ -59,7 +57,7 @@ public class MsTCPSampler extends MsTestElement { private String password = ""; @JSONField(ordinal = 33) private String request; -// @JSONField(ordinal = 34) + // @JSONField(ordinal = 34) // private Object requestResult; @JSONField(ordinal = 35) private List parameters; @@ -77,7 +75,11 @@ public class MsTCPSampler extends MsTestElement { if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { this.getRefElement(this); } -// config.setConfig(getEnvironmentConfig(useEnvironment)); + if (config.getConfig() == null) { + // 单独接口执行 + this.setProjectId(config.getProjectId()); + config.setConfig(getEnvironmentConfig(useEnvironment)); + } parseEnvironment(config.getConfig().get(this.projectId)); // 添加环境中的公共变量 @@ -111,7 +113,7 @@ public class MsTCPSampler extends MsTestElement { TCPSampler tcpSampler = new TCPSampler(); tcpSampler.setEnabled(this.isEnable()); tcpSampler.setName(this.getName()); - String name = this.getParentName(this.getParent(), config); + String name = this.getParentName(this.getParent()); if (StringUtils.isNotEmpty(name) && !config.isOperating()) { tcpSampler.setName(this.getName() + "<->" + name); } diff --git a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue index f81bf81c6d..2682f9dfef 100644 --- a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue +++ b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue @@ -146,6 +146,9 @@ if (!this.response.body) { this.response.body = ""; } + if(!this.response.responseResult.vars){ + this.response.responseResult.vars=""; + } this.reqMessages = this.$t('api_test.request.address') + ":\n" + this.response.url + "\n" + this.$t('api_test.scenario.headers') + ":\n" + this.response.headers + "\n" + "Cookies :\n" + this.response.cookies + "\n" + "Bpdy:" + "\n" + this.response.body;