From f17a37e6e9664956ee5b3e38044115a8327737aa Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 16 Nov 2021 15:27:26 +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=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=B1=82=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E7=8E=AF=E5=A2=83=E9=97=AE=E9=A2=98=20--bug=3D1007851?= =?UTF-8?q?=20--user=3D=E8=B5=B5=E5=8B=87=20=E3=80=90=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E3=80=91=E5=BC=95=E7=94=A8=E7=9A=84=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=EF=BC=8C=E5=90=AF=E7=94=A8=E5=9C=BA=E6=99=AF=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=20=E5=8A=9F=E8=83=BD=E6=B2=A1=E6=9C=89=E7=94=9F?= =?UTF-8?q?=E6=95=88=20https://www.tapd.cn/55049933/s/1068272?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/MsScenario.java | 50 ++++++++----------- .../scenario/component/ApiComponent.vue | 2 +- 2 files changed, 22 insertions(+), 30 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 48fae7b315..fcec04b733 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 @@ -103,7 +103,7 @@ public class MsScenario extends MsTestElement { ElementUtil.dataFormatting(element.getJSONArray("hashTree")); this.setName(scenario.getName()); this.setProjectId(scenario.getProjectId()); - hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { + LinkedList sourceHashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); // 场景变量 if (StringUtils.isNotEmpty(element.getString("variables"))) { @@ -119,7 +119,10 @@ public class MsScenario extends MsTestElement { }); this.setHeaders(headers); } - + if (element.get("environmentMap") != null) { + this.setEnvironmentMap((Map) element.get("environmentMap")); + } + this.setHashTree(sourceHashTree); } } catch (Exception ex) { @@ -139,18 +142,7 @@ public class MsScenario extends MsTestElement { } } if (this.environmentMap != null && !this.environmentMap.isEmpty()) { - this.environmentMap.keySet().forEach(projectId -> { - ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.environmentMap.get(projectId)); - if (environment != null && environment.getConfig() != null) { - EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); - envConfig.put(projectId, env); - if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { - this.setMockEnvironment(true); - } - } - }); + this.setEnv(this.environmentMap, envConfig); config.setConfig(envConfig); } } else { @@ -173,28 +165,15 @@ public class MsScenario extends MsTestElement { ElementUtil.addCounter(tree, variables); ElementUtil.addRandom(tree, variables); if (CollectionUtils.isNotEmpty(this.headers)) { - //setHeader(tree, this.headers); config.setHeaders(this.headers); } ParameterConfig newConfig = new ParameterConfig(); if (this.isEnvironmentEnable() && this.environmentMap != null && !this.environmentMap.isEmpty()) { - environmentMap.keySet().forEach(projectId -> { - ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.environmentMap.get(projectId)); - if (environment != null && environment.getConfig() != null) { - EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); - envConfig.put(projectId, env); - if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { - this.setMockEnvironment(true); - } - } - }); + this.setEnv(this.environmentMap, envConfig); newConfig.setConfig(envConfig); } if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { - // 给所有孩子加一个父亲标志 el.setParent(this); el.setMockEnvironment(this.isMockEnvironment()); if (this.isEnvironmentEnable()) { @@ -263,5 +242,18 @@ public class MsScenario extends MsTestElement { return null; } - + private void setEnv(Map environmentMap, Map envConfig) { + for (String projectId : environmentMap.keySet()) { + ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); + ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentMap.get(projectId)); + if (environment != null && StringUtils.isNotEmpty(environment.getConfig())) { + EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + env.setApiEnvironmentid(environment.getId()); + envConfig.put(projectId, env); + if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { + this.setMockEnvironment(true); + } + } + } + } } 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 91fc113050..bd3031ef44 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -425,7 +425,7 @@ export default { if (targetHashTree) { targetHashTree.forEach(item => { item.disabled = true; - }) + }); this.request.hashTree = targetHashTree; } return;