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 Map<String, List<String>> requestEnvMap;
private String resourcePool;
// <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> scenarioRunInfo;
// <测试计划场景关联表ID, <项目ID环境ID>>

View File

@ -86,6 +86,8 @@ public class TestPlanReportService {
@Resource
ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper;
@Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource
private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
@ -333,6 +335,7 @@ public class TestPlanReportService {
if (testPlanReport == null) {
runInfoDTO.setResourcePool(runModeConfigDTO.getResourcePoolId());
returnDTO = this.genTestPlanReport(saveRequest, runInfoDTO);
}
returnDTO.setPlanScenarioIdMap(saveRequest.getScenarioIdMap());
@ -662,6 +665,8 @@ public class TestPlanReportService {
if (testPlanReport != null && reportContent != null) {
try {
TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildTestPlanReport(testPlan, testPlanReport, reportContent);
//查找运行环境
this.selectEnvironmentByTestPlanReport(reportBuildResultDTO.getTestPlanSimpleReportDTO(), testPlanReport);
returnDTO = reportBuildResultDTO.getTestPlanSimpleReportDTO();
} catch (Exception e) {
LogUtil.error("计算测试计划报告信息出错!", e);
@ -1051,8 +1056,6 @@ public class TestPlanReportService {
}
testPlanReportDTO.setId(reportId);
testPlanReportDTO.setName(testPlanReport.getName());
//查找运行环境
this.selectEnvironmentByTestPlanReport(testPlanReportDTO, testPlanReport);
return testPlanReportDTO;
}
@ -1116,6 +1119,13 @@ public class TestPlanReportService {
public void setEnvironmentToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportRunInfoDTO 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())) {
EnvironmentGroup environmentGroup = apiTestEnvironmentService.selectById(runInfoDTO.getEnvGroupId());
@ -1123,25 +1133,44 @@ public class TestPlanReportService {
testPlanReportDTO.setEnvGroupName(environmentGroup.getName());
}
} else {
if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) {
Map<String, List<String>> projectEnvMap = new HashMap<>();
for (Map.Entry<String, List<String>> entry : runInfoDTO.getRequestEnvMap().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);
Map<String, List<String>> requestEnvMap = new HashMap<>();
if (MapUtils.isEmpty(runInfoDTO.getRequestEnvMap())) {
if (MapUtils.isNotEmpty(runInfoDTO.getApiCaseRunInfo())) {
for (Map<String, String> map : runInfoDTO.getApiCaseRunInfo().values()) {
requestEnvMap = TestPlanReportUtil.mergeApiCaseEnvMap(requestEnvMap, map);
}
}
if (MapUtils.isNotEmpty(projectEnvMap)) {
testPlanReportDTO.setProjectEnvMap(projectEnvMap);
if (MapUtils.isNotEmpty(runInfoDTO.getScenarioRunInfo())) {
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.remote.api.PlanTestPlanScenarioCaseService;
import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanReportUtil;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy;
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());
try {
Map<String, List<String>> projectEnvMap = getPlanProjectEnvMap(idList);
report.setProjectEnvMap(mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap()));
report.setProjectEnvMap(TestPlanReportUtil.mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap()));
} catch (Exception 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
private TestPlanUiResultReportDTO getUiResult(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanUiResultReportDTO uiResult = report.getUiResult();

View File

@ -1,82 +1,66 @@
package io.metersphere.plan.utils;
import io.metersphere.base.domain.TestPlanReportContentWithBLOBs;
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.dto.ApiPlanReportDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.service.ServiceUtils;
import io.metersphere.xpack.track.dto.IssuesDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class TestPlanReportUtil {
public static void initCaseExecuteInfoToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportContentWithBLOBs testPlanReportContent) {
testPlanReportDTO.setFunctionAllCases(
getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class)
);
testPlanReportDTO.setIssueList(
getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class)
);
testPlanReportDTO.setFunctionResult(
getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class)
);
testPlanReportDTO.setApiResult(
getReportContentResultObject(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class)
);
testPlanReportDTO.setLoadResult(
getReportContentResultObject(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class)
);
testPlanReportDTO.setFunctionAllCases(
getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class)
);
testPlanReportDTO.setIssueList(
getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class)
);
testPlanReportDTO.setApiAllCases(
getReportContentResultArray(testPlanReportContent.getApiAllCases(), TestPlanApiDTO.class)
);
testPlanReportDTO.setApiFailureCases(
getReportContentResultArray(testPlanReportContent.getApiFailureCases(), TestPlanApiDTO.class)
);
testPlanReportDTO.setScenarioAllCases(
getReportContentResultArray(testPlanReportContent.getScenarioAllCases(), TestPlanScenarioDTO.class)
);
testPlanReportDTO.setScenarioFailureCases(
getReportContentResultArray(testPlanReportContent.getScenarioFailureCases(), TestPlanScenarioDTO.class)
);
testPlanReportDTO.setLoadAllCases(
getReportContentResultArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class)
);
testPlanReportDTO.setLoadFailureCases(
getReportContentResultArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class)
);
testPlanReportDTO.setErrorReportCases(
getReportContentResultArray(testPlanReportContent.getErrorReportCases(), TestPlanApiDTO.class)
);
testPlanReportDTO.setErrorReportScenarios(
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 Map<String, List<String>> mergeProjectEnvMap(Map<String, List<String>> projectEnvMap, Map<String, List<String>> originProjectEnvMap) {
if (projectEnvMap == null) {
projectEnvMap = new HashMap<String, List<String>>();
}
if (originProjectEnvMap == null) {
originProjectEnvMap = new HashMap<String, List<String>>();
}
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;
}
public static Map<String, List<String>> mergeApiCaseEnvMap(Map<String, List<String>> projectEnvMap, Map<String, String> originProjectEnvMap) {
if (projectEnvMap == null) {
projectEnvMap = new HashMap<String, List<String>>();
}
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()).add(e.getValue());
} else {
r.put(e.getKey(), new ArrayList<>() {{
this.add(e.getValue());
}});
}
});
return r;
}
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
api_status_fake_error=Fake error
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=重新提审
api_status_fake_error=误报
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=重新提審
api_status_fake_error=誤報
test_case_sync_status_comment=關聯的case %s 在測試計劃【%s】內的執行結果出現%s。
serial=串行
parallel=並行

View File

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