fix(测试跟踪): 修复执行测试计划时环境变量展示的问题

--bug=1023758 --user=宋天阳 【测试跟踪】测试计划-操作执行-选择新环境-接口场景运行环境显示错误
https://www.tapd.cn/55049933/s/1353604
This commit is contained in:
song-tianyang 2023-03-21 17:07:58 +08:00 committed by 建国
parent e67e60c5e9
commit 5aaaa0cfc1
4 changed files with 49 additions and 30 deletions

View File

@ -281,6 +281,11 @@ public class ApiScenarioExecuteService {
for (String testPlanScenarioId : request.getProcessVO().getTestPlanScenarioMap().keySet()) {
TestPlanApiScenarioInfoDTO planApiScenario = request.getProcessVO().getTestPlanScenarioMap().get(testPlanScenarioId);
ApiScenarioWithBLOBs scenario = scenarioMap.get(planApiScenario.getApiScenarioId());
Set<String> scenarioUsedProjectIdSet = null;
try {
scenarioUsedProjectIdSet = apiScenarioEnvService.getApiScenarioEnv(scenario.getScenarioDefinition()).getProjectIds();
} catch (Exception ignore) {
}
if (scenario.getStepTotal() == null || scenario.getStepTotal() == 0) {
continue;
}
@ -318,14 +323,17 @@ public class ApiScenarioExecuteService {
if (MapUtils.isEmpty(runModeConfig.getEnvMap())) {
apiCaseExecuteService.setRunModeConfigEnvironment(runModeConfig, planEnvMap);
}
//对报告的envMap做过滤过滤多余的key
Map<String, String> diffEnvMap = new HashMap<>();
planEnvMap.forEach((k, v) -> {
if (StringUtils.equals(planApiScenario.getProjectId(), k)) {
diffEnvMap.put(k, v);
}
});
runModeConfig.setEnvMap(diffEnvMap);
//对报告的envMap做过滤通过场景用到的项目来进行匹配过滤掉使用不到的项目环境
if (CollectionUtils.isNotEmpty(scenarioUsedProjectIdSet)) {
List<String> scenarioUsedProjectIdList = new ArrayList<>(scenarioUsedProjectIdSet);
Map<String, String> diffEnvMap = new HashMap<>();
planEnvMap.forEach((k, v) -> {
if (scenarioUsedProjectIdList.contains(k)) {
diffEnvMap.put(k, v);
}
});
runModeConfig.setEnvMap(diffEnvMap);
}
report.setEnvConfig(JSON.toJSONString(runModeConfig));
}
// 生成文档结构

View File

@ -208,22 +208,12 @@ public class TestPlanReportService {
List<TestPlanApiScenarioInfoDTO> scenarios) {
TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO();
if (MapUtils.isNotEmpty(config.getEnvMap())) {
//判断记录选择的环境还是默认环境
Map<String, List<String>> requestEnvMap = new HashMap<>();
for (Map.Entry<String, String> entry : config.getEnvMap().entrySet()) {
requestEnvMap.put(entry.getKey(), new ArrayList<>() {{
this.add(entry.getValue());
}});
}
runInfoDTO.setRequestEnvMap(requestEnvMap);
} else {
runInfoDTO.setRequestEnvMap(config.getTestPlanDefaultEnvMap());
}
final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>();
runInfoDTO.setRunMode(config.getMode());
Map<String, List<String>> projectInvMap = TestPlanReportUtil.getTestPlanExecutedEnvironments(config.getTestPlanDefaultEnvMap(), config.getEnvMap());
runInfoDTO.setRequestEnvMap(projectInvMap);
final Map<String, String> runEnvMap = new HashMap<>();
if (StringUtils.equals(GROUP, config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) {
Map<String, String> groupMap = baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId());
if (MapUtils.isNotEmpty(groupMap)) {
@ -1173,7 +1163,7 @@ public class TestPlanReportService {
if (MapUtils.isEmpty(runInfoDTO.getRequestEnvMap())) {
if (MapUtils.isNotEmpty(runInfoDTO.getApiCaseRunInfo())) {
for (Map<String, String> map : runInfoDTO.getApiCaseRunInfo().values()) {
requestEnvMap = TestPlanReportUtil.mergeApiCaseEnvMap(requestEnvMap, map);
requestEnvMap = TestPlanReportUtil.mergeEnvironmentMap(requestEnvMap, map);
}
}
if (MapUtils.isNotEmpty(runInfoDTO.getScenarioRunInfo())) {

View File

@ -40,7 +40,24 @@ public class TestPlanReportUtil {
return r;
}
public static Map<String, List<String>> mergeApiCaseEnvMap(Map<String, List<String>> projectEnvMap, Map<String, String> originProjectEnvMap) {
//获取测试计划执行时的环境
public static Map<String, List<String>> getTestPlanExecutedEnvironments(Map<String, List<String>> defaultEnvMap, Map<String, String> selectedEnvMap) {
Map<String, List<String>> returnMap = new HashMap<String, List<String>>();
if (MapUtils.isNotEmpty(defaultEnvMap)) {
returnMap.putAll(defaultEnvMap);
}
if (MapUtils.isNotEmpty(selectedEnvMap)) {
for (Map.Entry<String, String> entry : selectedEnvMap.entrySet()) {
String projectId = entry.getKey();
returnMap.put(projectId, new ArrayList<>() {{
this.add(entry.getValue());
}});
}
}
return returnMap;
}
public static Map<String, List<String>> mergeEnvironmentMap(Map<String, List<String>> projectEnvMap, Map<String, String> originProjectEnvMap) {
if (projectEnvMap == null) {
projectEnvMap = new HashMap<String, List<String>>();
}

View File

@ -300,16 +300,20 @@ export default {
let projectEnvMapElement = this.projectEnvMap[d];
if (projectEnvMapElement.length > 0) {
projectEnvMapElement.forEach((envId) => {
let filter = envs.filter((e) => e.id === envId);
let filteredEnv = envs.filter((e) => e.id === envId);
if (!this.selectedEnvName.has(d)) {
let name = [];
name.push(filter[0].name);
this.selectedEnvName.set(d, name);
if (filteredEnv.length > 0) {
name.push(filteredEnv[0].name);
this.selectedEnvName.set(d, name);
this.$emit("setDefaultEnv", d, filteredEnv[0].id);
}
} else {
this.selectedEnvName.get(d).push(filter[0].name);
if (filteredEnv.length > 0) {
this.selectedEnvName.get(d).push(filteredEnv[0].name);
this.$emit("setDefaultEnv", d, filteredEnv[0].id);
}
}
this.$emit("setDefaultEnv", d, filter[0].id);
});
}
}