From dd3b34f0d5a669d7a4d6dfb834f2fbdba60d10e2 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 16 Dec 2022 11:15:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E6=89=A7=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=84=9A=E6=9C=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/exec/api/ApiCaseExecuteService.java | 45 +++++++++++-------- .../utils/ApiDefinitionExecResultUtil.java | 28 ++++++------ .../definition/ApiDefinitionService.java | 3 +- .../service/ext/ExtApiTaskService.java | 3 +- .../scenario/ApiScenarioReportService.java | 2 +- .../ApiScenarioReportStructureService.java | 3 +- .../scenario/ApiScenarioRerunService.java | 9 ++-- .../src/components/task/TaskCenter.vue | 3 +- 8 files changed, 56 insertions(+), 40 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java index 2abd0f12fa..900dbd0dd6 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java @@ -83,23 +83,21 @@ public class ApiCaseExecuteService { if (StringUtils.equals(EnvironmentType.GROUP.toString(), request.getConfig().getEnvironmentType()) && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { request.getConfig().setEnvMap(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId())); } - LoggerUtil.debug("开始查询测试计划用例"); + LoggerUtil.info("开始查询测试计划用例", request.getPlanIds().size()); - TestPlanApiCaseExample example = new TestPlanApiCaseExample(); - example.createCriteria().andIdIn(request.getPlanIds()); - example.setOrderByClause("`order` DESC"); - List planApiCases = testPlanApiCaseMapper.selectByExample(example); + List planApiCases = this.selectByPlanApiCaseIds(request.getPlanIds()); if (CollectionUtils.isEmpty(planApiCases)) { return responseDTOS; } if (StringUtils.isEmpty(request.getTriggerMode())) { request.setTriggerMode(ApiRunMode.API_PLAN.name()); } - LoggerUtil.debug("查询到测试计划用例 " + planApiCases.size()); + LoggerUtil.info("查询到测试计划用例 " + planApiCases.size()); Map executeQueue = request.isRerun() ? request.getExecuteQueue() : new LinkedHashMap<>(); - String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? ApiReportStatus.PENDING.name() - : ApiReportStatus.RUNNING.name(); + + String status = StringUtils.equals(request.getConfig().getMode(), RunModeConstants.SERIAL.toString()) + ? ApiReportStatus.PENDING.name() : ApiReportStatus.RUNNING.name(); // 查出用例 List apiCaseIds = planApiCases.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); @@ -117,23 +115,24 @@ public class ApiCaseExecuteService { //处理环境配置为空时的情况 RunModeConfigDTO runModeConfigDTO = new RunModeConfigDTO(); BeanUtils.copyBean(runModeConfigDTO, request.getConfig()); - if (MapUtils.isEmpty(runModeConfigDTO.getEnvMap())) { - ApiTestCase testCase = caseMap.get(testPlanApiCase.getApiCaseId()); - if (testCase != null) { - runModeConfigDTO.setEnvMap(new HashMap<>() {{ - this.put(testCase.getProjectId(), testPlanApiCase.getEnvironmentId()); - }}); - } + ApiTestCase testCase = caseMap.get(testPlanApiCase.getApiCaseId()); + if (testCase == null) { + continue; } - ApiDefinitionExecResultWithBLOBs report = ApiDefinitionExecResultUtil.addResult(request, runModeConfigDTO, testPlanApiCase, status, caseMap, resourcePoolId); + if (MapUtils.isEmpty(runModeConfigDTO.getEnvMap())) { + runModeConfigDTO.setEnvMap(new HashMap<>() {{ + this.put(testCase.getProjectId(), testPlanApiCase.getEnvironmentId()); + }}); + } + ApiDefinitionExecResultWithBLOBs report = ApiDefinitionExecResultUtil.addResult(request, runModeConfigDTO, testPlanApiCase, status, testCase, resourcePoolId); executeQueue.put(testPlanApiCase.getId(), report); responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode())); - LoggerUtil.debug("预生成测试用例结果报告:" + report.getName() + ", ID " + report.getId()); + LoggerUtil.info("预生成测试用例结果报告:" + report.getName(), report.getId()); } apiCaseResultService.batchSave(executeQueue); } - LoggerUtil.debug("开始生成测试计划队列"); + LoggerUtil.info("开始生成测试计划队列"); String reportType = request.getConfig().getReportType(); String poolId = request.getConfig().getResourcePoolId(); String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name(); @@ -157,6 +156,16 @@ public class ApiCaseExecuteService { return responseDTOS; } + public List selectByPlanApiCaseIds(List planApiCaseIds) { + if (CollectionUtils.isEmpty(planApiCaseIds)) { + return new ArrayList<>(); + } + TestPlanApiCaseExample example = new TestPlanApiCaseExample(); + example.createCriteria().andIdIn(planApiCaseIds); + example.setOrderByClause("`order` DESC"); + return testPlanApiCaseMapper.selectByExample(example); + } + public Map> checkEnv(List caseList) { Map> projectEnvMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(caseList)) { diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionExecResultUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionExecResultUtil.java index 0df2f904b7..826dd2cc82 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionExecResultUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionExecResultUtil.java @@ -8,10 +8,10 @@ import io.metersphere.base.domain.TestPlanApiCase; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ReportTypeConstants; import io.metersphere.commons.constants.TriggerMode; +import io.metersphere.commons.enums.StorageEnums; import io.metersphere.dto.RunModeConfigDTO; import org.apache.commons.lang3.StringUtils; -import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -27,7 +27,7 @@ public class ApiDefinitionExecResultUtil { apiResult.setStartTime(System.currentTimeMillis()); apiResult.setEndTime(System.currentTimeMillis()); apiResult.setTriggerMode(TriggerMode.BATCH.name()); - apiResult.setActuator("LOCAL"); + apiResult.setActuator(StorageEnums.LOCAL.name()); if (config != null && GenerateHashTreeUtil.isResourcePool(config.getResourcePoolId()).isPool()) { apiResult.setActuator(config.getResourcePoolId()); } @@ -42,31 +42,33 @@ public class ApiDefinitionExecResultUtil { return apiResult; } - public static ApiDefinitionExecResultWithBLOBs addResult(BatchRunDefinitionRequest request, RunModeConfigDTO runModeConfigDTO, TestPlanApiCase key, String status, - Map caseMap, String poolId) { + public static ApiDefinitionExecResultWithBLOBs addResult( + BatchRunDefinitionRequest request, + RunModeConfigDTO runModeConfigDTO, + TestPlanApiCase key, + String status, + ApiTestCase testCase, + String poolId) { + ApiDefinitionExecResultWithBLOBs apiResult = new ApiDefinitionExecResultWithBLOBs(); apiResult.setId(UUID.randomUUID().toString()); apiResult.setCreateTime(System.currentTimeMillis()); apiResult.setStartTime(System.currentTimeMillis()); apiResult.setEndTime(System.currentTimeMillis()); apiResult.setReportType(ReportTypeConstants.API_INDEPENDENT.name()); - ApiTestCase testCase = caseMap.get(key.getApiCaseId()); if (testCase != null) { apiResult.setName(testCase.getName()); apiResult.setProjectId(testCase.getProjectId()); apiResult.setVersionId(testCase.getVersionId()); } apiResult.setTriggerMode(request.getTriggerMode()); - apiResult.setActuator("LOCAL"); + apiResult.setActuator(StorageEnums.LOCAL.name()); if (StringUtils.isNotEmpty(poolId)) { apiResult.setActuator(poolId); } - if (StringUtils.isEmpty(request.getUserId())) { - if (SessionUtils.getUser() != null) { - apiResult.setUserId(SessionUtils.getUser().getId()); - } - } else { - apiResult.setUserId(request.getUserId()); + apiResult.setUserId(request.getUserId()); + if (StringUtils.isEmpty(apiResult.getUserId())) { + apiResult.setUserId(SessionUtils.getUserId()); } apiResult.setResourceId(key.getId()); @@ -92,7 +94,7 @@ public class ApiDefinitionExecResultUtil { apiResult.setStartTime(System.currentTimeMillis()); apiResult.setEndTime(System.currentTimeMillis()); apiResult.setTriggerMode(TriggerMode.BATCH.name()); - apiResult.setActuator("LOCAL"); + apiResult.setActuator(StorageEnums.LOCAL.name()); apiResult.setUserId(userId); apiResult.setResourceId(resourceId); apiResult.setStartTime(System.currentTimeMillis()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index ce8caf07a3..590113bc4e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -26,6 +26,7 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.*; import io.metersphere.commons.constants.*; +import io.metersphere.commons.enums.StorageEnums; import io.metersphere.commons.enums.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; @@ -997,7 +998,7 @@ public class ApiDefinitionService { apiReportEnvConfig.setResourcePoolName(resourcePool.getName()); } } else { - apiReportEnvConfig.setResourcePoolName("LOCAL"); + apiReportEnvConfig.setResourcePoolName(StorageEnums.LOCAL.name()); } return apiReportEnvConfig; } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiTaskService.java b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiTaskService.java index 5ac3070d91..b6416df443 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiTaskService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiTaskService.java @@ -14,6 +14,7 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.enums.ApiReportStatus; +import io.metersphere.commons.enums.StorageEnums; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.NodeDTO; @@ -203,7 +204,7 @@ public class ExtApiTaskService extends TaskService { if (StringUtils.isEmpty(reportId)) { return; } - if (StringUtils.isNotEmpty(actuator) && !StringUtils.equals(actuator, "LOCAL")) { + if (StringUtils.isNotEmpty(actuator) && !StringUtils.equals(actuator, StorageEnums.LOCAL.name())) { if (poolMap.containsKey(actuator)) { poolMap.get(actuator).add(reportId); } else { diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java index 4fd4deff4c..55375eb3dd 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java @@ -790,7 +790,7 @@ public class ApiScenarioReportService { if (initModel.getConfig() != null && StringUtils.isNotBlank(initModel.getConfig().getResourcePoolId())) { report.setActuator(initModel.getConfig().getResourcePoolId()); } else { - report.setActuator("LOCAL"); + report.setActuator(StorageEnums.LOCAL.name()); } report.setTriggerMode(initModel.getTriggerMode()); report.setReportVersion(2); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java index 4f46022433..e69e386e3c 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java @@ -10,6 +10,7 @@ import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.constants.ReportTypeConstants; import io.metersphere.commons.enums.ApiReportStatus; +import io.metersphere.commons.enums.StorageEnums; import io.metersphere.commons.utils.*; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.RequestResult; @@ -714,7 +715,7 @@ public class ApiScenarioReportStructureService { dto.setPoolName(resourcePool.getName()); } } else { - dto.setPoolName("LOCAL"); + dto.setPoolName(StorageEnums.LOCAL.name()); } if (runModeConfigDTO != null && StringUtils.isNotBlank(runModeConfigDTO.getMode())) { dto.setMode(runModeConfigDTO.getMode()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioRerunService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioRerunService.java index fc4841ce4c..2f97ec503d 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioRerunService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioRerunService.java @@ -19,6 +19,7 @@ import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ReportTypeConstants; import io.metersphere.commons.enums.ApiReportStatus; +import io.metersphere.commons.enums.StorageEnums; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.JSON; import io.metersphere.constants.RunModeConstants; @@ -111,7 +112,7 @@ public class ApiScenarioRerunService { config.setMode(RunModeConstants.PARALLEL.toString()); } config.setReportType(RunModeConstants.SET_REPORT.toString()); - if (!StringUtils.equalsAnyIgnoreCase(reportResults.get(0).getActuator(), "LOCAL")) { + if (!StringUtils.equalsAnyIgnoreCase(reportResults.get(0).getActuator(), StorageEnums.LOCAL.name())) { config.setResourcePoolId(reportResults.get(0).getActuator()); } request.setConfig(config); @@ -165,7 +166,7 @@ public class ApiScenarioRerunService { config.setMode(RunModeConstants.PARALLEL.toString()); } config.setReportName(reportDTO.getName()); - if (!StringUtils.equalsAnyIgnoreCase(reportDTO.getActuator(), "LOCAL")) { + if (!StringUtils.equalsAnyIgnoreCase(reportDTO.getActuator(), StorageEnums.LOCAL.name())) { config.setResourcePoolId(reportDTO.getActuator()); } config.setReportType(RunModeConstants.SET_REPORT.toString()); @@ -241,7 +242,7 @@ public class ApiScenarioRerunService { continue; } runModeConfig.setReportType(report.getReportType()); - if (!StringUtils.equalsAnyIgnoreCase(report.getActuator(), "LOCAL")) { + if (!StringUtils.equalsAnyIgnoreCase(report.getActuator(), StorageEnums.LOCAL.name())) { runModeConfig.setResourcePoolId(report.getActuator()); } executeQueue.put(testPlanApiCase.getId(), report); @@ -293,7 +294,7 @@ public class ApiScenarioRerunService { // 执行配置 RunModeConfigDTO config = new RunModeConfigDTO(); config.setMode(RunModeConstants.PARALLEL.toString()); - if (!StringUtils.equalsAnyIgnoreCase(reports.get(0).getActuator(), "LOCAL")) { + if (!StringUtils.equalsAnyIgnoreCase(reports.get(0).getActuator(), StorageEnums.LOCAL.name())) { config.setResourcePoolId(reports.get(0).getActuator()); } diff --git a/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue b/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue index 3219070e4b..dbdc11e582 100644 --- a/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue +++ b/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue @@ -10,7 +10,7 @@ - +