From 0527393ab418b9d7eece123631971088a34a0283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=BA=E5=9B=BD?= Date: Mon, 17 Apr 2023 16:08:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DV1=E7=89=88=E6=9C=AC=E6=97=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=AD=E5=89=8D=E5=90=8E=E7=BD=AESQL=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8F=96=E4=B8=8D=E5=88=B0=E7=8E=AF=E5=A2=83=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复V1版本旧数据中前后置SQL组件取不到环境的问题 --- .../request/processors/post/MsJDBCPostProcessor.java | 4 ++++ .../request/processors/pre/MsJDBCPreProcessor.java | 4 ++++ .../definition/request/sampler/MsHTTPSamplerProxy.java | 9 +++++++-- .../dto/definition/request/sampler/MsJDBCSampler.java | 5 +++++ .../api/dto/definition/request/sampler/MsTCPSampler.java | 9 +++++++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java index 8f2d4a03d0..5284a93660 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java @@ -53,6 +53,10 @@ public class MsJDBCPostProcessor extends MsTestElement { if (!config.isOperating() && !this.isEnable()) { return; } + //检查projectId 旧数据 + if (StringUtils.isBlank(this.getProjectId()) && this.getParent() != null) { + this.setProjectId(this.getParent().getProjectId()); + } if (config.getConfig() == null) { // 单独接口执行 this.setProjectId(config.getProjectId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java index 17deb34bd7..e74929605a 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java @@ -53,6 +53,10 @@ public class MsJDBCPreProcessor extends MsTestElement { if (!config.isOperating() && !this.isEnable()) { return; } + //检查projectId 旧数据 + if (StringUtils.isBlank(this.getProjectId()) && this.getParent() != null) { + this.setProjectId(this.getParent().getProjectId()); + } if (config.getConfig() == null) { // 单独接口执行 this.setProjectId(config.getProjectId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index a95df5f188..96b86964ec 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -6,7 +6,9 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager; +import io.metersphere.api.dto.definition.request.processors.post.MsJDBCPostProcessor; import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor; +import io.metersphere.api.dto.definition.request.processors.pre.MsJDBCPreProcessor; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.mock.MockApiHeaders; import io.metersphere.api.dto.scenario.Body; @@ -237,6 +239,9 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (CollectionUtils.isNotEmpty(hashTree)) { hashTree = ElementUtil.order(hashTree); for (MsTestElement el : hashTree) { + if (el instanceof MsJDBCPreProcessor || el instanceof MsJDBCPostProcessor) { + el.setParent(this); + } if (el.getEnvironmentId() == null) { if (this.getEnvironmentId() == null) { el.setEnvironmentId(useEnvironment); @@ -425,13 +430,13 @@ public class MsHTTPSamplerProxy extends MsTestElement { envPath += this.getPath(); } sampler.setPort(httpConfig.getPort()); - if (httpConfig.getDomain().startsWith("${")){ + if (httpConfig.getDomain().startsWith("${")) { sampler.setProtocol(httpConfig.getProtocol()); envPath = StringUtils.isNotBlank(this.path) ? StringUtils.join(httpConfig.getSocket(), this.path) : url; } else if (StringUtils.isNotEmpty(httpConfig.getDomain())) { sampler.setDomain(URLDecoder.decode(httpConfig.getDomain(), StandardCharsets.UTF_8.name())); sampler.setProtocol(httpConfig.getProtocol()); - } else { + } else { sampler.setDomain(""); sampler.setProtocol(""); sampler.setPort(-1); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index be462a0a5a..3936d34b84 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -2,6 +2,8 @@ package io.metersphere.api.dto.definition.request.sampler; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.definition.request.processors.post.MsJDBCPostProcessor; +import io.metersphere.api.dto.definition.request.processors.pre.MsJDBCPreProcessor; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; @@ -150,6 +152,9 @@ public class MsJDBCSampler extends MsTestElement { if (CollectionUtils.isNotEmpty(hashTree)) { hashTree = ElementUtil.order(hashTree); hashTree.forEach(el -> { + if (el instanceof MsJDBCPreProcessor || el instanceof MsJDBCPostProcessor) { + el.setParent(this); + } el.toHashTree(samplerHashTree, el.getHashTree(), config); }); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 43105930d6..d16b6d67d0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -3,6 +3,8 @@ package io.metersphere.api.dto.definition.request.sampler; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.definition.request.processors.post.MsJDBCPostProcessor; +import io.metersphere.api.dto.definition.request.processors.pre.MsJDBCPreProcessor; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; @@ -143,9 +145,9 @@ public class MsTCPSampler extends MsTestElement { // 失败重试 if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) { final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree); - loopTree.set(tcpSampler, samplerHashTree); + loopTree.set(tcpSampler, samplerHashTree); } else { - tree.set(tcpSampler, samplerHashTree); + tree.set(tcpSampler, samplerHashTree); } setUserParameters(samplerHashTree); @@ -164,6 +166,9 @@ public class MsTCPSampler extends MsTestElement { if (CollectionUtils.isNotEmpty(hashTree)) { hashTree = ElementUtil.order(hashTree); hashTree.forEach(el -> { + if (el instanceof MsJDBCPreProcessor || el instanceof MsJDBCPostProcessor) { + el.setParent(this); + } el.toHashTree(samplerHashTree, el.getHashTree(), config); }); }