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 c40464736b
commit afbe89092d
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 { public void exportPlanDbReport(String reportId, String lang, HttpServletResponse response) throws UnsupportedEncodingException {
TestPlanSimpleReportDTO report = testPlanReportService.getReport(reportId); 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()), Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
(r, res) -> r.setScenarioAllCases((List<TestPlanFailureScenarioDTO>) res)); if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
runReportWithExceptionHandle(report, r -> planTestPlanScenarioCaseService.buildResponse(r.getScenarioFailureCases()), report.setApiAllCases(planTestPlanApiCaseService.buildResponse(report.getApiAllCases()));
(r, res) -> r.setScenarioFailureCases((List<TestPlanFailureScenarioDTO>) res)); 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()), if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
(r, res) -> r.setUiAllCases((List<TestPlanUiScenarioDTO>) res)); report.setUiAllCases(planTestPlanUiScenarioCaseService.buildResponse(report.getUiAllCases()));
runReportWithExceptionHandle(report, r -> planTestPlanUiScenarioCaseService.buildResponse(r.getUiFailureCases()), report.setUiFailureCases(planTestPlanUiScenarioCaseService.buildResponse(report.getUiFailureCases()));
(r, res) -> r.setUiFailureCases((List<TestPlanUiScenarioDTO>) res)); }
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); report.setLang(lang);
render(report, response); 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) { public Boolean checkReportConfig(Map config, String key) {
return ServiceUtils.checkConfigEnable(config, key); return ServiceUtils.checkConfigEnable(config, key);
} }
public void render(TestPlanSimpleReportDTO report, HttpServletResponse response) throws UnsupportedEncodingException { public void render(TestPlanSimpleReportDTO report, HttpServletResponse response) throws UnsupportedEncodingException {
response.reset(); response.reset();
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");

View File

@ -147,6 +147,9 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
} }
public List<TestPlanFailureApiDTO> buildResponse(List<TestPlanFailureApiDTO> apiAllCases) { public List<TestPlanFailureApiDTO> buildResponse(List<TestPlanFailureApiDTO> apiAllCases) {
if (CollectionUtils.isEmpty(apiAllCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", apiAllCases, TestPlanFailureApiDTO.class); 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.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
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;
@ -175,6 +176,9 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
} }
public List<TestPlanFailureScenarioDTO> buildResponse(List<TestPlanFailureScenarioDTO> scenarioCases) { public List<TestPlanFailureScenarioDTO> buildResponse(List<TestPlanFailureScenarioDTO> scenarioCases) {
if (CollectionUtils.isEmpty(scenarioCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", scenarioCases, TestPlanFailureScenarioDTO.class); 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.service.TestPlanService;
import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -118,6 +119,9 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
} }
public List<TestPlanLoadCaseDTO> buildResponse(List<TestPlanLoadCaseDTO> loadCases) { public List<TestPlanLoadCaseDTO> buildResponse(List<TestPlanLoadCaseDTO> loadCases) {
if (CollectionUtils.isEmpty(loadCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", loadCases, TestPlanLoadCaseDTO.class); 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.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.ResetOrderRequest;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import org.apache.commons.collections.CollectionUtils;
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;
@ -129,6 +130,9 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
} }
public List<TestPlanUiScenarioDTO> buildResponse(List<TestPlanUiScenarioDTO> uiCases) { public List<TestPlanUiScenarioDTO> buildResponse(List<TestPlanUiScenarioDTO> uiCases) {
if (CollectionUtils.isEmpty(uiCases)) {
return null;
}
return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", uiCases, TestPlanUiScenarioDTO.class); return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", uiCases, TestPlanUiScenarioDTO.class);
} }