diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index e321e48787..18fbcd82c0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -115,8 +115,7 @@ public class MsScenario extends MsTestElement { scenarioTree = MsCriticalSectionController.createHashTree(tree, this.getName(), this.isEnable()); } // 启用当前场景变量优先选择 - if ((mixEnable == null || BooleanUtils.isTrue(mixEnable)) - && (this.variableEnable == null || BooleanUtils.isFalse(this.variableEnable))) { + if (isMixEnable() || isAllEnable()) { config.margeVariables(this.variables, config.getTransferVariables()); } // 环境变量 @@ -165,6 +164,11 @@ public class MsScenario extends MsTestElement { this.setGlobProcessor(this.isEnvironmentEnable() ? newConfig : config, scenarioTree, false); } + private boolean isMixEnable() { + return (mixEnable == null || BooleanUtils.isTrue(mixEnable)) + && (this.variableEnable == null || BooleanUtils.isFalse(this.variableEnable)); + } + private boolean isAllEnable() { return (this.variableEnable == null || BooleanUtils.isFalse(this.variableEnable)) && (this.mixEnable == null || BooleanUtils.isFalse(this.mixEnable)); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvGroupProjectService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvGroupProjectService.java index b547bdf064..0dbf111d22 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvGroupProjectService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/BaseEnvGroupProjectService.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -51,7 +52,9 @@ public class BaseEnvGroupProjectService { public Map getEnvMap(String groupId) { List list = baseEnvGroupProjectMapper.getList(groupId); - Map map = list.stream().collect(Collectors.toMap(EnvironmentGroupProject::getProjectId, EnvironmentGroupProject::getEnvironmentId)); - return map; + if (!CollectionUtils.isEmpty(list)) { + return list.stream().collect(Collectors.toMap(EnvironmentGroupProject::getProjectId, EnvironmentGroupProject::getEnvironmentId)); + } + return new HashMap<>(); } } 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 2cedb4fab7..c2bb39c6f8 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 @@ -263,11 +263,14 @@ public class TestPlanReportService { List scenarios) { TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); - final Map runEnvMap = config.getEnvMap(); + final Map runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>(); runInfoDTO.setRunMode(config.getMode()); if (StringUtils.equals(GROUP, config.getEnvironmentType()) && StringUtils.isNotEmpty(config.getEnvironmentGroupId())) { - runEnvMap.putAll(baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId())); + Map groupMap = baseEnvGroupProjectService.getEnvMap(config.getEnvironmentGroupId()); + if (MapUtils.isNotEmpty(groupMap)) { + runEnvMap.putAll(groupMap); + } runInfoDTO.setEnvGroupId(config.getEnvironmentGroupId()); } // 场景环境处理