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: [