From 529b4358fba6792749b4f31be6a1e7e5da7b9f47 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 1 Nov 2022 16:02:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=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=E5=9C=BA=E6=99=AF=E6=89=A7=E8=A1=8C=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=9C=AA=E9=80=89=E6=8B=A9=E7=8E=AF=E5=A2=83=E7=9A=84=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1018843 --user=王孝刚 [测试跟踪]测试计划-关联场景用例后-列表中执行场景-提示未选运行环境 https://www.tapd.cn/55049933/s/1285306 --- .../environment/item/BaseEnvElement.java | 6 ++--- .../environment/item/MsScenarioEnv.java | 11 +++++++++ .../exec/scenario/ApiScenarioEnvService.java | 8 +++++-- .../metersphere/api/jmeter/JMeterService.java | 2 +- .../commons/utils/GenerateHashTreeUtil.java | 23 ++++++++++++------- 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java index b8ffde66a4..501634378a 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/BaseEnvElement.java @@ -1,16 +1,16 @@ package io.metersphere.api.dto.scenario.environment.item; -import io.metersphere.plugin.core.MsTestElement; import lombok.Data; import java.util.LinkedList; + @Data public class BaseEnvElement { // 组件类型 private String type; // 用于数据反射对象 - private String clazzName = MsTestElement.class.getCanonicalName(); + private String clazzName = BaseEnvElement.class.getCanonicalName(); // 自身资源ID(用例ID/接口ID/场景ID)等 private String id; @@ -39,7 +39,7 @@ public class BaseEnvElement { private String refType; // 子组件 - private LinkedList hashTree; + private LinkedList hashTree; // 项目ID private String projectId; diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java new file mode 100644 index 0000000000..2ea02b42eb --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/item/MsScenarioEnv.java @@ -0,0 +1,11 @@ +package io.metersphere.api.dto.scenario.environment.item; + +import lombok.Data; + +import java.util.Map; + +@Data +public class MsScenarioEnv { + private String environmentId; + private Map environmentMap; +} 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 2134ca6c42..b75ee363ba 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 @@ -10,6 +10,7 @@ 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.scenario.environment.EnvironmentConfig; +import io.metersphere.api.dto.scenario.environment.item.MsScenarioEnv; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; @@ -172,6 +173,9 @@ public class ApiScenarioEnvService { environmentType = EnvironmentType.JSON.toString(); } String definition = apiScenarioWithBLOBs.getScenarioDefinition(); + JSONObject element = JSONUtil.parseObject(definition); + ElementUtil.dataFormatting(element); + definition = element.toString(); MsScenario scenario = JSON.parseObject(definition, MsScenario.class); GenerateHashTreeUtil.parse(definition, scenario); if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString()) && StringUtils.isNotEmpty(environmentJson)) { @@ -189,7 +193,7 @@ public class ApiScenarioEnvService { public boolean verifyScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs) { if (apiScenarioWithBLOBs != null) { String definition = apiScenarioWithBLOBs.getScenarioDefinition(); - MsScenario scenario = JSON.parseObject(definition, MsScenario.class); + MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class); Map envMap = scenario.getEnvironmentMap(); return this.check(definition, envMap, scenario.getEnvironmentId(), apiScenarioWithBLOBs.getProjectId()); } @@ -250,7 +254,7 @@ public class ApiScenarioEnvService { public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) { if (apiScenarioWithBLOBs != null) { String definition = apiScenarioWithBLOBs.getScenarioDefinition(); - MsScenario scenario = JSON.parseObject(definition, MsScenario.class); + MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class); Map envMap = scenario.getEnvironmentMap(); if (testPlanApiScenarios != null) { String envType = testPlanApiScenarios.getEnvironmentType(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 8dc2424c93..15490ea465 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -186,7 +186,7 @@ public class JMeterService { public void run(JmeterRunRequestDTO request) { if (request.getPool().isPool() && StringUtils.isNotBlank(request.getRunMode())) { this.runNode(request); - } else { + } else if (request.getHashTree() != null) { //解析hashTree,是否含有文件库文件 HashTreeUtil.initRepositoryFiles(request); CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).addTask(request); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java index bbd2cc29e1..2ac5c48759 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/GenerateHashTreeUtil.java @@ -10,18 +10,21 @@ import io.metersphere.api.dto.definition.request.*; import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.jmeter.NewDriverManager; import io.metersphere.api.jmeter.ResourcePoolCalculation; -import io.metersphere.base.domain.TestResource; -import io.metersphere.service.ApiExecutionQueueService; -import io.metersphere.service.RemakeReportService; -import io.metersphere.commons.constants.ElementConstants; -import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.base.domain.ApiScenarioWithBLOBs; +import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.mapper.TestResourcePoolMapper; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.constants.RunModeConstants; -import io.metersphere.dto.*; +import io.metersphere.dto.BaseSystemConfigDTO; +import io.metersphere.dto.JmeterRunRequestDTO; +import io.metersphere.dto.ResultDTO; +import io.metersphere.dto.RunModeConfigDTO; +import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.plugin.core.MsTestElement; +import io.metersphere.service.ApiExecutionQueueService; +import io.metersphere.service.RemakeReportService; import io.metersphere.utils.LoggerUtil; import io.metersphere.vo.BooleanPool; import io.metersphere.xpack.api.service.ApiRetryOnFailureService; @@ -139,14 +142,17 @@ public class GenerateHashTreeUtil { MsThreadGroup group = new MsThreadGroup(); group.setLabel(item.getName()); group.setName(runRequest.getReportId()); - MsScenario scenario = JSON.parseObject(item.getScenarioDefinition(), MsScenario.class); + JSONObject element = JSONUtil.parseObject(item.getScenarioDefinition()); + ElementUtil.dataFormatting(element); + String definition = element.toString(); + MsScenario scenario = JSON.parseObject(definition, MsScenario.class); group.setOnSampleError(scenario.getOnSampleError()); if (planEnvMap != null && planEnvMap.size() > 0) { scenario.setEnvironmentMap(planEnvMap); } else { setScenarioEnv(scenario, item); } - String data = item.getScenarioDefinition(); + String data = definition; // 失败重试 if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) { ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class); @@ -172,6 +178,7 @@ public class GenerateHashTreeUtil { } catch (Exception ex) { remakeException(runRequest); LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex); + return null; } LogUtil.info(testPlan.getJmx(jmeterHashTree));