fix(测试跟踪): 测试计划报告增加对1.20版本保存的测试计划报告数据的支持

--bug=1026580 --user=宋天阳 【测试跟踪】查看测试报告失败
https://www.tapd.cn/55049933/s/1376774
This commit is contained in:
song-tianyang 2023-05-29 19:02:13 +08:00 committed by 建国
parent b61b1c67d7
commit c875969fa8
3 changed files with 112 additions and 5 deletions

View File

@ -2,7 +2,9 @@ package io.metersphere.plan.dto;
import io.metersphere.base.domain.TestPlanReportContent; import io.metersphere.base.domain.TestPlanReportContent;
import io.metersphere.base.domain.TestPlanReportContentWithBLOBs;
import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.utils.JSON;
import io.metersphere.dto.*; import io.metersphere.dto.*;
import io.metersphere.plan.constant.ApiReportStatus; import io.metersphere.plan.constant.ApiReportStatus;
import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.xpack.track.dto.IssuesDao;
@ -110,4 +112,111 @@ public class TestPlanReportDataStruct extends TestPlanReportContent {
} }
return false; return false;
} }
public TestPlanReportDataStruct() {
}
public TestPlanReportDataStruct(TestPlanReportContentWithBLOBs testPlanReportContent) {
if (testPlanReportContent == null) {
return;
}
this.setExecuteRate(testPlanReportContent.getExecuteRate());
this.setPassRate(testPlanReportContent.getPassRate());
if (StringUtils.isNotEmpty(testPlanReportContent.getSummary())) {
this.setSummary(testPlanReportContent.getSummary());
}
if (StringUtils.isNotEmpty(testPlanReportContent.getConfig())) {
this.setConfig(testPlanReportContent.getConfig());
}
if (StringUtils.isNotEmpty(testPlanReportContent.getFunctionResult())) {
TestPlanFunctionResultReportDTO dto = this.parseJsonStringToObj(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class);
this.setFunctionResult(dto);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getApiResult())) {
TestPlanApiResultReportDTO dto = this.parseJsonStringToObj(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class);
this.setApiResult(dto);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getLoadResult())) {
TestPlanLoadResultReportDTO dto = this.parseJsonStringToObj(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class);
this.setLoadResult(dto);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getUiResult())) {
TestPlanUiResultReportDTO dto = this.parseJsonStringToObj(testPlanReportContent.getUiResult(), TestPlanUiResultReportDTO.class);
this.setUiResult(dto);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getFunctionAllCases())) {
List<TestPlanCaseDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class);
this.setFunctionAllCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getIssueList())) {
List<IssuesDao> dtoList = this.parseJsonStringToArray(testPlanReportContent.getIssueList(), IssuesDao.class);
this.setIssueList(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getLoadAllCases())) {
List<TestPlanLoadCaseDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class);
this.setLoadAllCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getLoadFailureCases())) {
List<TestPlanLoadCaseDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class);
this.setLoadFailureCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getApiAllCases())) {
List<TestPlanApiDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getApiAllCases(), TestPlanApiDTO.class);
this.setApiAllCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getErrorReportCases())) {
List<TestPlanApiDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getErrorReportCases(), TestPlanApiDTO.class);
this.setErrorReportCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getApiFailureCases())) {
List<TestPlanApiDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getApiFailureCases(), TestPlanApiDTO.class);
this.setApiFailureCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getUnExecuteCases())) {
List<TestPlanApiDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getUnExecuteCases(), TestPlanApiDTO.class);
this.setUnExecuteCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getScenarioAllCases())) {
List<TestPlanScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getScenarioAllCases(), TestPlanScenarioDTO.class);
this.setScenarioAllCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getErrorReportScenarios())) {
List<TestPlanScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getErrorReportScenarios(), TestPlanScenarioDTO.class);
this.setErrorReportScenarios(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getScenarioFailureCases())) {
List<TestPlanScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getScenarioFailureCases(), TestPlanScenarioDTO.class);
this.setScenarioFailureCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getUnExecuteScenarios())) {
List<TestPlanScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getUnExecuteScenarios(), TestPlanScenarioDTO.class);
this.setUnExecuteScenarios(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getUiAllCases())) {
List<TestPlanUiScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getUiAllCases(), TestPlanUiScenarioDTO.class);
this.setUiAllCases(dtoList);
}
if (StringUtils.isNotEmpty(testPlanReportContent.getUiFailureCases())) {
List<TestPlanUiScenarioDTO> dtoList = this.parseJsonStringToArray(testPlanReportContent.getUiFailureCases(), TestPlanUiScenarioDTO.class);
this.setUiFailureCases(dtoList);
}
}
private <T> T parseJsonStringToObj(String jsonString, Class<T> valueType) {
try {
return JSON.parseObject(jsonString, valueType);
} catch (Exception e) {
return null;
}
}
private <T> List<T> parseJsonStringToArray(String jsonString, Class<T> valueType) {
try {
return JSON.parseArray(jsonString, valueType);
} catch (Exception e) {
return null;
}
}
} }

View File

@ -956,10 +956,6 @@ public class TestPlanReportService {
TestPlanReportDataMapper planReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class); TestPlanReportDataMapper planReportDataMapper = sqlSession.getMapper(TestPlanReportDataMapper.class);
TestPlanReportContentMapper planReportContentMapper = sqlSession.getMapper(TestPlanReportContentMapper.class); TestPlanReportContentMapper planReportContentMapper = sqlSession.getMapper(TestPlanReportContentMapper.class);
// ApiDefinitionExecResultMapper batchDefinitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
// ApiScenarioReportMapper batchScenarioReportMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
// LoadTestReportMapper batchLoadTestReportMapper = sqlSession.getMapper(LoadTestReportMapper.class);
try { try {
while (reportIds.size() > handleCount) { while (reportIds.size() > handleCount) {
handleIdList = new ArrayList<>(handleCount); handleIdList = new ArrayList<>(handleCount);
@ -1124,6 +1120,8 @@ public class TestPlanReportService {
if (this.isDynamicallyGenerateReports(testPlanReportContent) || StringUtils.isNotEmpty(testPlanReportContent.getApiBaseCount())) { if (this.isDynamicallyGenerateReports(testPlanReportContent) || StringUtils.isNotEmpty(testPlanReportContent.getApiBaseCount())) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId()); TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId());
testPlanReportDTO = testPlanService.generateReportStruct(testPlan, testPlanReport, testPlanReportContent, false); testPlanReportDTO = testPlanService.generateReportStruct(testPlan, testPlanReport, testPlanReportContent, false);
} else {
testPlanReportDTO = new TestPlanReportDataStruct(testPlanReportContent);
} }
if (StringUtils.isNotEmpty(testPlanReportContent.getSummary())) { if (StringUtils.isNotEmpty(testPlanReportContent.getSummary())) {
testPlanReportDTO.setSummary(testPlanReportContent.getSummary()); testPlanReportDTO.setSummary(testPlanReportContent.getSummary());

View File

@ -2286,7 +2286,7 @@ public class TestPlanService {
TestPlanReportDataStruct testPlanReportDataStruct = new TestPlanReportDataStruct(); TestPlanReportDataStruct testPlanReportDataStruct = new TestPlanReportDataStruct();
try { try {
testPlanReportDataStruct = this.generateReportStruct(testPlanWithBLOBs, testPlanReport, testPlanReportContent, false); testPlanReportDataStruct = this.generateReportStruct(testPlanWithBLOBs, testPlanReport, testPlanReportContent, false);
if (StringUtils.isBlank(testPlanReportContent.getApiBaseCount()) if (testPlanReportContent != null && StringUtils.isBlank(testPlanReportContent.getApiBaseCount())
&& !testPlanReportDataStruct.hasRunningCase() && !testPlanReportDataStruct.hasRunningCase()
&& StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), TestPlanReportStatus.FAILED.name(), TestPlanReportStatus.COMPLETED.name(), TestPlanReportStatus.SUCCESS.name())) { && StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), TestPlanReportStatus.FAILED.name(), TestPlanReportStatus.COMPLETED.name(), TestPlanReportStatus.SUCCESS.name())) {
//旧版本的测试计划报告没有重新统计过测试计划报告时且当不存在运行中的用例会将结果保存下来 //旧版本的测试计划报告没有重新统计过测试计划报告时且当不存在运行中的用例会将结果保存下来