From 8f7e233510299b9e3264e61d476f607be7d15e58 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 29 Nov 2022 13:46:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020409 --user=陈建星 【测试跟踪】测试跟踪-报告-导出测试计划报告报500 https://www.tapd.cn/55049933/s/1307308 --- .../plan/service/TestPlanService.java | 37 ++++++++----------- .../api/PlanTestPlanApiCaseService.java | 3 ++ .../api/PlanTestPlanScenarioCaseService.java | 4 ++ .../PlanTestPlanLoadCaseService.java | 4 ++ .../ui/PlanTestPlanUiScenarioCaseService.java | 4 ++ 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 7c7c37fbf1..56bf64431e 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -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) res)); - runReportWithExceptionHandle(report, r -> planTestPlanApiCaseService.buildResponse(r.getApiFailureCases()), - (r, res) -> r.setApiFailureCases((List) res)); - runReportWithExceptionHandle(report, r -> planTestPlanScenarioCaseService.buildResponse(r.getScenarioAllCases()), - (r, res) -> r.setScenarioAllCases((List) res)); - runReportWithExceptionHandle(report, r -> planTestPlanScenarioCaseService.buildResponse(r.getScenarioFailureCases()), - (r, res) -> r.setScenarioFailureCases((List) res)); + Set 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) res)); - runReportWithExceptionHandle(report, r -> planTestPlanUiScenarioCaseService.buildResponse(r.getUiFailureCases()), - (r, res) -> r.setUiFailureCases((List) 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) res)); report.setLang(lang); render(report, response); } - public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function getCaseFunc, - BiConsumer 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"); diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java index ab10578911..a524f5f45d 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java @@ -147,6 +147,9 @@ public class PlanTestPlanApiCaseService extends ApiTestService { } public List buildResponse(List apiAllCases) { + if (CollectionUtils.isEmpty(apiAllCases)) { + return null; + } return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", apiAllCases, TestPlanFailureApiDTO.class); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java index 73085f3b74..1e9b4e6f19 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java @@ -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 buildResponse(List scenarioCases) { + if (CollectionUtils.isEmpty(scenarioCases)) { + return null; + } return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", scenarioCases, TestPlanFailureScenarioDTO.class); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java index 0311a964b4..30a9077602 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java @@ -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 buildResponse(List loadCases) { + if (CollectionUtils.isEmpty(loadCases)) { + return null; + } return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", loadCases, TestPlanLoadCaseDTO.class); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java index 5c539bd15f..5b30f6c4c7 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/ui/PlanTestPlanUiScenarioCaseService.java @@ -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 buildResponse(List uiCases) { + if (CollectionUtils.isEmpty(uiCases)) { + return null; + } return microService.postForDataArray(serviceName, BASE_UEL + "/build/response", uiCases, TestPlanUiScenarioDTO.class); }