fix(接口测试): 修复用例集合报告不展示步骤的问题 (#12532)

修复用例集合报告不展示步骤的问题

Co-authored-by: song-tianyang <tianyang.song@fit2cloud.com>
This commit is contained in:
MeterSphere Bot 2022-04-12 17:56:28 +08:00 committed by GitHub
parent cabc285686
commit 82884face5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 46 deletions

View File

@ -152,30 +152,4 @@ public class ApiScenarioReportResultService {
report.setContent(JSON.toJSONString(result).getBytes(StandardCharsets.UTF_8)); report.setContent(JSON.toJSONString(result).getBytes(StandardCharsets.UTF_8));
return report; return report;
} }
public boolean isResultFormat(ApiScenarioReportResultWithBLOBs result) {
if (result != null && result.getBaseInfo() != null) {
return true;
}else {
return false;
}
}
public ApiScenarioReportResultWithBLOBs formatScenarioResult(ApiScenarioReportResultWithBLOBs result) {
if (!this.isResultFormat(result)) {
ApiScenarioReportResultWithBLOBs baseResult = apiScenarioReportResultMapper.selectByPrimaryKey(result.getId());
if (baseResult != null) {
try {
RequestResult requestResult = JSON.parseObject(new String(baseResult.getContent(), StandardCharsets.UTF_8), RequestResult.class);
//记录基础信息
baseResult.setBaseInfo(JSONObject.toJSONString(getBaseInfo(requestResult)));
apiScenarioReportResultMapper.updateByPrimaryKeySelective(baseResult);
return baseResult;
} catch (Exception e) {
LogUtil.error("format scenario result error:" + e.getMessage());
}
}
}
return result;
}
} }

View File

@ -245,24 +245,23 @@ public class ApiScenarioReportStructureService {
if (reportResults.size() > 1) { if (reportResults.size() > 1) {
for (int i = 0; i < reportResults.size(); i++) { for (int i = 0; i < reportResults.size(); i++) {
ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(i); ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(i);
if(reportResult.getContent() != null){ //来自报告导出的数据
//来自报告导出的数据 if (i == 0) {
if (i == 0) { if (reportResult.getContent() != null) {
dto.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class)); dto.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
dto.setErrorCode(reportResults.get(0).getErrorCode()); dto.setErrorCode(reportResults.get(0).getErrorCode());
} else { } else {
StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), reportResults.get(i).getId(), (i + 1));
step.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
step.setErrorCode(reportResults.get(i).getErrorCode());
dtoList.add(step);
}
}else {
reportResult = apiScenarioReportResultService.formatScenarioResult(reportResult);
if (i == 0) {
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult); RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult);
dto.setStepId(reportResults.get(i).getId()); dto.setStepId(reportResults.get(i).getId());
dto.setValue(requestResultExpandDTO); dto.setValue(requestResultExpandDTO);
dto.setErrorCode(reportResults.get(0).getErrorCode()); dto.setErrorCode(reportResults.get(0).getErrorCode());
}
} else {
if (reportResult.getContent() != null) {
StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), reportResults.get(i).getId(), (i + 1));
step.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
step.setErrorCode(reportResults.get(i).getErrorCode());
dtoList.add(step);
} else { } else {
StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), reportResults.get(i).getId(), (i + 1)); StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), reportResults.get(i).getId(), (i + 1));
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult); RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult);
@ -274,12 +273,11 @@ public class ApiScenarioReportStructureService {
} }
} else { } else {
ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(0); ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(0);
if(reportResult.getContent() != null){ if (reportResult.getContent() != null) {
String content = new String(reportResults.get(0).getContent(), StandardCharsets.UTF_8); String content = new String(reportResults.get(0).getContent(), StandardCharsets.UTF_8);
dto.setValue(JSON.parseObject(content, RequestResult.class)); dto.setValue(JSON.parseObject(content, RequestResult.class));
dto.setErrorCode(reportResults.get(0).getErrorCode()); dto.setErrorCode(reportResults.get(0).getErrorCode());
}else { } else {
reportResult = apiScenarioReportResultService.formatScenarioResult(reportResult);
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult); RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult);
dto.setStepId(reportResults.get(0).getId()); dto.setStepId(reportResults.get(0).getId());
dto.setValue(requestResultExpandDTO); dto.setValue(requestResultExpandDTO);
@ -436,7 +434,7 @@ public class ApiScenarioReportStructureService {
vo.setRequestResult(requestResultExpandDTO); vo.setRequestResult(requestResultExpandDTO);
} }
StepTreeDTO treeDTO = new StepTreeDTO(item.getName(), item.getResourceId(), "API", item.getId(), (i + 1)); StepTreeDTO treeDTO = new StepTreeDTO(item.getName(), item.getResourceId(), "API", item.getId(), (i + 1));
// treeDTO.setValue(vo.getRequestResult()); treeDTO.setValue(vo.getRequestResult());
if (vo.getRequestResult() != null && vo.getRequestResult() instanceof RequestResultExpandDTO) { if (vo.getRequestResult() != null && vo.getRequestResult() instanceof RequestResultExpandDTO) {
RequestResultExpandDTO expandDTO = (RequestResultExpandDTO) vo.getRequestResult(); RequestResultExpandDTO expandDTO = (RequestResultExpandDTO) vo.getRequestResult();
if (expandDTO.getAttachInfoMap() != null && expandDTO.getAttachInfoMap().get("errorReportResult") != null) { if (expandDTO.getAttachInfoMap() != null && expandDTO.getAttachInfoMap().get("errorReportResult") != null) {
@ -495,23 +493,36 @@ public class ApiScenarioReportStructureService {
return reportDTO; return reportDTO;
} }
public ApiScenarioReportDTO assembleReport(String reportId,boolean selectReportContent) { public ApiScenarioReportDTO assembleReport(String reportId, boolean selectReportContent) {
ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId); ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId);
if (report != null && report.getReportType().equals(ReportTypeConstants.API_INTEGRATED.name())) { if (report != null && report.getReportType().equals(ReportTypeConstants.API_INTEGRATED.name())) {
return this.apiIntegratedReport(reportId); return this.apiIntegratedReport(reportId);
} else { } else {
return this.getReport(reportId,selectReportContent); return this.getReport(reportId, selectReportContent);
} }
} }
private ApiScenarioReportDTO getReport(String reportId,boolean selectContent) { private ApiScenarioReportDTO getReport(String reportId, boolean selectContent) {
List<ApiScenarioReportResultWithBLOBs> reportResults = null; List<ApiScenarioReportResultWithBLOBs> reportResults = null;
if(selectContent){ if (selectContent) {
ApiScenarioReportResultExample example = new ApiScenarioReportResultExample(); ApiScenarioReportResultExample example = new ApiScenarioReportResultExample();
example.createCriteria().andReportIdEqualTo(reportId); example.createCriteria().andReportIdEqualTo(reportId);
reportResults = reportResultMapper.selectByExampleWithBLOBs(example); reportResults = reportResultMapper.selectByExampleWithBLOBs(example);
} else { } else {
reportResults = this.selectBaseInfoResultByReportId(reportId); reportResults = this.selectBaseInfoResultByReportId(reportId);
//判断base_info是否为空为空则是旧数据
boolean isBaseInfoNull = false;
for (ApiScenarioReportResultWithBLOBs result : reportResults) {
if (result.getBaseInfo() == null) {
isBaseInfoNull = true;
break;
}
}
if (isBaseInfoNull) {
ApiScenarioReportResultExample example = new ApiScenarioReportResultExample();
example.createCriteria().andReportIdEqualTo(reportId);
reportResults = reportResultMapper.selectByExampleWithBLOBs(example);
}
} }
removeUiResultIfNotStep(reportResults, reportId); removeUiResultIfNotStep(reportResults, reportId);
@ -574,7 +585,7 @@ public class ApiScenarioReportStructureService {
private void removeUiResultIfNotStep(List<ApiScenarioReportResultWithBLOBs> reportResults, String reportId) { private void removeUiResultIfNotStep(List<ApiScenarioReportResultWithBLOBs> reportResults, String reportId) {
ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId); ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId);
if (report.getReportType() != null && report.getReportType().startsWith("UI")) { if (report.getReportType() != null && report.getReportType().startsWith("UI")) {
if(CollectionUtils.isNotEmpty(reportResults)){ if (CollectionUtils.isNotEmpty(reportResults)) {
Iterator<ApiScenarioReportResultWithBLOBs> iterator = reportResults.iterator(); Iterator<ApiScenarioReportResultWithBLOBs> iterator = reportResults.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
ApiScenarioReportResultWithBLOBs item = iterator.next(); ApiScenarioReportResultWithBLOBs item = iterator.next();