From 8d8073acfd09854c5d073ad4204bd735c4ec3abe Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 7 Jul 2021 14:58:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3=E6=97=A0=E6=B3=95=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=80=BC=E7=AD=89=E5=8F=B7=E7=BB=93=E5=B0=BE=E8=A2=AB?= =?UTF-8?q?=E8=88=8D=E5=BC=83=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复部分接口无法设置环境变量的问题,修复环境变量值等号结尾被舍弃的问题 --- .../api/dto/definition/request/MsTestElement.java | 2 +- .../definition/request/processors/MsJSR223Processor.java | 8 ++++---- .../request/processors/post/MsJSR223PostProcessor.java | 8 ++++---- .../request/processors/pre/MsJSR223PreProcessor.java | 8 ++++---- .../definition/request/sampler/MsHTTPSamplerProxy.java | 6 +++++- .../java/io/metersphere/api/dto/scenario/HttpConfig.java | 1 + .../api/service/ApiEnvironmentRunningParamService.java | 5 +++-- .../components/api/automation/scenario/DebugRun.vue | 1 + .../api/automation/scenario/EditApiScenario.vue | 1 + .../automation/scenario/common/Jsr233ProcessorContent.vue | 2 +- 10 files changed, 25 insertions(+), 17 deletions(-) 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 4ab7bb8274..f1904e04e2 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 @@ -108,7 +108,7 @@ public abstract class MsTestElement { @JSONField(ordinal = 13) private boolean isMockEnvironment; @JSONField(ordinal = 14) - private String useEnviroment; + private String useEnvironment; private MsTestElement parent; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; 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 ee2a15aa6d..87714884bf 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,17 +36,17 @@ public class MsJSR223Processor extends MsTestElement { @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { //替换Metersphere环境变量 - if(StringUtils.isEmpty(this.getUseEnviroment())){ + if(StringUtils.isEmpty(this.getUseEnvironment())){ if(config.getConfig() != null){ if(config.getProjectId() != null){ String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); }else { Collection evnConfigList = config.getConfig().values(); if(evnConfigList!=null && !evnConfigList.isEmpty()){ for (EnvironmentConfig configItem : evnConfigList) { String evnId = configItem.getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); break; } } @@ -54,7 +54,7 @@ public class MsJSR223Processor extends MsTestElement { } } - script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnviroment()+".\""); + script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnvironment()+".\""); // 非导出操作,且不是启用状态则跳过执行 if (!config.isOperating() && !this.isEnable()) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java index ed667e79be..1a224a47e3 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java @@ -32,17 +32,17 @@ public class MsJSR223PostProcessor extends MsTestElement { @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { - if(StringUtils.isEmpty(this.getUseEnviroment())){ + if(StringUtils.isEmpty(this.getUseEnvironment())){ if(config.getConfig() != null){ if(config.getProjectId() != null){ String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); }else { Collection evnConfigList = config.getConfig().values(); if(evnConfigList!=null && !evnConfigList.isEmpty()){ for (EnvironmentConfig configItem : evnConfigList) { String evnId = configItem.getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); break; } } @@ -50,7 +50,7 @@ public class MsJSR223PostProcessor extends MsTestElement { } } //替换Metersphere环境变量 - script = StringUtils.replace(script,RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnviroment()+".\""); + script = StringUtils.replace(script,RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnvironment()+".\""); // 非导出操作,且不是启用状态则跳过执行 if (!config.isOperating() && !this.isEnable()) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java index edf1ab8a28..4ebedefc9d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java @@ -32,17 +32,17 @@ public class MsJSR223PreProcessor extends MsTestElement { @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { - if(StringUtils.isEmpty(this.getUseEnviroment())){ + if(StringUtils.isEmpty(this.getUseEnvironment())){ if(config.getConfig() != null){ if(config.getProjectId() != null){ String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); }else { Collection evnConfigList = config.getConfig().values(); if(evnConfigList!=null && !evnConfigList.isEmpty()){ for (EnvironmentConfig configItem : evnConfigList) { String evnId = configItem.getApiEnvironmentid(); - this.setUseEnviroment(evnId); + this.setUseEnvironment(evnId); break; } } @@ -50,7 +50,7 @@ public class MsJSR223PreProcessor extends MsTestElement { } } //替换Metersphere环境变量 - script = StringUtils.replace(script,RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnviroment()+".\""); + script = StringUtils.replace(script,RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnvironment()+".\""); // 非导出操作,且不是启用状态则跳过执行 if (!config.isOperating() && !this.isEnable()) { 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 0e71865b0d..83916b9241 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 @@ -252,7 +252,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { - el.setUseEnviroment(useEnvironment); + el.setUseEnvironment(useEnvironment); el.toHashTree(httpSamplerTree, el.getHashTree(), config); } } @@ -265,6 +265,10 @@ public class MsHTTPSamplerProxy extends MsTestElement { private HttpConfig getHttpConfig(ParameterConfig config) { if (config.isEffective(this.getProjectId())) { + String useEvnId = config.getConfig().get(this.getProjectId()).getApiEnvironmentid(); + if(StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId,this.getUseEnvironment())){ + this.setUseEnvironment(useEvnId); + } return getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig()); } return null; diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java index 8a4e5a1dd1..78f283c958 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java @@ -10,6 +10,7 @@ import java.util.stream.Collectors; @Data public class HttpConfig { + private String apiEnvironmentid; private String socket; private String domain; private String protocol = "https"; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java b/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java index 65e587f05a..40eb79a062 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java @@ -102,8 +102,9 @@ public class ApiEnvironmentRunningParamService { String envId = envAndKeyArr[0]; String [] keyArr = ArrayUtils.remove(envAndKeyArr,0); String key = StringUtils.join(keyArr,"."); - String [] valueArr = ArrayUtils.remove(envItem,0); - String value = StringUtils.join(valueArr,"="); +// String [] valueArr = ArrayUtils.remove(envItem,0); +// String value = StringUtils.join(valueArr,"="); + String value = StringUtils.substring(env,jmeterVarKey.length()+1); if(StringUtils.isNoneEmpty(envId,key,value)){ this.addParam(envId,key,value); } diff --git a/frontend/src/business/components/api/automation/scenario/DebugRun.vue b/frontend/src/business/components/api/automation/scenario/DebugRun.vue index 630a4a7a3c..8cd652f4db 100644 --- a/frontend/src/business/components/api/automation/scenario/DebugRun.vue +++ b/frontend/src/business/components/api/automation/scenario/DebugRun.vue @@ -49,6 +49,7 @@ import {saveScenario} from "@/business/components/api/automation/api-automation" this.$emit('runRefresh', {}); this.$emit("changeDebugButton"); }); + alert("123"); }, } } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 5c9a3c747b..f59948c210 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -902,6 +902,7 @@ export default { promise.then(() => { let sign = this.$refs.envPopover.checkEnv(this.isFullUrl); if (!sign) { + this.buttonIsLoading = false; return; } //调试时不再保存 diff --git a/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue b/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue index 073e5f985b..5e2190e26e 100644 --- a/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue +++ b/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue @@ -43,7 +43,7 @@ }, { title: this.$t('api_test.request.processor.param_environment_set_global_variable'), - value: 'vars.put(${__metersphere_env_id}+"key","value");\n'+'vars.put("key","value");', + value: 'vars.put(${__metersphere_env_id}+"key","value");\n'+'vars.put("key","value")', }, { title: this.$t('api_test.request.processor.code_add_report_length'),