From 959f67c1c8fbf010f3807b55e0e32a2ed7a28fb8 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 22 Feb 2023 17:56:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=BB=98=E8=AE=A4=E7=8E=AF=E5=A2=83=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=89=A7=E8=A1=8C=E7=8E=AF=E5=A2=83=E5=8F=AA?= =?UTF-8?q?=E4=BC=9A=E6=94=B6=E5=88=B0=E6=AF=8F=E4=B8=AA=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E7=8E=AF=E5=A2=83=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 修复测试计划使用默认环境执行时,执行环境只会收到每个项目最后一个环境的问题 --- .../io/metersphere/dto/RunModeConfigDTO.java | 3 + .../plan/dto/TestPlanReportRunInfoDTO.java | 2 +- .../plan/request/api/TestPlanRunRequest.java | 1 + .../plan/service/TestPlanReportService.java | 29 +- .../plan/service/TestPlanService.java | 4 +- .../plan/common/TestPlanRunModeWithEnv.vue | 14 + .../business/plan/components/TestPlanList.vue | 866 +++++++++++------- .../business/plan/env/EnvSelectPopover.vue | 4 +- 8 files changed, 567 insertions(+), 356 deletions(-) diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java index 6cf1dce635..e0cc574739 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java @@ -26,6 +26,9 @@ public class RunModeConfigDTO { * 运行环境 */ private Map envMap; + + //测试计划整体执行时的默认环境 + private Map> testPlanDefaultEnvMap; private String environmentType; private String environmentGroupId; //ui 测试 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java index 1958806901..8a758608aa 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java @@ -15,7 +15,7 @@ public class TestPlanReportRunInfoDTO { private String envGroupId; private String runMode; - private Map requestEnvMap; + private Map> requestEnvMap; // <测试计划场景关联表ID, <项目ID,环境ID>> private Map>> scenarioRunInfo; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java b/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java index 4c273de168..8d3f58a35c 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java @@ -20,6 +20,7 @@ public class TestPlanRunRequest { private boolean runWithinResourcePool;//是否选择资源池 private String resourcePoolId;//资源池Id private Map envMap; + private Map> testPlanDefaultEnvMap; private String environmentType; private String environmentGroupId; private List testPlanIds; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index b06e417008..d883398af6 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -271,7 +271,18 @@ public class TestPlanReportService { List scenarios) { TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); - runInfoDTO.setRequestEnvMap(config.getEnvMap()); + if (MapUtils.isNotEmpty(config.getEnvMap())) { + //判断记录选择的环境还是默认环境 + Map> requestEnvMap = new HashMap<>(); + for (Map.Entry entry : config.getEnvMap().entrySet()) { + requestEnvMap.put(entry.getKey(), new ArrayList<>() {{ + this.add(entry.getValue()); + }}); + } + runInfoDTO.setRequestEnvMap(requestEnvMap); + } else { + runInfoDTO.setRequestEnvMap(config.getTestPlanDefaultEnvMap()); + } final Map runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>(); runInfoDTO.setRunMode(config.getMode()); @@ -1281,16 +1292,18 @@ public class TestPlanReportService { } else { if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) { Map> projectEnvMap = new HashMap<>(); - for (Map.Entry entry : runInfoDTO.getRequestEnvMap().entrySet()) { + for (Map.Entry> entry : runInfoDTO.getRequestEnvMap().entrySet()) { String projectId = entry.getKey(); - String envId = entry.getValue(); + List envIdList = entry.getValue(); Project project = baseProjectService.getProjectById(projectId); String projectName = project == null ? null : project.getName(); - String envNames = apiTestEnvironmentService.selectNameById(envId); - if (StringUtils.isNotEmpty(projectName) && StringUtils.isNotEmpty(envNames)) { - projectEnvMap.put(projectName, new ArrayList<>() {{ - this.add(envNames); - }}); + if (StringUtils.isNotEmpty(projectName)) { + List envNameList = new ArrayList<>(); + for (String envId : envIdList) { + String envName = apiTestEnvironmentService.selectNameById(envId); + envNameList.add(envName); + } + projectEnvMap.put(projectName, envNameList); } } if (MapUtils.isNotEmpty(projectEnvMap)) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 5a181c32db..bd3f0e07d5 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -840,7 +840,7 @@ public class TestPlanService { //环境参数为空时,依据测试计划保存的环境执行 if (((StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && StringUtils.isBlank(runModeConfig.getEnvironmentGroupId())) - || (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()))) + || (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()) && MapUtils.isEmpty(runModeConfig.getTestPlanDefaultEnvMap()))) && !StringUtils.equals(executionWay, ExecutionWay.RUN.name())) { TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId); if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { @@ -853,6 +853,7 @@ public class TestPlanService { Map envMap = testPlanRunRequest.getEnvMap(); String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId(); runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanId); + runModeConfig.setTestPlanDefaultEnvMap(testPlanRunRequest.getTestPlanDefaultEnvMap()); if (!testPlanRunRequest.isRunWithinResourcePool()) { runModeConfig.setResourcePoolId(null); } @@ -1637,6 +1638,7 @@ public class TestPlanService { String environmentGroupId = testplanRunRequest.getEnvironmentGroupId(); String testPlanId = testplanRunRequest.getTestPlanId(); RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId); + runModeConfig.setTestPlanDefaultEnvMap(testplanRunRequest.getTestPlanDefaultEnvMap()); String apiRunConfig = JSON.toJSONString(runModeConfig); return this.run(testPlanId, testplanRunRequest.getProjectId(), diff --git a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue index 6835647d7a..53b71de162 100644 --- a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue +++ b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue @@ -18,6 +18,7 @@ :has-option-group="true" :group-id="runConfig.environmentGroupId" @setProjectEnvMap="setProjectEnvMap" + @setDefaultEnv="setDefaultEnv" @setEnvGroup="setEnvGroup" ref="envSelectPopover" class="mode-row" @@ -249,6 +250,7 @@ export default { testType: null, resourcePools: [], projectEnvListMap: {}, + defaultEnvMap: {}, runConfig: { mode: "serial", reportType: "iddReport", @@ -261,6 +263,7 @@ export default { retryEnable: false, retryNum: 1, browser: "CHROME", + testPlanDefaultEnvMap: {}, }, projectList: [], projectIds: new Set(), @@ -309,9 +312,11 @@ export default { }, methods: { open(testType, runModeConfig) { + this.defaultEnvMap = {}; if (runModeConfig) { this.runConfig = JSON.parse(runModeConfig); this.runConfig.envMap = new Map(); + this.runConfig.testPlanDefaultEnvMap = {}; this.runConfig.onSampleError = this.runConfig.onSampleError === "true" || this.runConfig.onSampleError === true; @@ -368,6 +373,7 @@ export default { this.$emit("close"); }, handleRunBatch() { + this.runConfig.testPlanDefaultEnvMap = this.defaultEnvMap; this.$emit("handleRunBatch", this.runConfig); this.close(); }, @@ -376,6 +382,14 @@ export default { this.resourcePools = response.data; }); }, + setDefaultEnv(projectId, envId) { + let ids = this.defaultEnvMap[projectId]; + if (!ids) { + ids = []; + } + ids.push(envId); + this.defaultEnvMap[projectId] = ids; + }, setProjectEnvMap(projectEnvMap) { this.runConfig.envMap = projectEnvMap; }, diff --git a/test-track/frontend/src/business/plan/components/TestPlanList.vue b/test-track/frontend/src/business/plan/components/TestPlanList.vue index b0b489472c..b7ebb88535 100644 --- a/test-track/frontend/src/business/plan/components/TestPlanList.vue +++ b/test-track/frontend/src/business/plan/components/TestPlanList.vue @@ -1,10 +1,13 @@