fix(测试计划): 修复运行环境展示的问题

--bug=1023753 --user=宋天阳 【测试跟踪】jenkins执行测试计划-未显示运行环境
https://www.tapd.cn/55049933/s/1347702
This commit is contained in:
song-tianyang 2023-03-09 18:20:27 +08:00 committed by 建国
parent dc41c79c99
commit e24dc5a118
8 changed files with 110 additions and 107 deletions

View File

@ -17,6 +17,8 @@ public class TestPlanReportRunInfoDTO {
private String runMode; private String runMode;
private Map<String, List<String>> requestEnvMap; private Map<String, List<String>> requestEnvMap;
private String resourcePool;
// <测试计划场景关联表ID, <项目ID环境ID>> // <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> scenarioRunInfo; private Map<String, Map<String, List<String>>> scenarioRunInfo;
// <测试计划场景关联表ID, <项目ID环境ID>> // <测试计划场景关联表ID, <项目ID环境ID>>

View File

@ -86,6 +86,8 @@ public class TestPlanReportService {
@Resource @Resource
ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper;
@Resource @Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource @Resource
private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
@ -333,6 +335,7 @@ public class TestPlanReportService {
if (testPlanReport == null) { if (testPlanReport == null) {
runInfoDTO.setResourcePool(runModeConfigDTO.getResourcePoolId());
returnDTO = this.genTestPlanReport(saveRequest, runInfoDTO); returnDTO = this.genTestPlanReport(saveRequest, runInfoDTO);
} }
returnDTO.setPlanScenarioIdMap(saveRequest.getScenarioIdMap()); returnDTO.setPlanScenarioIdMap(saveRequest.getScenarioIdMap());
@ -662,6 +665,8 @@ public class TestPlanReportService {
if (testPlanReport != null && reportContent != null) { if (testPlanReport != null && reportContent != null) {
try { try {
TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildTestPlanReport(testPlan, testPlanReport, reportContent); TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildTestPlanReport(testPlan, testPlanReport, reportContent);
//查找运行环境
this.selectEnvironmentByTestPlanReport(reportBuildResultDTO.getTestPlanSimpleReportDTO(), testPlanReport);
returnDTO = reportBuildResultDTO.getTestPlanSimpleReportDTO(); returnDTO = reportBuildResultDTO.getTestPlanSimpleReportDTO();
} catch (Exception e) { } catch (Exception e) {
LogUtil.error("计算测试计划报告信息出错!", e); LogUtil.error("计算测试计划报告信息出错!", e);
@ -1051,8 +1056,6 @@ public class TestPlanReportService {
} }
testPlanReportDTO.setId(reportId); testPlanReportDTO.setId(reportId);
testPlanReportDTO.setName(testPlanReport.getName()); testPlanReportDTO.setName(testPlanReport.getName());
//查找运行环境
this.selectEnvironmentByTestPlanReport(testPlanReportDTO, testPlanReport);
return testPlanReportDTO; return testPlanReportDTO;
} }
@ -1116,6 +1119,13 @@ public class TestPlanReportService {
public void setEnvironmentToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) { public void setEnvironmentToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) {
if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) { if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) {
//查找资源池
if (StringUtils.isNotEmpty(runInfoDTO.getResourcePool())) {
TestResourcePool resourcePool = testResourcePoolMapper.selectByPrimaryKey(runInfoDTO.getResourcePool());
if (resourcePool != null) {
testPlanReportDTO.setResourcePool(resourcePool.getName());
}
}
// 环境组/运行环境 // 环境组/运行环境
if (StringUtils.isNotEmpty(runInfoDTO.getEnvGroupId())) { if (StringUtils.isNotEmpty(runInfoDTO.getEnvGroupId())) {
EnvironmentGroup environmentGroup = apiTestEnvironmentService.selectById(runInfoDTO.getEnvGroupId()); EnvironmentGroup environmentGroup = apiTestEnvironmentService.selectById(runInfoDTO.getEnvGroupId());
@ -1123,25 +1133,44 @@ public class TestPlanReportService {
testPlanReportDTO.setEnvGroupName(environmentGroup.getName()); testPlanReportDTO.setEnvGroupName(environmentGroup.getName());
} }
} else { } else {
if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) { Map<String, List<String>> requestEnvMap = new HashMap<>();
Map<String, List<String>> projectEnvMap = new HashMap<>(); if (MapUtils.isEmpty(runInfoDTO.getRequestEnvMap())) {
for (Map.Entry<String, List<String>> entry : runInfoDTO.getRequestEnvMap().entrySet()) { if (MapUtils.isNotEmpty(runInfoDTO.getApiCaseRunInfo())) {
String projectId = entry.getKey(); for (Map<String, String> map : runInfoDTO.getApiCaseRunInfo().values()) {
List<String> envIdList = entry.getValue(); requestEnvMap = TestPlanReportUtil.mergeApiCaseEnvMap(requestEnvMap, map);
Project project = baseProjectService.getProjectById(projectId);
String projectName = project == null ? null : project.getName();
if (StringUtils.isNotEmpty(projectName)) {
List<String> envNameList = new ArrayList<>();
for (String envId : envIdList) {
String envName = apiTestEnvironmentService.selectNameById(envId);
envNameList.add(envName);
}
projectEnvMap.put(projectName, envNameList);
} }
} }
if (MapUtils.isNotEmpty(projectEnvMap)) { if (MapUtils.isNotEmpty(runInfoDTO.getScenarioRunInfo())) {
testPlanReportDTO.setProjectEnvMap(projectEnvMap); for (Map<String, List<String>> map : runInfoDTO.getScenarioRunInfo().values()) {
requestEnvMap = TestPlanReportUtil.mergeProjectEnvMap(requestEnvMap, map);
}
} }
if (MapUtils.isNotEmpty(runInfoDTO.getUiScenarioRunInfo())) {
for (Map<String, List<String>> map : runInfoDTO.getUiScenarioRunInfo().values()) {
requestEnvMap = TestPlanReportUtil.mergeProjectEnvMap(requestEnvMap, map);
}
}
} else {
requestEnvMap = runInfoDTO.getRequestEnvMap();
}
Map<String, List<String>> projectEnvMap = new HashMap<>();
for (Map.Entry<String, List<String>> entry : requestEnvMap.entrySet()) {
String projectId = entry.getKey();
List<String> envIdList = entry.getValue();
Project project = baseProjectService.getProjectById(projectId);
String projectName = project == null ? null : project.getName();
if (StringUtils.isNotEmpty(projectName)) {
List<String> envNameList = new ArrayList<>();
for (String envId : envIdList) {
String envName = apiTestEnvironmentService.selectNameById(envId);
envNameList.add(envName);
}
projectEnvMap.put(projectName, envNameList);
}
}
if (MapUtils.isNotEmpty(projectEnvMap)) {
testPlanReportDTO.setProjectEnvMap(projectEnvMap);
} }
} }
//运行模式 //运行模式

View File

@ -14,12 +14,12 @@ import io.metersphere.plan.request.api.ApiScenarioRequest;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService; import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService;
import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService; import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanReportUtil;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -89,7 +89,7 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
try { try {
Map<String, List<String>> projectEnvMap = getPlanProjectEnvMap(idList); Map<String, List<String>> projectEnvMap = getPlanProjectEnvMap(idList);
report.setProjectEnvMap(mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap())); report.setProjectEnvMap(TestPlanReportUtil.mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap()));
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }
@ -97,28 +97,6 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
} }
} }
public Map<String, List<String>> mergeProjectEnvMap(Map<String, List<String>> projectEnvMap, Map<String, List<String>> originProjectEnvMap) {
if (MapUtils.isEmpty(projectEnvMap)) {
return originProjectEnvMap;
}
if (MapUtils.isEmpty(originProjectEnvMap)) {
return projectEnvMap;
}
Map<String, List<String>> r = new HashMap<>();
projectEnvMap.entrySet().forEach(e -> {
r.put(e.getKey(), e.getValue());
});
originProjectEnvMap.entrySet().forEach(e -> {
if (r.containsKey(e.getKey())) {
r.get(e.getKey()).addAll(e.getValue());
r.put(e.getKey(), r.get(e.getKey()).stream().distinct().collect(Collectors.toList()));
} else {
r.put(e.getKey(), e.getValue());
}
});
return r;
}
@NotNull @NotNull
private TestPlanUiResultReportDTO getUiResult(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) { private TestPlanUiResultReportDTO getUiResult(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanUiResultReportDTO uiResult = report.getUiResult(); TestPlanUiResultReportDTO uiResult = report.getUiResult();

View File

@ -1,82 +1,66 @@
package io.metersphere.plan.utils; package io.metersphere.plan.utils;
import io.metersphere.base.domain.TestPlanReportContentWithBLOBs;
import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.JSON;
import io.metersphere.dto.*; import io.metersphere.dto.TestPlanApiDTO;
import io.metersphere.dto.TestPlanScenarioDTO;
import io.metersphere.plan.constant.ApiReportStatus; import io.metersphere.plan.constant.ApiReportStatus;
import io.metersphere.plan.dto.ApiPlanReportDTO; import io.metersphere.plan.dto.ApiPlanReportDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.service.ServiceUtils; import io.metersphere.service.ServiceUtils;
import io.metersphere.xpack.track.dto.IssuesDao;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
public class TestPlanReportUtil { public class TestPlanReportUtil {
public static void initCaseExecuteInfoToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportContentWithBLOBs testPlanReportContent) {
testPlanReportDTO.setFunctionAllCases( public static Map<String, List<String>> mergeProjectEnvMap(Map<String, List<String>> projectEnvMap, Map<String, List<String>> originProjectEnvMap) {
getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class) if (projectEnvMap == null) {
); projectEnvMap = new HashMap<String, List<String>>();
testPlanReportDTO.setIssueList( }
getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class) if (originProjectEnvMap == null) {
); originProjectEnvMap = new HashMap<String, List<String>>();
testPlanReportDTO.setFunctionResult( }
getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class) Map<String, List<String>> r = new HashMap<>();
); projectEnvMap.entrySet().forEach(e -> {
testPlanReportDTO.setApiResult( r.put(e.getKey(), e.getValue());
getReportContentResultObject(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class) });
); originProjectEnvMap.entrySet().forEach(e -> {
testPlanReportDTO.setLoadResult( if (r.containsKey(e.getKey())) {
getReportContentResultObject(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class) r.get(e.getKey()).addAll(e.getValue());
); r.put(e.getKey(), r.get(e.getKey()).stream().distinct().collect(Collectors.toList()));
testPlanReportDTO.setFunctionAllCases( } else {
getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class) r.put(e.getKey(), e.getValue());
); }
testPlanReportDTO.setIssueList( });
getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class) return r;
); }
testPlanReportDTO.setApiAllCases(
getReportContentResultArray(testPlanReportContent.getApiAllCases(), TestPlanApiDTO.class) public static Map<String, List<String>> mergeApiCaseEnvMap(Map<String, List<String>> projectEnvMap, Map<String, String> originProjectEnvMap) {
); if (projectEnvMap == null) {
testPlanReportDTO.setApiFailureCases( projectEnvMap = new HashMap<String, List<String>>();
getReportContentResultArray(testPlanReportContent.getApiFailureCases(), TestPlanApiDTO.class) }
); if (MapUtils.isEmpty(originProjectEnvMap)) {
testPlanReportDTO.setScenarioAllCases( return projectEnvMap;
getReportContentResultArray(testPlanReportContent.getScenarioAllCases(), TestPlanScenarioDTO.class) }
); Map<String, List<String>> r = new HashMap<>();
testPlanReportDTO.setScenarioFailureCases( projectEnvMap.entrySet().forEach(e -> {
getReportContentResultArray(testPlanReportContent.getScenarioFailureCases(), TestPlanScenarioDTO.class) r.put(e.getKey(), e.getValue());
); });
testPlanReportDTO.setLoadAllCases( originProjectEnvMap.entrySet().forEach(e -> {
getReportContentResultArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class) if (r.containsKey(e.getKey())) {
); r.get(e.getKey()).add(e.getValue());
testPlanReportDTO.setLoadFailureCases( } else {
getReportContentResultArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class) r.put(e.getKey(), new ArrayList<>() {{
); this.add(e.getValue());
testPlanReportDTO.setErrorReportCases( }});
getReportContentResultArray(testPlanReportContent.getErrorReportCases(), TestPlanApiDTO.class) }
); });
testPlanReportDTO.setErrorReportScenarios( return r;
getReportContentResultArray(testPlanReportContent.getErrorReportScenarios(), TestPlanScenarioDTO.class)
);
testPlanReportDTO.setUnExecuteCases(
getReportContentResultArray(testPlanReportContent.getUnExecuteCases(), TestPlanApiDTO.class)
);
testPlanReportDTO.setUnExecuteScenarios(
getReportContentResultArray(testPlanReportContent.getUnExecuteScenarios(), TestPlanScenarioDTO.class)
);
testPlanReportDTO.setUiResult(
getReportContentResultObject(testPlanReportContent.getUiResult(), TestPlanUiResultReportDTO.class)
);
testPlanReportDTO.setUiAllCases(
getReportContentResultArray(testPlanReportContent.getUiAllCases(), TestPlanUiScenarioDTO.class)
);
testPlanReportDTO.setUiFailureCases(
getReportContentResultArray(testPlanReportContent.getUiFailureCases(), TestPlanUiScenarioDTO.class)
);
} }
public static boolean checkReportConfig(Map config, String key, String subKey) { public static boolean checkReportConfig(Map config, String key, String subKey) {

View File

@ -229,3 +229,5 @@ test_case_review_status_underway=Underway
test_case_review_status_re_review=ReReview test_case_review_status_re_review=ReReview
api_status_fake_error=Fake error api_status_fake_error=Fake error
test_case_sync_status_comment=Relevance case %s in test plan [%s] has be executed by result %s。 test_case_sync_status_comment=Relevance case %s in test plan [%s] has be executed by result %s。
serial=Serial
parallel=Parallel

View File

@ -200,3 +200,5 @@ test_case_review_status_underway=评审中
test_case_review_status_re_review=重新提审 test_case_review_status_re_review=重新提审
api_status_fake_error=误报 api_status_fake_error=误报
test_case_sync_status_comment=关联的case %s 在测试计划【%s】内的执行结果出现%s。 test_case_sync_status_comment=关联的case %s 在测试计划【%s】内的执行结果出现%s。
serial=串行
parallel=并行

View File

@ -200,3 +200,5 @@ test_case_review_status_underway=評審中
test_case_review_status_re_review=重新提審 test_case_review_status_re_review=重新提審
api_status_fake_error=誤報 api_status_fake_error=誤報
test_case_sync_status_comment=關聯的case %s 在測試計劃【%s】內的執行結果出現%s。 test_case_sync_status_comment=關聯的case %s 在測試計劃【%s】內的執行結果出現%s。
serial=串行
parallel=並行

View File

@ -242,6 +242,8 @@ export default {
getTestPlanReportContent(this.reportId).then((r) => { getTestPlanReportContent(this.reportId).then((r) => {
this.loading = false; this.loading = false;
this.report = r.data; this.report = r.data;
this.runMode = this.report.runMode;
this.resourcePool = this.report.resourcePool;
this.report.config = this.getDefaultConfig(this.report); this.report.config = this.getDefaultConfig(this.report);
}); });
} }
@ -260,6 +262,8 @@ export default {
getTestPlanReport(this.planId).then((r) => { getTestPlanReport(this.planId).then((r) => {
this.loading = false; this.loading = false;
this.report = r.data; this.report = r.data;
this.runMode = this.report.runMode;
this.resourcePool = this.report.resourcePool;
this.report.config = this.getDefaultConfig(this.report); this.report.config = this.getDefaultConfig(this.report);
}); });
} }