From b2caf9d79990f504efa88dfd328a1e452d6dc254 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 7 Jun 2022 15:26:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E6=AD=A5=E9=AA=A4=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=8C=96=E7=A7=BB=E5=8A=A8=E9=A1=BA=E5=BA=8F=E5=90=8E?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1013836 --user=赵勇 [接口测试]-新建场景-关联接口case-全屏-选环境-拖拽第一个用例到其他位置-调试没结果 https://www.tapd.cn/55049933/s/1175024 --- .../api/service/ApiAutomationService.java | 70 ++++++++++--------- .../automation/scenario/EditApiScenario.vue | 1 + .../scenario/maximize/MaximizeScenario.vue | 3 +- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index d5557b6f46..314d7dc5dd 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -728,42 +728,46 @@ public class ApiAutomationService { Boolean enable = request.getEnvironmentEnable(); String scenarioDefinition = request.getDefinition(); JSONObject element = JSON.parseObject(scenarioDefinition, Feature.DisableSpecialKeyDetect); - Map environmentMap = new HashMap<>(); - if (BooleanUtils.isFalse(enable)) { - String envType = request.getEnvironmentType(); - String envGroupId = request.getEnvironmentGroupId(); - if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) { - environmentMap = environmentGroupProjectService.getEnvMap(envGroupId); - } else if (StringUtils.equals(envType, EnvironmentType.JSON.name())) { - environmentMap = request.getEnvironmentMap(); - } - } else { - String scenarioId = request.getId(); - ApiScenarioDTO scenario = getNewApiScenario(scenarioId); - if (scenario != null) { - String referenced = element.getString("referenced"); - if (StringUtils.equalsIgnoreCase("REF", referenced)) { - JSONObject source = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect); - element = jsonMerge(source, element); + try { + Map environmentMap = new HashMap<>(); + if (BooleanUtils.isFalse(enable)) { + String envType = request.getEnvironmentType(); + String envGroupId = request.getEnvironmentGroupId(); + if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) { + environmentMap = environmentGroupProjectService.getEnvMap(envGroupId); + } else if (StringUtils.equals(envType, EnvironmentType.JSON.name())) { + environmentMap = request.getEnvironmentMap(); } - element.put("referenced", referenced); - String environmentType = scenario.getEnvironmentType(); - String environmentGroupId = scenario.getEnvironmentGroupId(); - String environmentJson = scenario.getEnvironmentJson(); - if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { - environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); - } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { - environmentMap = JSON.parseObject(environmentJson, Map.class); + } else { + String scenarioId = request.getId(); + ApiScenarioDTO scenario = getNewApiScenario(scenarioId); + if (scenario != null) { + String referenced = element.getString("referenced"); + if (StringUtils.equalsIgnoreCase("REF", referenced)) { + JSONObject source = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect); + element = jsonMerge(source, element); + } + element.put("referenced", referenced); + String environmentType = scenario.getEnvironmentType(); + String environmentGroupId = scenario.getEnvironmentGroupId(); + String environmentJson = scenario.getEnvironmentJson(); + if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { + environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); + } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { + environmentMap = JSON.parseObject(environmentJson, Map.class); + } } } - } - ParameterConfig config = new ParameterConfig(); - apiScenarioEnvService.setEnvConfig(environmentMap, config); - if (config.getConfig() != null && !config.getConfig().isEmpty()) { - ElementUtil.dataSetDomain(element.getJSONArray("hashTree"), config); + ParameterConfig config = new ParameterConfig(); + apiScenarioEnvService.setEnvConfig(environmentMap, config); + if (config.getConfig() != null && !config.getConfig().isEmpty()) { + ElementUtil.dataSetDomain(element.getJSONArray("hashTree"), config); + } + return JSON.toJSONString(element); + } catch (Exception e) { + return scenarioDefinition; } - return JSON.toJSONString(element); } @@ -813,7 +817,7 @@ public class ApiAutomationService { config.setOperating(true); config.getExcludeScenarioIds().add(apiScenario.getId()); try { - MsScenario scenario = JSONObject.parseObject(apiScenario.getScenarioDefinition(), MsScenario.class,Feature.DisableSpecialKeyDetect); + MsScenario scenario = JSONObject.parseObject(apiScenario.getScenarioDefinition(), MsScenario.class, Feature.DisableSpecialKeyDetect); if (scenario == null) { return null; } @@ -823,7 +827,7 @@ public class ApiAutomationService { String environmentJson = apiScenario.getEnvironmentJson(); String environmentGroupId = apiScenario.getEnvironmentGroupId(); if (StringUtils.equals(environmentType, EnvironmentType.JSON.name()) && StringUtils.isNotBlank(environmentJson)) { - scenario.setEnvironmentMap(JSON.parseObject(environmentJson, Map.class,Feature.DisableSpecialKeyDetect)); + scenario.setEnvironmentMap(JSON.parseObject(environmentJson, Map.class, Feature.DisableSpecialKeyDetect)); } else if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name()) && StringUtils.isNotBlank(environmentGroupId)) { Map envMap = environmentGroupProjectService.getEnvMap(environmentGroupId); scenario.setEnvironmentMap(envMap); diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index fde5107a11..eac1d8da06 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -336,6 +336,7 @@ @setCookieShare="setCookieShare" @setSampleError="setSampleError" @stop="stop" + @sort="sort" @openScenario="openScenario" @runScenario="runDebug" @stopScenario="stop" diff --git a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue index 5621392726..e569ec1360 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue @@ -737,9 +737,10 @@ export default { }, allowDrag(draggingNode, dropNode, dropType) { if (dropNode && draggingNode && dropType) { - this.sort(); + this.$emit("sort"); this.forceRerender(); this.cancelBatchProcessing(); + } }, nodeExpand(data) {