From 55822e7dc0eb9225c5212cfbe28b08fd9aa6d161 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 4 Jan 2023 15:23:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=94=A8=E4=BE=8B=E8=BF=87=E5=A4=9A=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/metersphere/metersphere/issues/20545 --- .../dto/automation/RunScenarioRequest.java | 20 +-- .../definition/BatchRunDefinitionRequest.java | 5 +- .../api/exec/api/ApiCaseExecuteService.java | 45 +++-- .../exec/scenario/ApiScenarioEnvService.java | 57 +++++-- .../scenario/ApiScenarioExecuteService.java | 159 +++++++++--------- .../api/parse/api/har/command/ViewHar.java | 74 -------- .../plan/ext/ExtTestPlanApiCaseMapper.java | 2 + .../plan/ext/ExtTestPlanApiCaseMapper.xml | 10 ++ .../ext/ExtTestPlanScenarioCaseMapper.java | 4 +- .../ext/ExtTestPlanScenarioCaseMapper.xml | 16 ++ .../commons/constants/CommonConstants.java | 2 +- .../utils/ApiDefinitionExecResultUtil.java | 4 +- .../commons/vo/RunPlanScenarioVO.java | 22 +++ .../plan/TestPlanScenarioCaseController.java | 5 - .../service/ApiExecutionQueueService.java | 4 +- .../plan/TestPlanScenarioCaseService.java | 75 +-------- .../scenario/ApiScenarioRerunService.java | 14 +- .../websocket/MsWebSocketClient.java | 8 +- .../autoconfigure/RestTemplateConfig.java | 2 +- .../mapper/ext/ExtTestPlanApiCaseMapper.java | 10 ++ .../mapper/ext/ExtTestPlanApiCaseMapper.xml | 12 ++ .../ext/ExtTestPlanScenarioCaseMapper.java | 9 + .../ext/ExtTestPlanScenarioCaseMapper.xml | 17 ++ .../plan/dto/BatchRunDefinitionRequest.java | 2 + .../plan/request/api/RunScenarioRequest.java | 2 + .../plan/service/TestPlanReportService.java | 91 +++++++++- .../plan/service/TestPlanService.java | 20 +-- .../remote/api/PlanApiAutomationService.java | 9 +- .../api/PlanTestPlanApiCaseService.java | 7 +- .../api/PlanTestPlanScenarioCaseService.java | 4 - 30 files changed, 385 insertions(+), 326 deletions(-) delete mode 100644 api-test/backend/src/main/java/io/metersphere/api/parse/api/har/command/ViewHar.java create mode 100644 api-test/backend/src/main/java/io/metersphere/commons/vo/RunPlanScenarioVO.java create mode 100644 test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java create mode 100644 test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml create mode 100644 test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java create mode 100644 test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java index 096abbdb07..62d7d602ae 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java @@ -1,5 +1,6 @@ package io.metersphere.api.dto.automation; +import io.metersphere.commons.vo.RunPlanScenarioVO; import io.metersphere.dto.RunModeConfigDTO; import lombok.Getter; import lombok.Setter; @@ -14,8 +15,6 @@ public class RunScenarioRequest { private String reportId; - private String environmentId; - private String projectId; private String triggerMode; @@ -24,25 +23,14 @@ public class RunScenarioRequest { private String runMode; - /** - * 测试情景和测试计划的关联ID - */ - private String planScenarioId; - - private List planCaseIds; - private List ids; private String reportUserID; - private Map scenarioTestPlanIdMap; - private ApiScenarioRequest condition; private RunModeConfigDTO config; - private boolean isTestPlanScheduleJob = false; - //生成测试报告:当isTestPlanScheduleJob为true时使用 private String testPlanReportId; @@ -53,6 +41,10 @@ public class RunScenarioRequest { private String serialReportId; private Map reportMap; - private String versionId; + private String testPlanId; + // 过程数据,整个测试计划执行 + private RunPlanScenarioVO processVO; + // 测试计划批量执行传入id + private List planScenarioIds; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java index 3a0537de53..83b2cd989e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java @@ -13,7 +13,7 @@ import java.util.Map; public class BatchRunDefinitionRequest { private String id; - private List planIds; + private List planCaseIds; private String triggerMode; @@ -27,6 +27,9 @@ public class BatchRunDefinitionRequest { private String planReportId; // 失败重跑 private boolean rerun; + + private String testPlanId; + private Map executeQueue; } 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 b2242c5879..c461889437 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 @@ -6,6 +6,7 @@ import io.metersphere.api.dto.EnvironmentType; import io.metersphere.api.dto.RunModeConfigWithEnvironmentDTO; import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.BatchRunDefinitionRequest; +import io.metersphere.api.dto.plan.TestPlanApiCaseInfoDTO; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.exec.queue.DBTestQueue; @@ -14,7 +15,7 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; -import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; +import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.exception.MSException; @@ -62,11 +63,11 @@ public class ApiCaseExecuteService { @Resource private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; @Resource - private TestPlanApiCaseMapper testPlanApiCaseMapper; - @Resource private JMeterService jMeterService; @Resource private BaseEnvironmentService baseEnvironmentService; + @Resource + private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; /** * 测试计划case执行 @@ -76,33 +77,34 @@ public class ApiCaseExecuteService { */ public List run(BatchRunDefinitionRequest request) { List responseDTOS = new LinkedList<>(); - if (CollectionUtils.isEmpty(request.getPlanIds())) { - return responseDTOS; - } if (request.getConfig() == null) { request.setConfig(new RunModeConfigDTO()); } - if (StringUtils.equals(EnvironmentType.GROUP.toString(), request.getConfig().getEnvironmentType()) && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { + if (StringUtils.equals(EnvironmentType.GROUP.name(), request.getConfig().getEnvironmentType()) + && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { request.getConfig().setEnvMap(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId())); } - LoggerUtil.info("开始查询测试计划用例", request.getPlanIds().size()); - - List planApiCases = this.selectByPlanApiCaseIds(request.getPlanIds()); + List planApiCases; + if (CollectionUtils.isNotEmpty(request.getPlanCaseIds())) { + planApiCases = extTestPlanApiCaseMapper.selectByPlanCaseIds(request.getPlanCaseIds()); + } else { + planApiCases = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(request.getTestPlanId()); + } if (CollectionUtils.isEmpty(planApiCases)) { return responseDTOS; } + LoggerUtil.info("查询到测试计划用例:" + planApiCases.size(), request.getPlanReportId()); + if (StringUtils.isEmpty(request.getTriggerMode())) { request.setTriggerMode(ApiRunMode.API_PLAN.name()); } - LoggerUtil.info("查询到测试计划用例 " + planApiCases.size()); - Map executeQueue = request.isRerun() ? request.getExecuteQueue() : new LinkedHashMap<>(); 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()); + List apiCaseIds = planApiCases.stream().map(TestPlanApiCaseInfoDTO::getApiCaseId).collect(Collectors.toList()); ApiTestCaseExample caseExample = new ApiTestCaseExample(); caseExample.createCriteria().andIdIn(apiCaseIds); List apiTestCases = apiTestCaseMapper.selectByExample(caseExample); @@ -113,7 +115,7 @@ public class ApiCaseExecuteService { resourcePoolId = request.getConfig().getResourcePoolId(); } if (!request.isRerun()) { - for (TestPlanApiCase testPlanApiCase : planApiCases) { + for (TestPlanApiCaseInfoDTO testPlanApiCase : planApiCases) { //处理环境配置为空时的情况 RunModeConfigDTO runModeConfigDTO = new RunModeConfigDTO(); BeanUtils.copyBean(runModeConfigDTO, request.getConfig()); @@ -134,7 +136,7 @@ public class ApiCaseExecuteService { apiCaseResultService.batchSave(executeQueue); } - LoggerUtil.info("开始生成测试计划队列"); + LoggerUtil.info("开始生成测试计划队列", request.getPlanReportId()); 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(); @@ -155,16 +157,6 @@ 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> getRequestEnv(List caseList) { Map> projectEnvMap = new HashMap<>(); if (CollectionUtils.isEmpty(caseList)) { @@ -247,7 +239,8 @@ public class ApiCaseExecuteService { } jMeterService.verifyPool(request.getProjectId(), request.getConfig()); - if (StringUtils.equals(EnvironmentType.GROUP.toString(), request.getConfig().getEnvironmentType()) && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { + if (StringUtils.equals(EnvironmentType.GROUP.name(), request.getConfig().getEnvironmentType()) + && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { request.getConfig().setEnvMap(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId())); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index 8b99d93d36..0ab6797e00 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -9,6 +9,7 @@ import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.MsScenario; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; +import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.environment.item.MsScenarioEnv; import io.metersphere.base.domain.*; @@ -254,7 +255,7 @@ public class ApiScenarioEnvService { return isEnv; } - public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) { + public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenarioInfoDTO testPlanApiScenarios) { if (apiScenarioWithBLOBs != null) { String definition = apiScenarioWithBLOBs.getScenarioDefinition(); MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class); @@ -285,7 +286,7 @@ public class ApiScenarioEnvService { */ public Map> checkEnv(RunScenarioRequest request, List apiScenarios) { Map> projectEnvMap = new HashMap<>(); - if (StringUtils.equals(request.getRequestOriginator(), "TEST_PLAN")) { + if (StringUtils.equals(request.getRequestOriginator(), CommonConstants.TEST_PLAN)) { this.checkPlanScenarioEnv(request); } else if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equalsAny(request.getRunMode(), ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { StringBuilder builder = new StringBuilder(); @@ -301,7 +302,7 @@ public class ApiScenarioEnvService { } } if (builder.length() > 0) { - MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); + MSException.throwException("场景:" + builder + "运行环境未配置,请检查!"); } } else if (StringUtils.equals(request.getRunMode(), ApiRunMode.SCHEDULE_SCENARIO.name())) { for (ApiScenarioWithBLOBs apiScenarioWithBLOBs : apiScenarios) { @@ -317,24 +318,23 @@ public class ApiScenarioEnvService { public void checkPlanScenarioEnv(RunScenarioRequest request) { StringBuilder builder = new StringBuilder(); - List planCaseIds = request.getPlanCaseIds(); - if (CollectionUtils.isNotEmpty(planCaseIds)) { - TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); - example.createCriteria().andIdIn(planCaseIds); - List testPlanApiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(example); - for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) { + if (request.getProcessVO() != null && + MapUtils.isNotEmpty(request.getProcessVO().getTestPlanScenarioMap()) + && MapUtils.isNotEmpty(request.getProcessVO().getTestPlanScenarioMap())) { + for (String key : request.getProcessVO().getTestPlanScenarioMap().keySet()) { try { - ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId()); - boolean haveEnv = this.verifyPlanScenarioEnv(apiScenarioWithBLOBs, testPlanApiScenario); + TestPlanApiScenarioInfoDTO dto = request.getProcessVO().getTestPlanScenarioMap().get(key); + ApiScenarioWithBLOBs apiScenarioWithBLOBs = request.getProcessVO().getScenarioMap().get(dto.getApiScenarioId()); + boolean haveEnv = this.verifyPlanScenarioEnv(apiScenarioWithBLOBs, dto); if (!haveEnv) { builder.append(apiScenarioWithBLOBs.getName()).append("; "); } } catch (Exception e) { - MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); + MSException.throwException("场景:" + builder + "运行环境未配置,请检查!"); } } if (builder.length() > 0) { - MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); + MSException.throwException("场景:" + builder + "运行环境未配置,请检查!"); } } } @@ -522,7 +522,8 @@ public class ApiScenarioEnvService { JSONObject jsonObject = JSONUtil.parseObject(envConfig); if (jsonObject.has("executionEnvironmentMap")) { RunModeConfigWithEnvironmentDTO configWithEnvironment = JSON.parseObject(envConfig, RunModeConfigWithEnvironmentDTO.class); - if (StringUtils.equals("GROUP", configWithEnvironment.getEnvironmentType()) && StringUtils.isNotEmpty(configWithEnvironment.getEnvironmentGroupId())) { + if (StringUtils.equals(EnvironmentType.GROUP.name(), configWithEnvironment.getEnvironmentType()) + && StringUtils.isNotEmpty(configWithEnvironment.getEnvironmentGroupId())) { groupId = configWithEnvironment.getEnvironmentGroupId(); } if (MapUtils.isNotEmpty(configWithEnvironment.getExecutionEnvironmentMap())) { @@ -532,7 +533,8 @@ public class ApiScenarioEnvService { } } else { RunModeConfigDTO config = JSON.parseObject(envConfig, RunModeConfigDTO.class); - if (StringUtils.equals("GROUP", config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) { + if (StringUtils.equals(EnvironmentType.GROUP.name(), config.getEnvironmentType()) + && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) { groupId = config.getEnvironmentGroupId(); } envMapByRunConfig = config.getEnvMap(); @@ -576,4 +578,29 @@ public class ApiScenarioEnvService { return project.getName(); } } + + public void setScenarioEnv(RunScenarioRequest request, Map configEnvMap) { + if (StringUtils.equals(request.getConfig().getEnvironmentType(), EnvironmentType.JSON.toString()) + && MapUtils.isNotEmpty(request.getConfig().getEnvMap())) { + configEnvMap.putAll(request.getConfig().getEnvMap()); + } else if (StringUtils.equals(request.getConfig().getEnvironmentType(), EnvironmentType.GROUP.toString()) + && StringUtils.isNotBlank(request.getConfig().getEnvironmentGroupId())) { + configEnvMap.putAll(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId())); + } + } + + public Map getPlanScenarioEnv(TestPlanApiScenarioInfoDTO planApiScenario, Map configEnvMap) { + Map planEnvMap = new LinkedHashMap<>(); + if (StringUtils.equals(planApiScenario.getEnvironmentType(), EnvironmentType.JSON.toString()) + && StringUtils.isNotBlank(planApiScenario.getEnvironment())) { + planEnvMap.putAll(JSON.parseObject(planApiScenario.getEnvironment(), Map.class)); + } else if (StringUtils.equals(planApiScenario.getEnvironmentType(), EnvironmentType.GROUP.toString()) + && StringUtils.isNotBlank(planApiScenario.getEnvironmentGroupId())) { + planEnvMap.putAll(environmentGroupProjectService.getEnvMap(planApiScenario.getEnvironmentGroupId())); + } + if (MapUtils.isNotEmpty(configEnvMap)) { + planEnvMap.putAll(configEnvMap); + } + return planEnvMap; + } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 1c31a09855..9c65f8e055 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -8,15 +8,18 @@ import io.metersphere.api.dto.automation.ExecuteType; import io.metersphere.api.dto.automation.RunScenarioRequest; import io.metersphere.api.dto.definition.RunDefinitionRequest; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.api.exec.api.ApiCaseExecuteService; import io.metersphere.api.exec.queue.DBTestQueue; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.jmeter.NewDriverManager; -import io.metersphere.base.domain.*; +import io.metersphere.base.domain.ApiScenario; +import io.metersphere.base.domain.ApiScenarioExample; +import io.metersphere.base.domain.ApiScenarioReportWithBLOBs; +import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; -import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ExtendedParameter; @@ -24,6 +27,7 @@ import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; +import io.metersphere.commons.vo.RunPlanScenarioVO; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.JmeterRunRequestDTO; @@ -85,8 +89,6 @@ public class ApiScenarioExecuteService { @Resource protected JMeterService jMeterService; @Resource - protected TestPlanApiScenarioMapper testPlanApiScenarioMapper; - @Resource private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; @Resource private SystemParameterService systemParameterService; @@ -102,7 +104,8 @@ public class ApiScenarioExecuteService { request.setConfig(new RunModeConfigDTO()); } - if (StringUtils.equals("GROUP", request.getConfig().getEnvironmentType()) && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { + if (StringUtils.equals(EnvironmentType.GROUP.name(), request.getConfig().getEnvironmentType()) + && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) { request.getConfig().setEnvMap(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId())); } @@ -131,9 +134,10 @@ public class ApiScenarioExecuteService { Map executeQueue = new LinkedHashMap<>(); LoggerUtil.info("Scenario run-执行脚本装载-初始化执行队列"); - if (StringUtils.equalsAny(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { + if (StringUtils.equalsAny(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name(), + ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { //测试计划执行 - assemblyPlanScenario(apiScenarios, request, executeQueue); + assemblyPlanScenario(request, executeQueue); } else { // 按照场景执行 assemblyScenario(apiScenarios, request, executeQueue); @@ -141,47 +145,19 @@ public class ApiScenarioExecuteService { LoggerUtil.info("Scenario run-执行脚本装载-初始化执行队列完成:" + executeQueue.size()); List responseDTOS = new LinkedList<>(); - if (executeQueue.isEmpty()) { + if (MapUtils.isEmpty(executeQueue)) { return responseDTOS; } // 集合报告处理 if (GenerateHashTreeUtil.isSetReport(request.getConfig())) { - // 失败重跑更新报告状态 - if (request.isRerun()) { - ApiScenarioReportWithBLOBs report = new ApiScenarioReportWithBLOBs(); - report.setId(serialReportId); - report.setStatus(ApiReportStatus.RERUNNING.name()); - apiScenarioReportMapper.updateByPrimaryKeySelective(report); - } else { - LoggerUtil.info("Scenario run-执行脚本装载-初始化集成报告:" + serialReportId); - request.getConfig().setReportId(UUID.randomUUID().toString()); - List scenarioIds = new ArrayList<>(); - String reportScenarioIds = generateScenarioIds(scenarioIds); - if (request.getConfig() == null) { - request.setConfig(new RunModeConfigWithEnvironmentDTO()); - } - if (MapUtils.isEmpty(request.getConfig().getEnvMap())) { - RunModeConfigWithEnvironmentDTO runModeConfig = new RunModeConfigWithEnvironmentDTO(); - BeanUtils.copyBean(runModeConfig, request.getConfig()); - Map> projectEnvMap = apiScenarioEnvService.selectApiScenarioEnv(apiScenarios); - apiCaseExecuteService.setExecutionEnvironment(runModeConfig, projectEnvMap); - request.setConfig(runModeConfig); - } - // 生成集合报告 - String names = apiScenarios.stream().map(ApiScenario::getName).collect(Collectors.joining(",")); - ApiScenarioReportResult report = apiScenarioReportService.getApiScenarioReportResult(request, serialReportId, names, reportScenarioIds); - report.setVersionId(apiScenarios.get(0).getVersionId()); - apiScenarioReportMapper.insert(report); - - responseDTOS.add(new MsExecResponseDTO(JSON.toJSONString(scenarioIds), serialReportId, request.getRunMode())); - apiScenarioReportStructureService.save(apiScenarios, serialReportId, request.getConfig().getReportType()); - } + this.setReport(request, serialReportId, apiScenarios, responseDTOS); } String reportType = request.getConfig().getReportType(); String planReportId = StringUtils.isNotEmpty(request.getTestPlanReportId()) ? request.getTestPlanReportId() : serialReportId; // 生成执行队列 - DBTestQueue executionQueue = apiExecutionQueueService.add(executeQueue, request.getConfig().getResourcePoolId(), ApiRunMode.SCENARIO.name(), planReportId, reportType, request.getRunMode(), request.getConfig()); + DBTestQueue executionQueue = apiExecutionQueueService.add( + executeQueue, request.getConfig().getResourcePoolId(), ApiRunMode.SCENARIO.name(), planReportId, reportType, request.getRunMode(), request.getConfig()); // 预生成报告 if (!request.isRerun() && !GenerateHashTreeUtil.isSetReport(request.getConfig())) { @@ -215,7 +191,25 @@ public class ApiScenarioExecuteService { } public List get(RunScenarioRequest request) { - ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); + RunPlanScenarioVO vo = new RunPlanScenarioVO(); + if (StringUtils.equalsAny(request.getRunMode(), + ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { + // 测试计划执行数据查询 + List testPlanApiScenarioList; + if (CollectionUtils.isNotEmpty(request.getPlanScenarioIds())) { + testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectByPlanIds(request.getPlanScenarioIds()); + } else { + testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(request.getTestPlanId()); + } + if (CollectionUtils.isNotEmpty(testPlanApiScenarioList)) { + List ids = testPlanApiScenarioList.stream().map(TestPlanApiScenarioInfoDTO::getApiScenarioId).collect(Collectors.toList()); + request.setIds(ids); + vo.setTestPlanScenarioMap(testPlanApiScenarioList.stream() + .collect(Collectors.toMap(TestPlanApiScenarioInfoDTO::getId, Function.identity(), (t1, t2) -> t1))); + } + } else { + ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); + } List ids = request.getIds(); ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(ids); @@ -226,9 +220,44 @@ public class ApiScenarioExecuteService { sortById(ids, apiScenarios); } } + vo.setScenarioMap(apiScenarios.stream().collect(Collectors.toMap(ApiScenarioWithBLOBs::getId, Function.identity(), (t1, t2) -> t1))); + request.setProcessVO(vo); return apiScenarios; } + private void setReport(RunScenarioRequest request, String serialReportId, List apiScenarios, List responseDTOS) { + // 失败重跑更新报告状态 + if (request.isRerun()) { + ApiScenarioReportWithBLOBs report = new ApiScenarioReportWithBLOBs(); + report.setId(serialReportId); + report.setStatus(ApiReportStatus.RERUNNING.name()); + apiScenarioReportMapper.updateByPrimaryKeySelective(report); + } else { + LoggerUtil.info("Scenario run-执行脚本装载-初始化集成报告:" + serialReportId); + request.getConfig().setReportId(UUID.randomUUID().toString()); + List scenarioIds = new ArrayList<>(); + String reportScenarioIds = generateScenarioIds(scenarioIds); + if (request.getConfig() == null) { + request.setConfig(new RunModeConfigWithEnvironmentDTO()); + } + if (MapUtils.isEmpty(request.getConfig().getEnvMap())) { + RunModeConfigWithEnvironmentDTO runModeConfig = new RunModeConfigWithEnvironmentDTO(); + BeanUtils.copyBean(runModeConfig, request.getConfig()); + Map> projectEnvMap = apiScenarioEnvService.selectApiScenarioEnv(apiScenarios); + apiCaseExecuteService.setExecutionEnvironment(runModeConfig, projectEnvMap); + request.setConfig(runModeConfig); + } + // 生成集合报告 + String names = apiScenarios.stream().map(ApiScenario::getName).collect(Collectors.joining(",")); + ApiScenarioReportResult report = apiScenarioReportService.getApiScenarioReportResult(request, serialReportId, names, reportScenarioIds); + report.setVersionId(apiScenarios.get(0).getVersionId()); + apiScenarioReportMapper.insert(report); + + responseDTOS.add(new MsExecResponseDTO(JSON.toJSONString(scenarioIds), serialReportId, request.getRunMode())); + apiScenarioReportStructureService.save(apiScenarios, serialReportId, request.getConfig().getReportType()); + } + } + protected void sortById(List ids, List apiScenarios) { FixedOrderComparator fixedOrderComparator = new FixedOrderComparator(ids); fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE); @@ -236,30 +265,20 @@ public class ApiScenarioExecuteService { Collections.sort(apiScenarios, beanComparator); } - /** * 测试计划接口场景的预执行(生成场景报告) */ - private void assemblyPlanScenario(List apiScenarios, RunScenarioRequest request, Map executeQueue) { + private void assemblyPlanScenario(RunScenarioRequest request, Map executeQueue) { String reportId = request.getId(); - Map planScenarioIdMap = request.getScenarioTestPlanIdMap(); - if (MapUtils.isEmpty(planScenarioIdMap)) { - return; - } - Map scenarioMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenarioWithBLOBs::getId, Function.identity(), (t1, t2) -> t1)); + Map scenarioMap = request.getProcessVO().getScenarioMap(); //检查环境组 Map configEnvMap = new HashMap<>(); if (request.getConfig() != null) { - if (StringUtils.equals(request.getConfig().getEnvironmentType(), EnvironmentType.JSON.toString()) && MapUtils.isNotEmpty(request.getConfig().getEnvMap())) { - configEnvMap = request.getConfig().getEnvMap(); - } else if (StringUtils.equals(request.getConfig().getEnvironmentType(), EnvironmentType.GROUP.toString()) && StringUtils.isNotBlank(request.getConfig().getEnvironmentGroupId())) { - configEnvMap = environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId()); - } + apiScenarioEnvService.setScenarioEnv(request, configEnvMap); } - - for (String testPlanScenarioId : planScenarioIdMap.keySet()) { - String scenarioId = planScenarioIdMap.get(testPlanScenarioId); - ApiScenarioWithBLOBs scenario = scenarioMap.get(scenarioId); + for (String testPlanScenarioId : request.getProcessVO().getTestPlanScenarioMap().keySet()) { + TestPlanApiScenarioInfoDTO planApiScenario = request.getProcessVO().getTestPlanScenarioMap().get(testPlanScenarioId); + ApiScenarioWithBLOBs scenario = scenarioMap.get(planApiScenario.getApiScenarioId()); if (scenario.getStepTotal() == null || scenario.getStepTotal() == 0) { continue; } @@ -267,39 +286,30 @@ public class ApiScenarioExecuteService { request.setProjectId(scenario.getProjectId()); } // 获取场景用例单独的执行环境 - Map planEnvMap = new HashMap<>(); - TestPlanApiScenario planApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testPlanScenarioId); - if (planApiScenario == null) { - continue; - } - // 环境处理 - if (StringUtils.equals(planApiScenario.getEnvironmentType(), EnvironmentType.JSON.toString()) && StringUtils.isNotBlank(planApiScenario.getEnvironment())) { - planEnvMap = JSON.parseObject(planApiScenario.getEnvironment(), Map.class); - } else if (StringUtils.equals(planApiScenario.getEnvironmentType(), EnvironmentType.GROUP.toString()) && StringUtils.isNotBlank(planApiScenario.getEnvironmentGroupId())) { - planEnvMap = environmentGroupProjectService.getEnvMap(planApiScenario.getEnvironmentGroupId()); - } - planEnvMap.putAll(configEnvMap); - + Map planEnvMap = apiScenarioEnvService.getPlanScenarioEnv(planApiScenario, configEnvMap); if (StringUtils.isEmpty(request.getProjectId())) { request.setProjectId(extTestPlanScenarioCaseMapper.getProjectIdById(testPlanScenarioId)); } + ApiScenarioReportResult report = apiScenarioReportService.initResult(reportId, testPlanScenarioId, scenario.getName(), request); if (request.isRerun()) { - if (request.getReportMap().containsKey(scenarioId)) { - report = request.getReportMap().get(scenarioId); + if (request.getReportMap().containsKey(planApiScenario.getApiScenarioId())) { + report = request.getReportMap().get(planApiScenario.getApiScenarioId()); } else if (request.getReportMap().containsKey(testPlanScenarioId)) { report = request.getReportMap().get(testPlanScenarioId); } + if (report == null) { + return; + } } - if (report == null) { - return; - } + report.setVersionId(scenario.getVersionId()); RunModeDataDTO runModeDataDTO = getRunModeDataDTO(testPlanScenarioId, report); runModeDataDTO.setPlanEnvMap(planEnvMap); runModeDataDTO.setScenario(scenario); executeQueue.put(report.getId(), runModeDataDTO); + if (ObjectUtils.isNotEmpty(request.getConfig())) { RunModeConfigWithEnvironmentDTO runModeConfig = new RunModeConfigWithEnvironmentDTO(); BeanUtils.copyBean(runModeConfig, request.getConfig()); @@ -311,7 +321,6 @@ public class ApiScenarioExecuteService { Map envMap = runModeConfig.getEnvMap(); planEnvMap.forEach((k, v) -> { if (envMap != null && envMap.get(k) != null) { - diffEnvMap.put(k, envMap.get(k)); } }); diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/command/ViewHar.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/command/ViewHar.java deleted file mode 100644 index 9768c8b5fa..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/command/ViewHar.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.metersphere.api.parse.api.har.command;///** -// * -// * har - HAR file reader, writer and viewer -// * Copyright (c) 2014, Sandeep Gupta -// * -// * http://sangupta.com/projects/har -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// * -// */ -// -//package io.metersphere.api.dto.parse.api.har.command; -// -//import java.io.File; -// -//import com.sangupta.har.HarUtils; -//import com.sangupta.har.model.Har; -//import com.sangupta.har.model.HarEntry; -//import com.sangupta.har.model.HarPage; -//import com.sangupta.jerry.util.AssertUtils; -// -//import io.airlift.command.Arguments; -//import io.airlift.command.Command; -// -//@Command(name = "view", description = "View HAR file") -//public class ViewHar implements Runnable { -// -// @Arguments -// private String file; -// -// @Override -// public void run() { -// Har har = null; -// -// try { -// har = HarUtils.read(new File(this.file)); -// } catch(Exception e) { -// System.out.println("Error reading HAR file: " + e.getMessage()); -// return; -// } -// -// if(har.log == null || AssertUtils.isEmpty(har.log.pages)) { -// System.out.println("HAR file has no pages!"); -// return; -// } -// -// // connect references -// HarUtils.connectReferences(har); -// -// // start displaying -// System.out.println("Number of pages viewed: " + har.log.pages.size()); -// System.out.println(); -// -// for(HarPage page : har.log.pages) { -// System.out.println(page); -// -// // output the calls for this page -// for(HarEntry entry : page.entries) { -// System.out.println("\t" + entry); -// } -// } -// } -// -//} diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java index 41d5ee20bc..228f9f83b2 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java @@ -35,6 +35,8 @@ public interface ExtTestPlanApiCaseMapper { List selectLegalDataByTestPlanId(String planId); + List selectByPlanCaseIds(List planCaseIds); + List selectForPlanReport(String planId); List getFailureList(@Param("planId") String planId, @Param("status") String status); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml index 56e7b5b32b..6104f1c2a3 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml @@ -544,4 +544,14 @@ #{v} + + diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java index 85706cdec2..d6aaa24304 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java @@ -1,12 +1,10 @@ package io.metersphere.base.mapper.plan.ext; -import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO; import io.metersphere.api.dto.automation.TestPlanScenarioRequest; import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.base.domain.TestPlanApiScenario; - import io.metersphere.dto.PlanReportCaseDTO; import org.apache.ibatis.annotations.Param; @@ -30,6 +28,8 @@ public interface ExtTestPlanScenarioCaseMapper { List selectLegalDataByTestPlanId(String planId); + List selectByPlanIds(List planScenarioIds); + List selectForPlanReport(String planId); List getFailureList(@Param("planId") String planId, @Param("status") String status); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.xml index ab1e0c5dc4..70ccfe9627 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.xml @@ -401,4 +401,20 @@ SELECT test_plan_id FROM test_plan_api_scenario WHERE id = #{0} ) + + diff --git a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java index 40e10c3441..e928995013 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java @@ -2,7 +2,7 @@ package io.metersphere.commons.constants; public class CommonConstants { public static final String TrashStatus = "Trash"; - public static final String PROJECT_TEMPLATE = "PROJECT_TEMPLATE"; + public static final String TEST_PLAN = "TEST_PLAN"; public static final String LOCAL_STATUS_KEY = "LOCAL_STATUS_KEY"; public static final String REPORT_STATUS = "REPORT_STATUS"; public static final String TRIGGER_MODE = "trigger_mode"; 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 826dd2cc82..a6187f047b 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 @@ -2,9 +2,9 @@ package io.metersphere.commons.utils; import io.metersphere.api.dto.definition.BatchRunDefinitionRequest; +import io.metersphere.api.dto.plan.TestPlanApiCaseInfoDTO; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; import io.metersphere.base.domain.ApiTestCase; -import io.metersphere.base.domain.TestPlanApiCase; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ReportTypeConstants; import io.metersphere.commons.constants.TriggerMode; @@ -45,7 +45,7 @@ public class ApiDefinitionExecResultUtil { public static ApiDefinitionExecResultWithBLOBs addResult( BatchRunDefinitionRequest request, RunModeConfigDTO runModeConfigDTO, - TestPlanApiCase key, + TestPlanApiCaseInfoDTO key, String status, ApiTestCase testCase, String poolId) { diff --git a/api-test/backend/src/main/java/io/metersphere/commons/vo/RunPlanScenarioVO.java b/api-test/backend/src/main/java/io/metersphere/commons/vo/RunPlanScenarioVO.java new file mode 100644 index 0000000000..b58dcb8f40 --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/commons/vo/RunPlanScenarioVO.java @@ -0,0 +1,22 @@ +package io.metersphere.commons.vo; + +import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; +import io.metersphere.base.domain.ApiScenarioWithBLOBs; +import lombok.Getter; +import lombok.Setter; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Setter +@Getter +public class RunPlanScenarioVO { + private Map testPlanScenarioMap; + + private Map scenarioMap; + + public RunPlanScenarioVO() { + this.testPlanScenarioMap = new LinkedHashMap<>(); + this.scenarioMap = new LinkedHashMap<>(); + } +} diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java index e0f79c2568..4dcb81f01d 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java @@ -190,11 +190,6 @@ public class TestPlanScenarioCaseController { return testPlanScenarioCaseService.buildExecuteApiReport(request); } - @PostMapping("/plan/report/schedule/info/{planId}") - public TestPlanApiReportInfoDTO genApiReportInfoForSchedule(@PathVariable("planId") String planId, @RequestBody RunModeConfigDTO runModeConfigDTO) { - return testPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO); - } - @GetMapping("/is/executing/{planId}") public Boolean isExecuting(@PathVariable("planId") String planId) { return testPlanScenarioCaseService.isExecuting(planId); diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java index e292652d53..c52bfeb067 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java @@ -69,7 +69,7 @@ public class ApiExecutionQueueService { @Transactional(propagation = Propagation.REQUIRES_NEW) public DBTestQueue add(Object runObj, String poolId, String type, String reportId, String reportType, String runMode, RunModeConfigDTO config) { - LoggerUtil.info("报告【" + reportId + "】开始生成执行链"); + LoggerUtil.info("报告【" + type + "】开始生成执行链", reportId); if (config.getEnvMap() == null) { config.setEnvMap(new LinkedHashMap<>()); } @@ -99,7 +99,7 @@ public class ApiExecutionQueueService { extApiExecutionQueueMapper.sqlInsert(queueDetails); } resQueue.setDetailMap(detailMap); - LoggerUtil.info("报告【" + reportId + "】生成执行链结束"); + LoggerUtil.info("报告【" + type + "】生成执行链结束", reportId); return resQueue; } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index 17b5cf8575..d0d387acc0 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -16,7 +16,6 @@ import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; -import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.ApiRunMode; @@ -29,7 +28,6 @@ import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.dto.PlanReportCaseDTO; import io.metersphere.dto.ProjectConfig; import io.metersphere.dto.RunModeConfigDTO; -import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; import io.metersphere.log.vo.OperatingLogDetails; @@ -70,8 +68,6 @@ public class TestPlanScenarioCaseService { @Resource ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; @Resource - ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; - @Resource ExtTestPlanApiScenarioMapper extTestPlanApiScenarioMapper; @Resource ApiScenarioReportService apiScenarioReportService; @@ -94,8 +90,6 @@ public class TestPlanScenarioCaseService { @Resource private ApiDefinitionExecResultService apiDefinitionExecResultService; @Resource - private BaseEnvGroupProjectService environmentGroupProjectService; - @Resource private BaseEnvironmentService apiTestEnvironmentService; @Resource private ExtApiScenarioModuleMapper extApiScenarioModuleMapper; @@ -293,14 +287,13 @@ public class TestPlanScenarioCaseService { RunScenarioRequest request = new RunScenarioRequest(); request.setIds(scenarioIds); request.setReportId(testPlanScenarioRequest.getId()); - request.setScenarioTestPlanIdMap(scenarioPlanIdMap); request.setRunMode(ApiRunMode.SCENARIO_PLAN.name()); request.setId(testPlanScenarioRequest.getId()); request.setExecuteType(ExecuteType.Saved.name()); request.setTriggerMode(testPlanScenarioRequest.getTriggerMode()); request.setConfig(testPlanScenarioRequest.getConfig()); - request.setPlanCaseIds(planCaseIdList); - request.setRequestOriginator("TEST_PLAN"); + request.setPlanScenarioIds(planCaseIdList); + request.setRequestOriginator(CommonConstants.TEST_PLAN); return apiAutomationService.run(request); } @@ -1009,70 +1002,6 @@ public class TestPlanScenarioCaseService { return testPlanApiCaseService.buildCases(apiTestCases); } - public TestPlanApiReportInfoDTO genApiReportInfoForSchedule(String planId, RunModeConfigDTO runModeConfigDTO) { - TestPlanApiReportInfoDTO testPlanApiReportInfo = new TestPlanApiReportInfoDTO(); - Map planApiCaseIdMap = new LinkedHashMap<>(); - Map planScenarioIdMap = new LinkedHashMap<>(); - - List testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId); - for (TestPlanApiScenarioInfoDTO model : testPlanApiScenarioList) { - planScenarioIdMap.put(model.getId(), model.getApiScenarioId()); - } - List testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(planId); - for (TestPlanApiCaseInfoDTO model : testPlanApiCaseList) { - planApiCaseIdMap.put(model.getId(), model.getApiCaseId()); - } - - testPlanApiReportInfo.setPlanApiCaseIdMap(planApiCaseIdMap); - testPlanApiReportInfo.setPlanScenarioIdMap(planScenarioIdMap); - //解析运行环境信息 - TestPlanReportRunInfoDTO runInfoDTO = this.parseTestPlanRunInfo(runModeConfigDTO, testPlanApiCaseList, testPlanApiScenarioList); - testPlanApiReportInfo.setRunInfoDTO(runInfoDTO); - return testPlanApiReportInfo; - } - - public TestPlanReportRunInfoDTO parseTestPlanRunInfo(RunModeConfigDTO runModeConfigDTO, List testPlanApiCaseList, List testPlanApiScenarioList) { - TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); - Map selectEnvMap = runModeConfigDTO.getEnvMap(); - runInfoDTO.setRunMode(runModeConfigDTO.getMode()); - if (StringUtils.equals("GROUP", runModeConfigDTO.getEnvironmentType()) && StringUtils.isNotEmpty(runModeConfigDTO.getEnvironmentGroupId())) { - selectEnvMap = environmentGroupProjectService.getEnvMap(runModeConfigDTO.getEnvironmentGroupId()); - runInfoDTO.setEnvGroupId(runModeConfigDTO.getEnvironmentGroupId()); - } - - for (TestPlanApiScenarioInfoDTO model : testPlanApiScenarioList) { - Map envMap = null; - if (StringUtils.equalsIgnoreCase("group", model.getEnvironmentType()) && StringUtils.isNotEmpty(model.getEnvironmentGroupId())) { - envMap = environmentGroupProjectService.getEnvMap(model.getEnvironmentGroupId()); - } else { - if (MapUtils.isNotEmpty(selectEnvMap) && selectEnvMap.containsKey(model.getProjectId())) { - runInfoDTO.putScenarioRunInfo(model.getId(), model.getProjectId(), selectEnvMap.get(model.getProjectId())); - } else if (StringUtils.isNotEmpty(model.getEnvironment())) { - try { - envMap = JSON.parseObject(model.getEnvironment(), Map.class); - } catch (Exception e) { - LogUtil.error("解析场景环境失败!", e); - } - } - } - if (MapUtils.isNotEmpty(envMap)) { - for (Map.Entry entry : envMap.entrySet()) { - String projectId = entry.getKey(); - String envIdStr = entry.getValue(); - runInfoDTO.putScenarioRunInfo(model.getId(), projectId, envIdStr); - } - } - } - for (TestPlanApiCaseInfoDTO model : testPlanApiCaseList) { - if (MapUtils.isNotEmpty(selectEnvMap) && selectEnvMap.containsKey(model.getProjectId())) { - runInfoDTO.putApiCaseRunInfo(model.getId(), model.getProjectId(), selectEnvMap.get(model.getProjectId())); - } else { - runInfoDTO.putApiCaseRunInfo(model.getId(), model.getProjectId(), model.getEnvironmentId()); - } - } - return runInfoDTO; - } - public Boolean isExecuting(String planId) { List testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId); return !testPlanApiScenarioList.stream() 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 2f97ec503d..4e1306b354 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 @@ -16,6 +16,7 @@ import io.metersphere.base.mapper.ext.ExtApiScenarioReportResultMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiScenarioMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ReportTypeConstants; import io.metersphere.commons.enums.ApiReportStatus; @@ -228,7 +229,7 @@ public class ApiScenarioRerunService { BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); request.setTriggerMode(testPlanReport.getTriggerMode()); request.setRerun(true); - request.setPlanIds(ids); + request.setPlanCaseIds(ids); request.setPlanReportId(parametersDTO.getReportId()); request.setUserId(parametersDTO.getCases().get(0).getUserId()); @@ -271,9 +272,7 @@ public class ApiScenarioRerunService { } List scenarioIds = apiScenarios.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList()); LoggerUtil.info("重跑测试计划报告:【" + parametersDTO.getReportId() + "】,对应重跑场景资源:" + scenarioIds.size()); - - Map scenarioTestPlanIdMap = apiScenarios.stream().collect(Collectors.toMap(TestPlanApiScenario::getId, a -> a.getApiScenarioId(), (k1, k2) -> k1)); - + List planScenarioIds = apiScenarios.stream().map(TestPlanApiScenario::getId).collect(Collectors.toList()); // 查出原始报告 List reportIds = apiScenarios.stream().map(TestPlanApiScenario::getReportId).collect(Collectors.toList()); if (com.alibaba.nacos.common.utils.CollectionUtils.isEmpty(reportIds)) { @@ -282,7 +281,7 @@ public class ApiScenarioRerunService { ApiScenarioReportExample reportExample = new ApiScenarioReportExample(); reportExample.createCriteria().andIdIn(reportIds); List reports = apiScenarioReportMapper.selectByExample(reportExample); - if (com.alibaba.nacos.common.utils.CollectionUtils.isEmpty(reports)) { + if (CollectionUtils.isEmpty(reports)) { return isStart; } // config @@ -312,7 +311,8 @@ public class ApiScenarioRerunService { request.setExecuteType(ExecuteType.Completed.name()); request.setRunMode(ApiRunMode.SCENARIO_PLAN.name()); request.setIds(scenarioIds); // 场景IDS - request.setScenarioTestPlanIdMap(scenarioTestPlanIdMap);//场景id和计划场景id映射关系 + request.setPlanScenarioIds(planScenarioIds); + // 一批执行的报告配置都是相同的 ApiScenarioReportWithBLOBs scenario = apiScenarioReportMapper.selectByPrimaryKey(reportIds.get(0)); if (scenario != null && StringUtils.isNotEmpty(scenario.getEnvConfig())) { @@ -322,7 +322,7 @@ public class ApiScenarioRerunService { } request.setTestPlanReportId(parametersDTO.getReportId()); request.setId(UUID.randomUUID().toString()); - request.setRequestOriginator("TEST_PLAN"); + request.setRequestOriginator(CommonConstants.TEST_PLAN); LoggerUtil.info("清理原始报告对应结果:【" + request.getTestPlanReportId() + "】," + reportIds.size()); ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); diff --git a/api-test/backend/src/main/java/io/metersphere/websocket/MsWebSocketClient.java b/api-test/backend/src/main/java/io/metersphere/websocket/MsWebSocketClient.java index 71a96e9dcd..b2f25adc55 100644 --- a/api-test/backend/src/main/java/io/metersphere/websocket/MsWebSocketClient.java +++ b/api-test/backend/src/main/java/io/metersphere/websocket/MsWebSocketClient.java @@ -18,22 +18,22 @@ public class MsWebSocketClient extends WebSocketClient { LogUtil.info("握手..."); for (Iterator it = shake.iterateHttpFields(); it.hasNext(); ) { String key = it.next(); - System.out.println(key + ":" + shake.getFieldValue(key)); + LogUtil.info(key + ":" + shake.getFieldValue(key)); } } @Override public void onMessage(String paramString) { - System.out.println("接收到消息:" + paramString); + LogUtil.info("接收到消息:" + paramString); } @Override public void onClose(int paramInt, String paramString, boolean paramBoolean) { - System.out.println("关闭..."); + LogUtil.info("关闭..."); } @Override public void onError(Exception e) { - System.out.println("异常" + e); + LogUtil.info("异常" + e); } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java index 5c36949df1..c94d85d5ff 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java @@ -35,7 +35,7 @@ public class RestTemplateConfig implements WebMvcConfigurer { private final static int MAX_PER_ROUTE = 500; private final static int CONN_REQUEST_TIMEOUT = 5000; private final static int CONNECT_TIMEOUT = 8000; - private final static int SOCKET_TIMEOUT = 20 * 1000; + private final static int SOCKET_TIMEOUT = 200 * 1000; @Bean public RestTemplate restTemplate() { diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java new file mode 100644 index 0000000000..519f5c301e --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.plan.dto.TestPlanApiCaseInfoDTO; + +import java.util.List; + +public interface ExtTestPlanApiCaseMapper { + List selectLegalDataByTestPlanId(String planId); +} + diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml new file mode 100644 index 0000000000..41cd507124 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java new file mode 100644 index 0000000000..f74c7aede8 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java @@ -0,0 +1,9 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.plan.dto.TestPlanApiScenarioInfoDTO; + +import java.util.List; + +public interface ExtTestPlanScenarioCaseMapper { + List selectLegalDataByTestPlanId(String planId); + } diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml new file mode 100644 index 0000000000..42e2488beb --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/BatchRunDefinitionRequest.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/BatchRunDefinitionRequest.java index aa496c7d52..f9d6afce24 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/BatchRunDefinitionRequest.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/BatchRunDefinitionRequest.java @@ -25,6 +25,8 @@ public class BatchRunDefinitionRequest { private String planReportId; // 失败重跑 private boolean rerun; + private Map executeQueue; + private String testPlanId; } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/request/api/RunScenarioRequest.java b/test-track/backend/src/main/java/io/metersphere/plan/request/api/RunScenarioRequest.java index ec911d0fc9..2bb0fc170d 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/request/api/RunScenarioRequest.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/request/api/RunScenarioRequest.java @@ -53,4 +53,6 @@ public class RunScenarioRequest { private String serialReportId; // private Map reportMap; + private String testPlanId; } + 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 20dd205035..4c2a84955d 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 @@ -4,14 +4,12 @@ package io.metersphere.plan.service; import com.fasterxml.jackson.core.JsonProcessingException; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; -import io.metersphere.base.mapper.ext.ExtTestPlanMapper; -import io.metersphere.base.mapper.ext.ExtTestPlanReportContentMapper; -import io.metersphere.base.mapper.ext.ExtTestPlanReportMapper; -import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; +import io.metersphere.base.mapper.ext.*; import io.metersphere.commons.constants.*; import io.metersphere.commons.utils.*; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.*; +import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.excel.constants.TestPlanTestCaseStatus; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.plan.constant.ApiReportStatus; @@ -80,8 +78,12 @@ public class TestPlanReportService { private TestPlanPrincipalMapper testPlanPrincipalMapper; @Resource ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; - // @Resource - // private PerformanceTestService performanceTestService; + @Resource + private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; + @Resource + private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; + @Resource + private BaseEnvGroupProjectService baseEnvGroupProjectService; @Resource private PlanApiDefinitionExecResultService planApiDefinitionExecResultService; @Resource @@ -103,6 +105,8 @@ public class TestPlanReportService { @Resource private BaseUserService baseUserService; + private final String GROUP = "GROUP"; + public List list(QueryTestPlanReportRequest request) { List list = new ArrayList<>(); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -231,6 +235,78 @@ public class TestPlanReportService { } } + public TestPlanApiReportInfoDTO genApiReportInfoForSchedule(String planId, RunModeConfigDTO runModeConfigDTO) { + TestPlanApiReportInfoDTO testPlanApiReportInfo = new TestPlanApiReportInfoDTO(); + Map planApiCaseIdMap = new LinkedHashMap<>(); + Map planScenarioIdMap = new LinkedHashMap<>(); + + List testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId); + for (TestPlanApiScenarioInfoDTO model : testPlanApiScenarioList) { + planScenarioIdMap.put(model.getId(), model.getApiScenarioId()); + } + List testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(planId); + for (TestPlanApiCaseInfoDTO model : testPlanApiCaseList) { + planApiCaseIdMap.put(model.getId(), model.getApiCaseId()); + } + + testPlanApiReportInfo.setPlanApiCaseIdMap(planApiCaseIdMap); + testPlanApiReportInfo.setPlanScenarioIdMap(planScenarioIdMap); + //解析运行环境信息 + TestPlanReportRunInfoDTO runInfoDTO = this.parseTestPlanRunInfo(runModeConfigDTO, testPlanApiCaseList, testPlanApiScenarioList); + testPlanApiReportInfo.setRunInfoDTO(runInfoDTO); + return testPlanApiReportInfo; + } + + public TestPlanReportRunInfoDTO parseTestPlanRunInfo( + RunModeConfigDTO config, + List cases, + List scenarios) { + + TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); + final Map runEnvMap = config.getEnvMap(); + runInfoDTO.setRunMode(config.getMode()); + + if (StringUtils.equals(GROUP, config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) { + runEnvMap.putAll(baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId())); + runInfoDTO.setEnvGroupId(config.getEnvironmentGroupId()); + } + // 场景环境处理 + scenarios.forEach(item -> { + Map envMap = null; + if (StringUtils.equalsIgnoreCase(GROUP, item.getEnvironmentType()) + && StringUtils.isNotEmpty(item.getEnvironmentGroupId())) { + envMap = baseEnvGroupProjectService.getEnvMap(item.getEnvironmentGroupId()); + } else { + if (MapUtils.isNotEmpty(runEnvMap) && runEnvMap.containsKey(item.getProjectId())) { + runInfoDTO.putScenarioRunInfo(item.getId(), item.getProjectId(), runEnvMap.get(item.getProjectId())); + } else if (StringUtils.isNotEmpty(item.getEnvironment())) { + try { + envMap = JSON.parseObject(item.getEnvironment(), Map.class); + } catch (Exception e) { + LogUtil.error("解析场景环境失败!", e); + } + } + } + if (MapUtils.isNotEmpty(envMap)) { + for (Map.Entry entry : envMap.entrySet()) { + String projectId = entry.getKey(); + String envIdStr = entry.getValue(); + runInfoDTO.putScenarioRunInfo(item.getId(), projectId, envIdStr); + } + } + }); + + // 用例环境处理 + cases.forEach(item -> { + if (MapUtils.isNotEmpty(runEnvMap) && runEnvMap.containsKey(item.getProjectId())) { + runInfoDTO.putApiCaseRunInfo(item.getId(), item.getProjectId(), runEnvMap.get(item.getProjectId())); + } else { + runInfoDTO.putApiCaseRunInfo(item.getId(), item.getProjectId(), item.getEnvironmentId()); + } + }); + return runInfoDTO; + } + public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String planReportId, String planId, String userId, String triggerMode, RunModeConfigDTO runModeConfigDTO) { TestPlanReport testPlanReport = this.getTestPlanReport(planReportId); TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO(); @@ -250,7 +326,8 @@ public class TestPlanReportService { Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); if (serviceIdSet.contains(MicroServiceName.API_TEST)) { - TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = planTestPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO); + // 这里不再调用API服务生成相关数据,否则当关联用例/场景量大时会超时 + TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = this.genApiReportInfoForSchedule(planId, runModeConfigDTO); Map planScenarioIdMap = testPlanApiReportInfoDTO.getPlanScenarioIdMap(); Map planApiCaseIdMap = testPlanApiReportInfoDTO.getPlanApiCaseIdMap(); runInfoDTO = testPlanApiReportInfoDTO.getRunInfoDTO(); 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 2569f55468..dac6db1a91 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 @@ -155,12 +155,7 @@ public class TestPlanService { @Resource private TestResourcePoolMapper testResourcePoolMapper; @Resource - private SystemParameterService systemParameterService; - @Resource - private BaseProjectApplicationService projectApplicationService; - @Resource private TestPlanReportMapper testPlanReportMapper; - public static final String POOL = "POOL"; public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -792,23 +787,26 @@ public class TestPlanService { RunScenarioRequest request = new RunScenarioRequest(); request.setReportId(planScenarioExecuteRequest.getReportId()); + request.setTestPlanId(entry.getKey()); request.setEnvironmentId(planScenarioExecuteRequest.getEnvironmentId()); request.setTriggerMode(planScenarioExecuteRequest.getTriggerMode()); request.setExecuteType(planScenarioExecuteRequest.getExecuteType()); request.setRunMode(planScenarioExecuteRequest.getRunMode()); - request.setIds(new ArrayList<>(scenarioMap.values()));//场景IDS request.setReportUserID(planScenarioExecuteRequest.getReportUserID()); - request.setScenarioTestPlanIdMap(scenarioMap);//未知 request.setConfig(planScenarioExecuteRequest.getConfig()); request.setTestPlanScheduleJob(true); request.setTestPlanReportId(planScenarioExecuteRequest.getTestPlanReportId()); request.setId(UUID.randomUUID().toString()); request.setProjectId(planScenarioExecuteRequest.getProjectId()); request.setRequestOriginator("TEST_PLAN"); - request.setPlanCaseIds(new ArrayList<>(testPlanScenarioIdMap.keySet())); if ("api".equalsIgnoreCase(planScenarioExecuteRequest.getType())) { list.addAll(planApiAutomationService.run(request)); } else { + // 以下三个参数接口测试未使用到,暂时迁移到这里 + request.setIds(new ArrayList<>(scenarioMap.values()));//场景IDS + request.setScenarioTestPlanIdMap(scenarioMap);//未知 + request.setPlanCaseIds(new ArrayList<>(testPlanScenarioIdMap.keySet())); + RunUiScenarioRequest runUiScenarioRequest = new RunUiScenarioRequest(); BeanUtils.copyBean(runUiScenarioRequest, request); RunModeConfigDTO configDTO = new RunModeConfigDTO(); @@ -887,7 +885,7 @@ public class TestPlanService { if (MapUtils.isNotEmpty(reportInfoDTO.getApiTestCaseDataMap())) { //执行接口案例任务 LoggerUtil.info("开始执行测试计划接口用例 " + planReportId); - apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId, userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig); + apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId, userId, testPlanId, runModeConfig); } if (MapUtils.isNotEmpty(reportInfoDTO.getPlanScenarioIdMap())) { //执行场景执行任务 @@ -946,13 +944,13 @@ public class TestPlanService { return runModeConfig; } - private Map executeApiTestCase(String triggerMode, String planReportId, String userId, List planCaseIds, RunModeConfigDTO runModeConfig) { + private Map executeApiTestCase(String triggerMode, String planReportId, String userId, String testPlanId, RunModeConfigDTO runModeConfig) { BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); request.setTriggerMode(triggerMode); - request.setPlanIds(planCaseIds); request.setPlanReportId(planReportId); request.setConfig(runModeConfig); request.setUserId(userId); + request.setTestPlanId(testPlanId); List dtoList = planTestPlanApiCaseService.run(request); return this.parseMsExecResponseDTOToTestIdReportMap(dtoList); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanApiAutomationService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanApiAutomationService.java index 2f2eea55a8..3df8a894c6 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanApiAutomationService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanApiAutomationService.java @@ -1,11 +1,13 @@ package io.metersphere.plan.service.remote.api; import io.metersphere.base.domain.ApiScenarioWithBLOBs; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.plan.request.api.RunScenarioRequest; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.PathVariable; +import java.util.ArrayList; import java.util.List; @Service @@ -15,7 +17,12 @@ public class PlanApiAutomationService extends ApiTestService { public List run(RunScenarioRequest request) { - return microService.postForDataArray(serviceName, BASE_UEL + "/plan/run", request, MsExecResponseDTO.class); + try { + return microService.postForDataArray(serviceName, BASE_UEL + "/plan/run", request, MsExecResponseDTO.class); + } catch (Exception e) { + LogUtil.error("调用API服务执行场景用例失败", e); + return new ArrayList<>(); + } } public ApiScenarioWithBLOBs get(@PathVariable String id) { 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 9e33a1ccd0..934dabd537 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 @@ -93,7 +93,12 @@ public class PlanTestPlanApiCaseService extends ApiTestService { } public List run(BatchRunDefinitionRequest request) { - return microService.postForDataArray(serviceName, BASE_UEL + "/run", request, MsExecResponseDTO.class); + try { + return microService.postForDataArray(serviceName, BASE_UEL + "/run", request, MsExecResponseDTO.class); + } catch (Exception e) { + LogUtil.info("调用API服务执行用例失败", e); + return new ArrayList<>(); + } } public RunModeConfigDTO setApiCaseEnv(String planId, RunModeConfigDTO runModeConfig) { 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 e9344fd0e8..95ab801694 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 @@ -155,10 +155,6 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { return microService.postForData(serviceName, BASE_UEL + "/plan/execute/report", request, ApiPlanReportDTO.class); } - public TestPlanApiReportInfoDTO genApiReportInfoForSchedule(String planId, RunModeConfigDTO runModeConfigDTO) { - return microService.postForData(serviceName, BASE_UEL + "/plan/report/schedule/info/" + planId, runModeConfigDTO, TestPlanApiReportInfoDTO.class); - } - public Boolean isCaseExecuting(String planId) { return microService.getForData(serviceName, BASE_UEL + "/is/executing/" + planId, Boolean.class); }