From 025fa9cde07b9224daf6377c780a238d45b52d34 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 26 Feb 2021 13:14:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E5=9C=BA=E6=99=AF=E6=AD=A5=E9=AA=A4=E4=B8=AD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=97=A0=E6=B3=95=E6=89=A7=E8=A1=8C=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 --- .../api/dto/definition/request/MsScenario.java | 2 +- .../request/sampler/MsHTTPSamplerProxy.java | 2 +- .../api/service/ApiDefinitionService.java | 16 ++++++++++++++++ .../automation/scenario/EditApiScenario.vue | 2 +- .../scenario/component/ApiComponent.vue | 18 +++++++++++++----- .../scenario/component/ComponentConfig.vue | 5 +++-- .../api/definition/components/Run.vue | 16 +++++++++++++--- .../definition/components/case/ApiCaseList.vue | 4 +++- .../components/runtest/RunTestHTTPPage.vue | 3 ++- frontend/src/common/js/utils.js | 8 ++++++++ 10 files changed, 61 insertions(+), 15 deletions(-) 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..104c568e6c 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 != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && 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/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 726df485fe..1ce15e9f3d 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 @@ -114,7 +114,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setFollowRedirects(this.isFollowRedirects()); sampler.setUseKeepAlive(true); sampler.setDoMultipart(this.isDoMultipartPost()); - if (config != null && config.getConfig() != null) { + if (config != null && config.getConfig() != null && !config.getConfig().isEmpty()) { config.setConfig(config.getConfig()); } else { // 单独接口执行 diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index cf39bcd701..8f9a45da4b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -13,6 +13,7 @@ import io.metersphere.api.dto.definition.parse.ApiDefinitionImportParserFactory; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ScheduleInfoSwaggerUrlRequest; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; +import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.request.RequestType; import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult; import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest; @@ -85,6 +86,8 @@ public class ApiDefinitionService { private ScheduleMapper scheduleMapper; @Resource private ApiTestCaseMapper apiTestCaseMapper; + @Resource + private ApiTestEnvironmentService environmentService; private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24); @@ -427,8 +430,21 @@ public class ApiDefinitionService { public String run(RunDefinitionRequest request, List bodyFiles) { List bodyUploadIds = new ArrayList<>(request.getBodyUploadIds()); FileUtils.createBodyFiles(bodyUploadIds, bodyFiles); + ParameterConfig config = new ParameterConfig(); config.setProjectId(request.getProjectId()); + + Map envConfig = new HashMap<>(); + Map map = request.getEnvironmentMap(); + if (map != null) { + map.keySet().forEach(id -> { + ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(id)); + EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + envConfig.put(id, env); + }); + config.setConfig(envConfig); + } + HashTree hashTree = request.getTestElement().generateHashTree(config); String runMode = ApiRunMode.DEFINITION.name(); if (StringUtils.isNotBlank(request.getType()) && StringUtils.equals(request.getType(), ApiRunMode.API_PLAN.name())) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 25caf7618a..78ae9e667b 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -149,7 +149,7 @@ diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 2d8644c056..1bfc9ebdc0 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -16,7 +16,7 @@ {{ $t('commons.copy') }} {{ $t('api_test.scenario.reference') }} {{getProjectName(request.projectId)}} - @@ -84,7 +84,8 @@ default: false, }, currentEnvironmentId: String, - projectList: Array + projectList: Array, + envMap: Map }, components: { CustomizeReqInfo, @@ -249,13 +250,20 @@ this.reload(); }, run() { - if (!this.currentEnvironmentId) { - this.$error(this.$t('api_test.environment.select_environment')); - return; + if (!this.envMap || this.envMap.size === 0) { + this.$warning("请在环境配置中为该步骤所属项目选择运行环境!"); + return false; + } else if (this.envMap && this.envMap.size > 0) { + const env = this.envMap.get(this.request.projectId); + if (!env) { + this.$warning("请在环境配置中为该步骤所属项目选择运行环境!"); + return false; + } } this.request.active = true; this.loading = true; this.runData = []; + this.runData.projectId = this.request.projectId; this.request.useEnvironment = this.currentEnvironmentId; this.request.customizeReq = this.isCustomizeReq; let debugData = { diff --git a/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue b/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue index 12ed422f4e..4b5d93a5f2 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue @@ -2,7 +2,7 @@
+ @remove="remove" @copyRow="copyRow" @refReload="refReload" :project-list="projectList" :env-map="envMap"/>
@@ -28,7 +28,8 @@ currentEnvironmentId: String, response: {}, node: {}, - projectList: Array + projectList: Array, + envMap: Map }, data() { return { diff --git a/frontend/src/business/components/api/definition/components/Run.vue b/frontend/src/business/components/api/definition/components/Run.vue index e53b698131..d8d6d9ae85 100644 --- a/frontend/src/business/components/api/definition/components/Run.vue +++ b/frontend/src/business/components/api/definition/components/Run.vue @@ -2,7 +2,7 @@