diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java index 58869caa67..27c77fc1f9 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java @@ -8,6 +8,7 @@ import io.metersphere.api.dto.automation.TestPlanFailureApiDTO; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; +import io.metersphere.base.domain.ApiScenarioReportWithBLOBs; import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogModule; import io.metersphere.commons.constants.PermissionConstants; @@ -204,4 +205,10 @@ public class TestPlanApiCaseController { public List selectExtForPlanReport(@PathVariable("planId") String planId) { return testPlanApiCaseService.selectExtForPlanReport(planId); } + + @GetMapping("/get/report/scenario/ext/{planId}") + public List selectExtForPlanScenarioReport(@PathVariable("planId") String planId) { + return testPlanApiCaseService.selectExtForPlanScenarioReport(planId); + } + } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index f94b6e1bc9..b4bed96b2e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -16,6 +16,7 @@ import io.metersphere.api.exec.api.ApiExecuteService; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; +import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; @@ -91,6 +92,8 @@ public class TestPlanApiCaseService { private TestPlanService testPlanService; @Resource private JMeterService jMeterService; + @Resource + private ApiScenarioReportMapper apiScenarioReportMapper; public List list(ApiTestCaseRequest request) { request.setProjectId(null); @@ -818,6 +821,14 @@ public class TestPlanApiCaseService { return results; } + public List selectExtForPlanScenarioReport(String planId) { + ApiScenarioReportExample example = new ApiScenarioReportExample(); + example.createCriteria().andRelevanceTestPlanReportIdEqualTo(planId); + List results = apiScenarioReportMapper.selectByExampleWithBLOBs(example); + return results; + } + + public List getApiCaseProjectIds(String planId) { TestPlanApiCaseExample caseExample = new TestPlanApiCaseExample(); caseExample.createCriteria().andTestPlanIdEqualTo(planId); diff --git a/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java b/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java index d0fe0cf2c2..9bd02e25a1 100644 --- a/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java +++ b/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java @@ -199,4 +199,9 @@ public class TestPlanLoadCaseController { testPlanLoadCaseService.buildLoadResponse(cases); return cases; } + + @GetMapping("/pool/{loadReportId}") + public String getPlanLoadCaseResourcePoolId(@PathVariable String loadReportId) { + return testPlanLoadCaseService.getPlanLoadCaseResourcePoolId(loadReportId); + } } diff --git a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java index 29047e6aaa..08cb15923e 100644 --- a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java +++ b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java @@ -34,6 +34,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; import javax.annotation.Resource; import java.util.*; @@ -410,6 +411,17 @@ public class TestPlanLoadCaseService { return StringUtils.EMPTY; } + public String getPlanLoadCaseResourcePoolId(String loadReportId) { + if (StringUtils.isBlank(loadReportId)) { + return StringUtils.EMPTY; + } + LoadTestReportWithBLOBs loadCases = loadTestReportMapper.selectByPrimaryKey(loadReportId); + if (loadCases != null) { + return loadCases.getTestResourcePoolId(); + } + return StringUtils.EMPTY; + } + public String getAdvancedConfiguration(String loadCaseId) { if (StringUtils.isBlank(loadCaseId)) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/PlanEnvConfig.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/PlanEnvConfig.java new file mode 100644 index 0000000000..98ae3eb9a8 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/PlanEnvConfig.java @@ -0,0 +1,8 @@ +package io.metersphere.plan.dto; + +import lombok.Data; + +@Data +public class PlanEnvConfig { + private String runMode; +} diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 24864afe71..20dd205035 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -1400,4 +1400,100 @@ public class TestPlanReportService { } return null; } + + public TestPlanSimpleReportDTO getReportOpt(String reportId) { + TestPlanReportContentExample example = new TestPlanReportContentExample(); + example.createCriteria().andTestPlanReportIdEqualTo(reportId); + List testPlanReportContents = testPlanReportContentMapper.selectByExampleWithBLOBs(example); + if (CollectionUtils.isEmpty(testPlanReportContents)) { + return null; + } + TestPlanReportContentWithBLOBs testPlanReportContent = testPlanReportContents.get(0); + if (testPlanReportContent == null) { + return null; + } + if (this.isDynamicallyGenerateReports(testPlanReportContent)) { + testPlanReportContent = this.dynamicallyGenerateReports(testPlanReportContent); + } + TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO(); + BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent); + this.generateEnvironmentInfo(testPlanReportDTO, reportId); + + testPlanReportDTO.setFunctionResult( + getReportContentResultObject(testPlanReportContent.getFunctionResult(), TestPlanFunctionResultReportDTO.class) + ); + + testPlanReportDTO.setApiResult( + getReportContentResultObject(testPlanReportContent.getApiResult(), TestPlanApiResultReportDTO.class) + ); + + testPlanReportDTO.setLoadResult( + getReportContentResultObject(testPlanReportContent.getLoadResult(), TestPlanLoadResultReportDTO.class) + ); + + testPlanReportDTO.setFunctionAllCases( + getReportContentResultArray(testPlanReportContent.getFunctionAllCases(), TestPlanCaseDTO.class) + ); + + testPlanReportDTO.setIssueList( + getReportContentResultArray(testPlanReportContent.getIssueList(), IssuesDao.class) + ); + + testPlanReportDTO.setApiAllCases( + getReportContentResultArray(testPlanReportContent.getApiAllCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setApiFailureCases( + getReportContentResultArray(testPlanReportContent.getApiFailureCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setScenarioAllCases( + getReportContentResultArray(testPlanReportContent.getScenarioAllCases(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setScenarioFailureCases( + getReportContentResultArray(testPlanReportContent.getScenarioFailureCases(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setLoadAllCases( + getReportContentResultArray(testPlanReportContent.getLoadAllCases(), TestPlanLoadCaseDTO.class) + ); + + testPlanReportDTO.setLoadFailureCases( + getReportContentResultArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class) + ); + + testPlanReportDTO.setErrorReportCases( + getReportContentResultArray(testPlanReportContent.getErrorReportCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setErrorReportScenarios( + getReportContentResultArray(testPlanReportContent.getErrorReportScenarios(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setUnExecuteCases( + getReportContentResultArray(testPlanReportContent.getUnExecuteCases(), TestPlanFailureApiDTO.class) + ); + + testPlanReportDTO.setUnExecuteScenarios( + getReportContentResultArray(testPlanReportContent.getUnExecuteScenarios(), TestPlanFailureScenarioDTO.class) + ); + + testPlanReportDTO.setUiResult( + getReportContentResultObject(testPlanReportContent.getUiResult(), TestPlanUiResultReportDTO.class) + ); + + testPlanReportDTO.setUiAllCases( + getReportContentResultArray(testPlanReportContent.getUiAllCases(), TestPlanUiScenarioDTO.class) + ); + + testPlanReportDTO.setUiFailureCases( + getReportContentResultArray(testPlanReportContent.getUiFailureCases(), TestPlanUiScenarioDTO.class) + ); + + testPlanReportDTO.setId(reportId); + TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId()); + testPlanReportDTO.setName(testPlanReport.getName()); + return testPlanReportDTO; + } } 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 cc1b279083..efa6e1410d 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 @@ -156,6 +156,8 @@ public class TestPlanService { private SystemParameterService systemParameterService; @Resource private BaseProjectApplicationService projectApplicationService; + @Resource + private TestPlanReportMapper testPlanReportMapper; public static final String POOL = "POOL"; public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { @@ -2013,6 +2015,13 @@ public class TestPlanService { getResourcePool(apiDefinition.getActuator(), testPlanExtReportDTO); return testPlanExtReportDTO; } + List apiScenarioLists = planTestPlanApiCaseService.selectExtForPlanScenarioReport(reportId); + if(CollectionUtils.isNotEmpty(apiScenarioLists)){ + ApiScenarioReportWithBLOBs apiScenario = apiScenarioLists.get(0); + convertEnvConfig(apiScenario.getEnvConfig(), testPlanExtReportDTO); + getResourcePool(apiScenario.getActuator(), testPlanExtReportDTO); + return testPlanExtReportDTO; + } } if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { List apiDefinitionLists = planTestPlanUiScenarioCaseService.selectExtForPlanReport(reportId); @@ -2023,6 +2032,25 @@ public class TestPlanService { return testPlanExtReportDTO; } } + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + TestPlanSimpleReportDTO testPlanSimpleReportDTO = testPlanReportService.getReportOpt(reportId); + if (testPlanSimpleReportDTO != null) { + List loadList = testPlanSimpleReportDTO.getLoadAllCases(); + if (CollectionUtils.isNotEmpty(loadList)) { + String loadReportId = loadList.get(0).getLoadReportId(); + if (StringUtils.isNotEmpty(loadReportId)) { + // 资源池 + String planLoadCaseResourcePoolId = planTestPlanLoadCaseService.getPlanLoadCaseResourcePoolId(loadReportId); + // 运行模式 + TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId); + if (testPlanReport != null && StringUtils.isNotEmpty(testPlanReport.getRunInfo())) { + convertPlanEnvConfig(testPlanReport.getRunInfo(), testPlanExtReportDTO); + } + getResourcePool(planLoadCaseResourcePoolId, testPlanExtReportDTO); + } + } + } + } return testPlanExtReportDTO; } @@ -2063,6 +2091,13 @@ public class TestPlanService { getResourcePool(apiDefinition.getActuator(), testPlanExtReportDTO); return testPlanExtReportDTO; } + List apiScenarioLists = planTestPlanApiCaseService.selectExtForPlanScenarioReport(reportId); + if(CollectionUtils.isNotEmpty(apiScenarioLists)){ + ApiScenarioReportWithBLOBs apiScenario = apiScenarioLists.get(0); + convertEnvConfig(apiScenario.getEnvConfig(), testPlanExtReportDTO); + getResourcePool(apiScenario.getActuator(), testPlanExtReportDTO); + return testPlanExtReportDTO; + } } if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { List apiDefinitionLists = planTestPlanUiScenarioCaseService.selectExtForPlanReport(reportId); @@ -2073,6 +2108,25 @@ public class TestPlanService { return testPlanExtReportDTO; } } + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + TestPlanSimpleReportDTO testPlanSimpleReportDTO = testPlanReportService.getReportOpt(reportId); + if (testPlanSimpleReportDTO != null) { + List loadList = testPlanSimpleReportDTO.getLoadAllCases(); + if (CollectionUtils.isNotEmpty(loadList)) { + String loadReportId = loadList.get(0).getLoadReportId(); + if (StringUtils.isNotEmpty(loadReportId)) { + // 资源池 + String planLoadCaseResourcePoolId = planTestPlanLoadCaseService.getPlanLoadCaseResourcePoolId(loadReportId); + // 运行模式 + TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId); + if (testPlanReport != null && StringUtils.isNotEmpty(testPlanReport.getRunInfo())) { + convertPlanEnvConfig(testPlanReport.getRunInfo(), testPlanExtReportDTO); + } + getResourcePool(planLoadCaseResourcePoolId, testPlanExtReportDTO); + } + } + } + } return testPlanExtReportDTO; } @@ -2088,4 +2142,18 @@ public class TestPlanService { projectIds.addAll(apiScenarioProjectIds); return projectIds.stream().distinct().collect(Collectors.toList()); } + + private void convertPlanEnvConfig(String envConfig, TestPlanExtReportDTO testPlanExtReportDTO) throws JsonProcessingException { + if(StringUtils.isEmpty(envConfig)){ + return; + } + PlanEnvConfig env = objectMapper.readValue(envConfig, PlanEnvConfig.class); + if(StringUtils.isNotEmpty(env.getRunMode())){ + if(RunMode.RUN_MODE_SERIAL.getCode().equals(env.getRunMode())){ + testPlanExtReportDTO.setRunMode(RunMode.RUN_MODE_SERIAL.getDesc()); + } else if (RunMode.RUN_MODE_PARALLEL.getCode().equals(env.getRunMode())) { + testPlanExtReportDTO.setRunMode(RunMode.RUN_MODE_PARALLEL.getDesc()); + } + } + } } 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 0ce57537bf..9e33a1ccd0 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 @@ -1,6 +1,7 @@ package io.metersphere.plan.service.remote.api; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; +import io.metersphere.base.domain.ApiScenarioReportWithBLOBs; import io.metersphere.commons.constants.MicroServiceName; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; @@ -166,4 +167,8 @@ public class PlanTestPlanApiCaseService extends ApiTestService { public List selectExtForPlanReport(String planId) { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/ext/" + planId, ApiDefinitionExecResultWithBLOBs.class); } + + public List selectExtForPlanScenarioReport(String planId) { + return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/scenario/ext/" + planId, ApiScenarioReportWithBLOBs.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 30a9077602..f9d667d607 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 @@ -129,4 +129,9 @@ public class PlanTestPlanLoadCaseService extends LoadTestService { request.setAllowedRepeatCase(testPlanService.isAllowedRepeatCase(request.getTestPlanId())); return microService.postForData(serviceName, BASE_UEL + String.format("/relevance/list/%s/%s", pageNum, pageSize), request); } + + public String getPlanLoadCaseResourcePoolId(String loadReportId) { + return (String) microService.getForData(serviceName, BASE_UEL + "/pool/" + loadReportId); + } + }