fix(测试跟踪): 修复测试计划关联场景执行提示未选择环境的缺陷

--bug=1018843 --user=王孝刚 [测试跟踪]测试计划-关联场景用例后-列表中执行场景-提示未选运行环境
https://www.tapd.cn/55049933/s/1285306
This commit is contained in:
wxg0103 2022-11-01 16:02:21 +08:00 committed by wxg0103
parent 4649e95a7d
commit f890ce8735
5 changed files with 36 additions and 14 deletions

View File

@ -1,16 +1,16 @@
package io.metersphere.api.dto.scenario.environment.item; package io.metersphere.api.dto.scenario.environment.item;
import io.metersphere.plugin.core.MsTestElement;
import lombok.Data; import lombok.Data;
import java.util.LinkedList; import java.util.LinkedList;
@Data @Data
public class BaseEnvElement { public class BaseEnvElement {
// 组件类型 // 组件类型
private String type; private String type;
// 用于数据反射对象 // 用于数据反射对象
private String clazzName = MsTestElement.class.getCanonicalName(); private String clazzName = BaseEnvElement.class.getCanonicalName();
// 自身资源ID用例ID/接口ID/场景ID) // 自身资源ID用例ID/接口ID/场景ID)
private String id; private String id;
@ -39,7 +39,7 @@ public class BaseEnvElement {
private String refType; private String refType;
// 子组件 // 子组件
private LinkedList<MsTestElement> hashTree; private LinkedList<BaseEnvElement> hashTree;
// 项目ID // 项目ID
private String projectId; private String projectId;

View File

@ -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<String, String> environmentMap;
}

View File

@ -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.ParameterConfig;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; 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.domain.*;
import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioMapper;
import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ApiTestCaseMapper;
@ -172,6 +173,9 @@ public class ApiScenarioEnvService {
environmentType = EnvironmentType.JSON.toString(); environmentType = EnvironmentType.JSON.toString();
} }
String definition = apiScenarioWithBLOBs.getScenarioDefinition(); String definition = apiScenarioWithBLOBs.getScenarioDefinition();
JSONObject element = JSONUtil.parseObject(definition);
ElementUtil.dataFormatting(element);
definition = element.toString();
MsScenario scenario = JSON.parseObject(definition, MsScenario.class); MsScenario scenario = JSON.parseObject(definition, MsScenario.class);
GenerateHashTreeUtil.parse(definition, scenario); GenerateHashTreeUtil.parse(definition, scenario);
if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString()) && StringUtils.isNotEmpty(environmentJson)) { if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString()) && StringUtils.isNotEmpty(environmentJson)) {
@ -189,7 +193,7 @@ public class ApiScenarioEnvService {
public boolean verifyScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs) { public boolean verifyScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs) {
if (apiScenarioWithBLOBs != null) { if (apiScenarioWithBLOBs != null) {
String definition = apiScenarioWithBLOBs.getScenarioDefinition(); String definition = apiScenarioWithBLOBs.getScenarioDefinition();
MsScenario scenario = JSON.parseObject(definition, MsScenario.class); MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class);
Map<String, String> envMap = scenario.getEnvironmentMap(); Map<String, String> envMap = scenario.getEnvironmentMap();
return this.check(definition, envMap, scenario.getEnvironmentId(), apiScenarioWithBLOBs.getProjectId()); return this.check(definition, envMap, scenario.getEnvironmentId(), apiScenarioWithBLOBs.getProjectId());
} }
@ -250,7 +254,7 @@ public class ApiScenarioEnvService {
public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) { public boolean verifyPlanScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) {
if (apiScenarioWithBLOBs != null) { if (apiScenarioWithBLOBs != null) {
String definition = apiScenarioWithBLOBs.getScenarioDefinition(); String definition = apiScenarioWithBLOBs.getScenarioDefinition();
MsScenario scenario = JSON.parseObject(definition, MsScenario.class); MsScenarioEnv scenario = JSON.parseObject(definition, MsScenarioEnv.class);
Map<String, String> envMap = scenario.getEnvironmentMap(); Map<String, String> envMap = scenario.getEnvironmentMap();
if (testPlanApiScenarios != null) { if (testPlanApiScenarios != null) {
String envType = testPlanApiScenarios.getEnvironmentType(); String envType = testPlanApiScenarios.getEnvironmentType();

View File

@ -186,7 +186,7 @@ public class JMeterService {
public void run(JmeterRunRequestDTO request) { public void run(JmeterRunRequestDTO request) {
if (request.getPool().isPool() && StringUtils.isNotBlank(request.getRunMode())) { if (request.getPool().isPool() && StringUtils.isNotBlank(request.getRunMode())) {
this.runNode(request); this.runNode(request);
} else { } else if (request.getHashTree() != null) {
//解析hashTree是否含有文件库文件 //解析hashTree是否含有文件库文件
HashTreeUtil.initRepositoryFiles(request); HashTreeUtil.initRepositoryFiles(request);
CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).addTask(request); CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).addTask(request);

View File

@ -10,18 +10,21 @@ import io.metersphere.api.dto.definition.request.*;
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
import io.metersphere.api.jmeter.NewDriverManager; import io.metersphere.api.jmeter.NewDriverManager;
import io.metersphere.api.jmeter.ResourcePoolCalculation; 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.ApiScenarioWithBLOBs;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.mapper.TestResourcePoolMapper; import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.commons.constants.ElementConstants;
import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.constants.RunModeConstants; 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.plugin.core.MsTestElement;
import io.metersphere.service.ApiExecutionQueueService;
import io.metersphere.service.RemakeReportService;
import io.metersphere.utils.LoggerUtil; import io.metersphere.utils.LoggerUtil;
import io.metersphere.vo.BooleanPool; import io.metersphere.vo.BooleanPool;
import io.metersphere.xpack.api.service.ApiRetryOnFailureService; import io.metersphere.xpack.api.service.ApiRetryOnFailureService;
@ -139,14 +142,17 @@ public class GenerateHashTreeUtil {
MsThreadGroup group = new MsThreadGroup(); MsThreadGroup group = new MsThreadGroup();
group.setLabel(item.getName()); group.setLabel(item.getName());
group.setName(runRequest.getReportId()); 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()); group.setOnSampleError(scenario.getOnSampleError());
if (planEnvMap != null && planEnvMap.size() > 0) { if (planEnvMap != null && planEnvMap.size() > 0) {
scenario.setEnvironmentMap(planEnvMap); scenario.setEnvironmentMap(planEnvMap);
} else { } else {
setScenarioEnv(scenario, item); setScenarioEnv(scenario, item);
} }
String data = item.getScenarioDefinition(); String data = definition;
// 失败重试 // 失败重试
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) { if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class); ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class);
@ -172,6 +178,7 @@ public class GenerateHashTreeUtil {
} catch (Exception ex) { } catch (Exception ex) {
remakeException(runRequest); remakeException(runRequest);
LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex); LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex);
return null;
} }
LogUtil.info(testPlan.getJmx(jmeterHashTree)); LogUtil.info(testPlan.getJmx(jmeterHashTree));