diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index cc0534f1a1..0ac7b04ecb 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; +import io.metersphere.api.dto.mockconfig.MockConfigStaticData; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.service.ApiAutomationService; @@ -73,6 +74,7 @@ public class MsScenario extends MsTestElement { @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + boolean isMockEvn = false; // 非导出操作,且不是启用状态则跳过执行 if (!config.isOperating() && !this.isEnable()) { return; @@ -131,6 +133,9 @@ public class MsScenario extends MsTestElement { if (environment != null && environment.getConfig() != null) { EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); envConfig.put(projectId, env); + if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { + this.setMockEnvironment(true); + } } }); config.setConfig(envConfig); @@ -154,6 +159,7 @@ public class MsScenario extends MsTestElement { for (MsTestElement el : hashTree) { // 给所有孩子加一个父亲标志 el.setParent(this); + el.setMockEnvironment(this.isMockEnvironment()); el.toHashTree(tree, el.getHashTree(), config); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index ff32d58ffa..739ca18efe 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -699,9 +699,13 @@ public class ApiAutomationService { if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO.name())) { StringBuilder builder = new StringBuilder(); for (ApiScenarioWithBLOBs apiScenarioWithBLOBs : apiScenarios) { - boolean haveEnv = checkScenarioEnv(apiScenarioWithBLOBs); - if (!haveEnv) { - builder.append(apiScenarioWithBLOBs.getName()).append("; "); + try { + boolean haveEnv = checkScenarioEnv(apiScenarioWithBLOBs); + if (!haveEnv) { + builder.append(apiScenarioWithBLOBs.getName()).append("; "); + } + } catch (Exception e) { + MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); } } if (builder.length() > 0) { diff --git a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java index 590fccad2a..f2b6864867 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -169,7 +169,37 @@ public class MockConfigService { MockExpectConfigResponse returnModel = null; if (reqJsonObj == null || reqJsonObj.isEmpty()) { - return returnModel; + for (MockExpectConfigResponse model : mockExpectConfigList) { + if (!model.isStatus()) { + continue; + } + JSONObject requestObj = model.getRequest(); + boolean isJsonParam = requestObj.getBoolean("jsonParam"); + JSONObject mockExpectJson = new JSONObject(); + if (isJsonParam) { + mockExpectJson = JSONObject.parseObject(requestObj.getString("jsonData")); + } else { + JSONArray jsonArray = requestObj.getJSONArray("variables"); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject object = jsonArray.getJSONObject(i); + String name = ""; + String value = ""; + if (object.containsKey("name")) { + name = String.valueOf(object.get("name")).trim(); + } + if (object.containsKey("value")) { + value = String.valueOf(object.get("value")).trim(); + } + if (StringUtils.isNotEmpty(name)) { + mockExpectJson.put(name, value); + } + } + } + if (mockExpectJson.isEmpty()) { + return model; + } + + } } for (MockExpectConfigResponse model : mockExpectConfigList) { try { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml index 36ee462257..c426c0f3e8 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml @@ -252,20 +252,21 @@ GROUP BY groupField;