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 f7648025cb..cceef25f46 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1411,10 +1411,12 @@ public class ApiAutomationService { return; } JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect); - JSONArray hashTree = element.getJSONArray("hashTree"); - ApiScenarioImportUtil.formatHashTree(hashTree); - setHashTree(hashTree); - scenario.setScenarioDefinition(JSONObject.toJSONString(element)); + if (element != null) { + JSONArray hashTree = element.getJSONArray("hashTree"); + ApiScenarioImportUtil.formatHashTree(hashTree); + setHashTree(hashTree); + scenario.setScenarioDefinition(JSONObject.toJSONString(element)); + } names.add(scenario.getName()); ids.add(scenario.getId()); } @@ -1456,6 +1458,8 @@ public class ApiAutomationService { public List exportJmx(ApiScenarioBatchRequest request) { List apiScenarioWithBLOBs = getExportResult(request); + //检查运行环境 + checkExportEnv(apiScenarioWithBLOBs); // 生成jmx List resList = new ArrayList<>(); apiScenarioWithBLOBs.forEach(item -> { @@ -1483,6 +1487,8 @@ public class ApiAutomationService { public byte[] exportZip(ApiScenarioBatchRequest request) { List scenarios = getExportResult(request); + //环境检查 + checkExportEnv(scenarios); // 生成jmx Map files = new LinkedHashMap<>(); scenarios.forEach(item -> { @@ -1505,6 +1511,23 @@ public class ApiAutomationService { return FileUtils.listBytesToZip(files); } + private void checkExportEnv(List scenarios) { + StringBuilder builder = new StringBuilder(); + for (ApiScenarioWithBLOBs apiScenarioWithBLOBs : scenarios) { + try { + boolean haveEnv = apiScenarioEnvService.checkScenarioEnv(apiScenarioWithBLOBs, null); + if (!haveEnv) { + builder.append(apiScenarioWithBLOBs.getName()).append("; "); + } + } catch (Exception e) { + MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); + } + } + if (builder.length() > 0) { + MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!"); + } + } + public void batchUpdateEnv(ApiScenarioBatchRequest request) { Map envMap = request.getEnvMap(); String envType = request.getEnvironmentType();