fix(UI测试): 修复测试计划环境展示相关问题
--bug=1023048_--user=张大海_【测试跟踪】复制测试计划-操作-执行-运行环境未显示跨项目环境_https
This commit is contained in:
parent
fb9791e4d6
commit
9fdb2b0d9d
|
@ -6,4 +6,6 @@ import java.util.List;
|
||||||
|
|
||||||
public interface ExtTestPlanScenarioCaseMapper {
|
public interface ExtTestPlanScenarioCaseMapper {
|
||||||
List<TestPlanApiScenarioInfoDTO> selectLegalDataByTestPlanId(String planId);
|
List<TestPlanApiScenarioInfoDTO> selectLegalDataByTestPlanId(String planId);
|
||||||
|
|
||||||
|
List<TestPlanApiScenarioInfoDTO> selectLegalUiDataByTestPlanId(String planId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,18 @@
|
||||||
AND tpas.test_plan_id = #{0}
|
AND tpas.test_plan_id = #{0}
|
||||||
ORDER BY tpas.`order` DESC;
|
ORDER BY tpas.`order` DESC;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectLegalUiDataByTestPlanId" resultType="io.metersphere.plan.dto.TestPlanApiScenarioInfoDTO">
|
||||||
|
SELECT tpas.id,
|
||||||
|
tpas.ui_scenario_id,
|
||||||
|
tpas.environment,
|
||||||
|
tpas.environment_type,
|
||||||
|
tpas.environment_group_id,
|
||||||
|
apis.project_id
|
||||||
|
FROM test_plan_ui_scenario tpas
|
||||||
|
INNER JOIN ui_scenario apis ON tpas.ui_scenario_id = apis.id
|
||||||
|
WHERE (apis.`status` IS NULL OR apis.`status` != 'Trash')
|
||||||
|
AND tpas.test_plan_id = #{0}
|
||||||
|
ORDER BY tpas.`order` DESC;
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -17,11 +17,14 @@ public class TestPlanReportRunInfoDTO {
|
||||||
private String runMode;
|
private String runMode;
|
||||||
// <测试计划场景关联表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>>
|
||||||
|
private Map<String, Map<String, List<String>>> uiScenarioRunInfo;
|
||||||
// <测试计划用例关联表ID, <项目ID,环境ID>>
|
// <测试计划用例关联表ID, <项目ID,环境ID>>
|
||||||
private Map<String, Map<String, String>> apiCaseRunInfo;
|
private Map<String, Map<String, String>> apiCaseRunInfo;
|
||||||
|
|
||||||
public TestPlanReportRunInfoDTO() {
|
public TestPlanReportRunInfoDTO() {
|
||||||
scenarioRunInfo = new HashMap<>();
|
scenarioRunInfo = new HashMap<>();
|
||||||
|
uiScenarioRunInfo = new HashMap<>();
|
||||||
apiCaseRunInfo = new HashMap<>();
|
apiCaseRunInfo = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +47,26 @@ public class TestPlanReportRunInfoDTO {
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putUiScenarioRunInfo(String scenarioResourceId, String projectId, String environmentId) {
|
||||||
|
if (uiScenarioRunInfo.containsKey(scenarioResourceId)) {
|
||||||
|
if (uiScenarioRunInfo.get(scenarioResourceId).containsKey(projectId)) {
|
||||||
|
if (!uiScenarioRunInfo.get(scenarioResourceId).get(projectId).contains(environmentId)) {
|
||||||
|
uiScenarioRunInfo.get(scenarioResourceId).get(projectId).add(environmentId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uiScenarioRunInfo.get(scenarioResourceId).put(projectId, new ArrayList<>() {{
|
||||||
|
this.add(environmentId);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uiScenarioRunInfo.put(scenarioResourceId, new HashMap<>() {{
|
||||||
|
this.put(projectId, new ArrayList<>() {{
|
||||||
|
this.add(environmentId);
|
||||||
|
}});
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void putApiCaseRunInfo(String apiCaseResourceId, String projectId, String environmentId) {
|
public void putApiCaseRunInfo(String apiCaseResourceId, String projectId, String environmentId) {
|
||||||
apiCaseRunInfo.put(apiCaseResourceId, new HashMap<>() {{
|
apiCaseRunInfo.put(apiCaseResourceId, new HashMap<>() {{
|
||||||
|
|
|
@ -29,6 +29,7 @@ import io.metersphere.service.ServiceUtils;
|
||||||
import io.metersphere.utils.DiscoveryUtil;
|
import io.metersphere.utils.DiscoveryUtil;
|
||||||
import io.metersphere.utils.LoggerUtil;
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import io.metersphere.xpack.track.dto.IssuesDao;
|
import io.metersphere.xpack.track.dto.IssuesDao;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
@ -41,7 +42,6 @@ import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -362,12 +362,20 @@ public class TestPlanReportService {
|
||||||
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
|
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
|
||||||
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
|
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
|
||||||
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
|
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
|
||||||
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
|
if (CollectionUtils.isNotEmpty(testPlanUiScenarioList)) {
|
||||||
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
|
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
|
||||||
|
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
|
||||||
|
}
|
||||||
|
List<TestPlanApiScenarioInfoDTO> testPlanUiScenarioInfoList = extTestPlanScenarioCaseMapper.selectLegalUiDataByTestPlanId(planId);
|
||||||
|
TestPlanReportRunInfoDTO uiRunInfoDTO = this.parseTestPlanUiRunInfo(runModeConfigDTO, testPlanUiScenarioInfoList);
|
||||||
|
if (runInfoDTO != null) {
|
||||||
|
runInfoDTO.setUiScenarioRunInfo(uiRunInfoDTO.getUiScenarioRunInfo());
|
||||||
|
} else {
|
||||||
|
runInfoDTO = uiRunInfoDTO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
|
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
|
||||||
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
|
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
|
||||||
|
|
||||||
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
|
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,6 +399,46 @@ public class TestPlanReportService {
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TestPlanReportRunInfoDTO parseTestPlanUiRunInfo(RunModeConfigDTO config, List<TestPlanApiScenarioInfoDTO> scenarios) {
|
||||||
|
TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO();
|
||||||
|
final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>();
|
||||||
|
runInfoDTO.setRunMode(config.getMode());
|
||||||
|
|
||||||
|
if (StringUtils.equals(GROUP, config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) {
|
||||||
|
Map<String, String> groupMap = baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId());
|
||||||
|
if (MapUtils.isNotEmpty(groupMap)) {
|
||||||
|
runEnvMap.putAll(groupMap);
|
||||||
|
}
|
||||||
|
runInfoDTO.setEnvGroupId(config.getEnvironmentGroupId());
|
||||||
|
}
|
||||||
|
// 场景环境处理
|
||||||
|
scenarios.forEach(item -> {
|
||||||
|
Map<String, String> envMap = null;
|
||||||
|
if (StringUtils.equalsIgnoreCase(GROUP, item.getEnvironmentType())
|
||||||
|
&& StringUtils.isNotEmpty(item.getEnvironmentGroupId())) {
|
||||||
|
envMap = baseEnvGroupProjectService.getEnvMap(item.getEnvironmentGroupId());
|
||||||
|
} else {
|
||||||
|
if (MapUtils.isNotEmpty(runEnvMap) && runEnvMap.containsKey(item.getProjectId())) {
|
||||||
|
runInfoDTO.putUiScenarioRunInfo(item.getId(), item.getProjectId(), runEnvMap.get(item.getProjectId()));
|
||||||
|
} else if (StringUtils.isNotEmpty(item.getEnvironment())) {
|
||||||
|
try {
|
||||||
|
envMap = JSON.parseObject(item.getEnvironment(), Map.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error("解析场景环境失败!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (MapUtils.isNotEmpty(envMap)) {
|
||||||
|
for (Map.Entry<String, String> entry : envMap.entrySet()) {
|
||||||
|
String projectId = entry.getKey();
|
||||||
|
String envIdStr = entry.getValue();
|
||||||
|
runInfoDTO.putUiScenarioRunInfo(item.getId(), projectId, envIdStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return runInfoDTO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saveRequest.reportId 报告ID(外部传入)
|
* saveRequest.reportId 报告ID(外部传入)
|
||||||
|
@ -1193,9 +1241,12 @@ public class TestPlanReportService {
|
||||||
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
|
if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) {
|
||||||
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport);
|
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport);
|
||||||
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
|
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
|
||||||
} else if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
|
}
|
||||||
|
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
|
||||||
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanUiScenarioCaseService.generateEnvironmentInfo(testPlanReport);
|
TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanUiScenarioCaseService.generateEnvironmentInfo(testPlanReport);
|
||||||
|
Map<String, List<String>> projectMap = testPlanReportDTO.getProjectEnvMap();
|
||||||
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
|
BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo);
|
||||||
|
testPlanReportDTO.setProjectEnvMap(planTestPlanUiScenarioCaseService.mergeProjectEnvMap(testPlanEnvInfo.getProjectEnvMap(), projectMap));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
|
|
|
@ -1602,6 +1602,8 @@ public class TestPlanService {
|
||||||
environmentIds.add(eId);
|
environmentIds.add(eId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
scenarioEnv.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,14 @@ import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
|
||||||
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 org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
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;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -71,11 +72,8 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
|
||||||
//记录UI用例的运行环境信息
|
//记录UI用例的运行环境信息
|
||||||
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
|
List<String> idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList());
|
||||||
try {
|
try {
|
||||||
if (MapUtils.isEmpty(report.getProjectEnvMap())) {
|
Map<String, List<String>> projectEnvMap = getPlanProjectEnvMap(idList);
|
||||||
report.setProjectEnvMap(getPlanProjectEnvMap(idList));
|
report.setProjectEnvMap(mergeProjectEnvMap(projectEnvMap, report.getProjectEnvMap()));
|
||||||
} else {
|
|
||||||
report.getProjectEnvMap().putAll(getPlanProjectEnvMap(idList));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
|
@ -83,6 +81,28 @@ 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();
|
||||||
|
|
|
@ -160,6 +160,7 @@ export default {
|
||||||
reportId: "",
|
reportId: "",
|
||||||
infoDb: false,
|
infoDb: false,
|
||||||
selectRows: new Set(),
|
selectRows: new Set(),
|
||||||
|
map: new Map(),
|
||||||
projectEnvMap: new Map(),
|
projectEnvMap: new Map(),
|
||||||
projectList: [],
|
projectList: [],
|
||||||
customNum: false,
|
customNum: false,
|
||||||
|
@ -272,12 +273,12 @@ export default {
|
||||||
},
|
},
|
||||||
initProjectIds() {
|
initProjectIds() {
|
||||||
this.projectIds.clear();
|
this.projectIds.clear();
|
||||||
// this.map.clear();
|
this.map.clear();
|
||||||
this.selectRows.forEach((row) => {
|
this.selectRows.forEach((row) => {
|
||||||
getUiScenarioEnvByProjectId(row.id).then((res) => {
|
getUiScenarioEnvByProjectId(row.id).then((res) => {
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
data.projectIds.forEach((d) => this.projectIds.add(d));
|
data.projectIds.forEach((d) => this.projectIds.add(d));
|
||||||
// this.map.set(row.id, data.projectIds);
|
this.map.set(row.id, data.projectIds);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue