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;