From 5001cb29ca1176a9337caa1ef3dad537dd518dfc Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 17 Mar 2023 17:01:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA=E4=B8=AD=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=20=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=B1=95=E7=A4=BALocal=E8=B5=84=E6=BA=90=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1024554 --user=宋天阳 【测试跟踪】报告-查看-计划无接口测试用例-资源池显示为LOCAL https://www.tapd.cn/55049933/s/1352351 --- .../plan/service/TestPlanReportService.java | 52 ++++++++----------- .../plan/utils/TestPlanReportUtil.java | 14 ++++- 2 files changed, 35 insertions(+), 31 deletions(-) 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 bf40289df3..75a2c11955 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 @@ -675,7 +675,7 @@ public class TestPlanReportService { try { returnDTO = testPlanService.buildTestPlanReportStruct(testPlan, testPlanReport, reportContent); //查找运行环境 - this.initRunInfomation(returnDTO, testPlanReport); + this.initRunInformation(returnDTO, testPlanReport); } catch (Exception e) { LogUtil.error("计算测试计划报告信息出错!", e); } @@ -1117,25 +1117,12 @@ public class TestPlanReportService { TestResourcePoolExample example = new TestResourcePoolExample(); example.createCriteria().andIdIn(report.getResourcePools()); List resourcePoolList = testResourcePoolMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(resourcePoolList)) { - ArrayList resourcePoolName = new ArrayList<>(); - resourcePoolList.forEach(item -> { - if (!resourcePoolName.contains(item.getName())) { - resourcePoolName.add(item.getName()); - } - }); - String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); - report.setResourcePool(resourcePoolNames); - } else { - report.setResourcePool("LOCAL"); - } - } else { - report.setResourcePool("LOCAL"); + report.setResourcePool(getResourcePoolName(resourcePoolList, report.getResourcePools().contains("LOCAL"))); } return report; } - public void initRunInfomation(TestPlanReportDataStruct testPlanReportDTO, TestPlanReport testPlanReport) { + public void initRunInformation(TestPlanReportDataStruct testPlanReportDTO, TestPlanReport testPlanReport) { if (StringUtils.isNotEmpty(testPlanReport.getRunInfo())) { try { TestPlanReportRunInfoDTO runInfoDTO = JSON.parseObject(testPlanReport.getRunInfo(), TestPlanReportRunInfoDTO.class); @@ -1146,6 +1133,23 @@ public class TestPlanReportService { } } + private String getResourcePoolName(List resourcePoolList, boolean hasLocal) { + ArrayList resourcePoolName = new ArrayList<>(); + if (hasLocal) { + resourcePoolName.add("LOCAL"); + } + if (CollectionUtils.isNotEmpty(resourcePoolList)) { + resourcePoolList.forEach(item -> { + if (!resourcePoolName.contains(item.getName())) { + resourcePoolName.add(item.getName()); + } + }); + } + + String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); + return resourcePoolNames; + } + public void setEnvironmentToDTO(TestPlanReportDataStruct testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) { if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) { //查找资源池 @@ -1153,19 +1157,9 @@ public class TestPlanReportService { TestResourcePoolExample example = new TestResourcePoolExample(); example.createCriteria().andIdIn(runInfoDTO.getResourcePools()); List resourcePoolList = testResourcePoolMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(resourcePoolList)) { - ArrayList resourcePoolName = new ArrayList<>(); - resourcePoolList.forEach(item -> { - if (!resourcePoolName.contains(item.getName())) { - resourcePoolName.add(item.getName()); - } - }); - String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); - testPlanReportDTO.setResourcePool(resourcePoolNames); - } else { - testPlanReportDTO.setResourcePool("LOCAL"); - } - } else { + testPlanReportDTO.setResourcePool(getResourcePoolName(resourcePoolList, runInfoDTO.getResourcePools().contains("LOCAL"))); + } else if (CollectionUtils.isNotEmpty(testPlanReportDTO.getApiAllCases()) || CollectionUtils.isNotEmpty(testPlanReportDTO.getScenarioAllCases())) { + //存在接口或者场景的用例,资源池默认是local testPlanReportDTO.setResourcePool("LOCAL"); } // 环境组/运行环境 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java b/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java index d0a001838e..3501c80fdd 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java @@ -136,13 +136,23 @@ public class TestPlanReportUtil { return null; } - public static List mergeResourcePools(List resourcePools, List originResourcePools) { + public static List mergeResourcePools(List resourcePools, List reFormatOriginResourcePools) { if (resourcePools == null) { resourcePools = new ArrayList<>(); } - if (originResourcePools == null) { + if (reFormatOriginResourcePools == null) { return resourcePools; } + //检查originResourcePools是否含有null。 null代表local + List originResourcePools = new ArrayList<>(); + for (String resourcePool : reFormatOriginResourcePools) { + if (StringUtils.isEmpty(resourcePool)) { + resourcePool = "LOCAL"; + } + if (!originResourcePools.contains(resourcePool)) { + originResourcePools.add(resourcePool); + } + } List returnList = new ArrayList<>(); returnList.addAll(resourcePools); returnList.addAll(originResourcePools);