fix(测试跟踪): 测试计划报告导出报错

--bug=1020409 --user=陈建星 【测试跟踪】测试跟踪-报告-导出测试计划报告报500 https://www.tapd.cn/55049933/s/1307308
This commit is contained in:
chenjianxing 2022-11-29 13:46:26 +08:00 committed by jianxing
parent 33c8af78a4
commit 8f7e233510
5 changed files with 30 additions and 22 deletions

View File

@ -1375,39 +1375,32 @@ public class TestPlanService {
public void exportPlanDbReport(String reportId, String lang, HttpServletResponse response) throws UnsupportedEncodingException {
TestPlanSimpleReportDTO report = testPlanReportService.getReport(reportId);
runReportWithExceptionHandle(report, r -> planTestPlanApiCaseService.buildResponse(r.getApiAllCases()),
(r, res) -> r.setApiAllCases((List<TestPlanFailureApiDTO>) res));
runReportWithExceptionHandle(report, r -> planTestPlanApiCaseService.buildResponse(r.getApiFailureCases()),
(r, res) -> r.setApiFailureCases((List<TestPlanFailureApiDTO>) res));
runReportWithExceptionHandle(report, r -> planTestPlanScenarioCaseService.buildResponse(r.getScenarioAllCases()),
(r, res) -> r.setScenarioAllCases((List<TestPlanFailureScenarioDTO>) res));
runReportWithExceptionHandle(report, r -> planTestPlanScenarioCaseService.buildResponse(r.getScenarioFailureCases()),
(r, res) -> r.setScenarioFailureCases((List<TestPlanFailureScenarioDTO>) res));
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
report.setApiAllCases(planTestPlanApiCaseService.buildResponse(report.getApiAllCases()));
report.setApiFailureCases(planTestPlanApiCaseService.buildResponse(report.getApiFailureCases()));
report.setScenarioAllCases(planTestPlanScenarioCaseService.buildResponse(report.getScenarioAllCases()));
report.setScenarioFailureCases(planTestPlanScenarioCaseService.buildResponse(report.getScenarioFailureCases()));
}
runReportWithExceptionHandle(report, r -> planTestPlanUiScenarioCaseService.buildResponse(r.getUiAllCases()),
(r, res) -> r.setUiAllCases((List<TestPlanUiScenarioDTO>) res));
runReportWithExceptionHandle(report, r -> planTestPlanUiScenarioCaseService.buildResponse(r.getUiFailureCases()),
(r, res) -> r.setUiFailureCases((List<TestPlanUiScenarioDTO>) res));
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
report.setUiAllCases(planTestPlanUiScenarioCaseService.buildResponse(report.getUiAllCases()));
report.setUiFailureCases(planTestPlanUiScenarioCaseService.buildResponse(report.getUiFailureCases()));
}
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
report.setLoadAllCases(planTestPlanLoadCaseService.buildResponse(report.getLoadAllCases()));
}
runReportWithExceptionHandle(report, r -> planTestPlanLoadCaseService.buildResponse(r.getLoadAllCases()),
(r, res) -> r.setLoadAllCases((List<TestPlanLoadCaseDTO>) res));
report.setLang(lang);
render(report, response);
}
public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function<TestPlanSimpleReportDTO, Object> getCaseFunc,
BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) {
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
setReportCaseFunc.accept(report, getCaseFunc.apply(report));
}
}
public Boolean checkReportConfig(Map config, String key) {
return ServiceUtils.checkConfigEnable(config, key);
}
public void render(TestPlanSimpleReportDTO report, HttpServletResponse response) throws UnsupportedEncodingException {
response.reset();
response.setContentType("application/octet-stream");

View File

@ -147,6 +147,9 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
}
public List<TestPlanFailureApiDTO> buildResponse(List<TestPlanFailureApiDTO> apiAllCases) {
if (CollectionUtils.isEmpty(apiAllCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", apiAllCases, TestPlanFailureApiDTO.class);
}

View File

@ -12,6 +12,7 @@ import io.metersphere.plan.request.api.ApiScenarioRequest;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -175,6 +176,9 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
}
public List<TestPlanFailureScenarioDTO> buildResponse(List<TestPlanFailureScenarioDTO> scenarioCases) {
if (CollectionUtils.isEmpty(scenarioCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", scenarioCases, TestPlanFailureScenarioDTO.class);
}

View File

@ -15,6 +15,7 @@ import io.metersphere.plan.request.performance.LoadPlanReportDTO;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -118,6 +119,9 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
}
public List<TestPlanLoadCaseDTO> buildResponse(List<TestPlanLoadCaseDTO> loadCases) {
if (CollectionUtils.isEmpty(loadCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", loadCases, TestPlanLoadCaseDTO.class);
}

View File

@ -18,6 +18,7 @@ import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -129,6 +130,9 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
}
public List<TestPlanUiScenarioDTO> buildResponse(List<TestPlanUiScenarioDTO> uiCases) {
if (CollectionUtils.isEmpty(uiCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", uiCases, TestPlanUiScenarioDTO.class);
}