From 88ef3440012d5c4fc93ade2a84998845c82d6da8 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 25 Apr 2022 16:12:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0dubbo=E8=AF=B7=E6=B1=82=E7=9A=84=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E7=BD=AE=E8=84=9A=E6=9C=AC=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1012658 --user=宋天阳 【接口测试】dubbo协议-运行环境添加的全局后置脚本设置打印log不生效 https://www.tapd.cn/55049933/s/1146802 --- .../request/sampler/MsDubboSampler.java | 23 +++++++++++++++++++ .../GlobalScriptFilterRequest.java | 2 +- .../environment/EnvironmentGlobalScript.vue | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) 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 58237eba3f..e4f93d91cd 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 @@ -12,12 +12,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample; import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument; import io.github.ningyu.jmeter.plugin.util.Constants; +import io.metersphere.api.dto.definition.parse.JMeterScriptUtil; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConfigCenter; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndService; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter; import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; +import io.metersphere.api.dto.scenario.environment.GlobalScriptFilterRequest; import io.metersphere.api.service.ApiDefinitionService; import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; @@ -100,12 +103,32 @@ public class MsDubboSampler extends MsTestElement { } final HashTree testPlanTree = tree.add(dubboSample(config)); + + //添加全局前后置脚本 + EnvironmentConfig envConfig = null; + if (config.getConfig() != null) { + envConfig = config.getConfig().get(this.getProjectId()); + } + //处理全局前后置脚本(步骤内) + String environmentId = this.getEnvironmentId(); + if (environmentId == null) { + if(StringUtils.isEmpty(this.useEnvironment) && envConfig != null){ + environmentId = envConfig.getApiEnvironmentid(); + }else { + environmentId = this.useEnvironment; + } + } + //根据配置将脚本放置在私有脚本之前 + JMeterScriptUtil.setScriptByEnvironmentConfig(envConfig, testPlanTree, GlobalScriptFilterRequest.DUBBO.name(), environmentId, config, false); if (CollectionUtils.isNotEmpty(hashTree)) { hashTree = ElementUtil.order(hashTree); hashTree.forEach(el -> { el.toHashTree(testPlanTree, el.getHashTree(), config); }); } + + //根据配置将脚本放置在私有脚本之后 + JMeterScriptUtil.setScriptByEnvironmentConfig(envConfig, testPlanTree, GlobalScriptFilterRequest.DUBBO.name(), environmentId, config, true); } private boolean setRefElement() { diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/environment/GlobalScriptFilterRequest.java b/backend/src/main/java/io/metersphere/api/dto/scenario/environment/GlobalScriptFilterRequest.java index 17ca9d02f7..a61d577ae7 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/environment/GlobalScriptFilterRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/environment/GlobalScriptFilterRequest.java @@ -1,5 +1,5 @@ package io.metersphere.api.dto.scenario.environment; public enum GlobalScriptFilterRequest { - HTTP,TCP,JDBC + HTTP,TCP,JDBC,DUBBO } diff --git a/frontend/src/business/components/api/test/components/environment/EnvironmentGlobalScript.vue b/frontend/src/business/components/api/test/components/environment/EnvironmentGlobalScript.vue index 63f750011c..0484d67415 100644 --- a/frontend/src/business/components/api/test/components/environment/EnvironmentGlobalScript.vue +++ b/frontend/src/business/components/api/test/components/environment/EnvironmentGlobalScript.vue @@ -97,6 +97,7 @@ export default { {value: "HTTP", label: "HTTP"}, {value: "TCP", label: "TCP"}, {value: "JDBC", label: "JDBC"}, + {value: "DUBBO", label: "DUBBO"}, ], scriptExecSort: [], scriptPreExecSort: [