From 81d52b4fabee5b5c8f1cc48ff351ebfc2faae8d7 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 28 Mar 2022 19:44:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=87=BA=EF=BC=8C=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E5=B1=82=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1011678 --user=郭雨琦 场景导出加一层对hashtree的搜索,如果是引用的用例,在步骤中没有hashtree,那就去查引用的case 的hashtree如果有赋值,没有停止在这一层了 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001011678 --- .../api/service/ApiAutomationService.java | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) 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 fcb1744f8d..dcc61c4f93 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -10,6 +10,7 @@ import io.metersphere.api.dto.automation.parse.ScenarioImport; import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory; import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.datacount.ApiMethodUrlDTO; +import io.metersphere.api.dto.definition.ApiTestCaseInfo; import io.metersphere.api.dto.definition.RunDefinitionRequest; import io.metersphere.api.dto.definition.request.*; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; @@ -131,6 +132,8 @@ public class ApiAutomationService { private MsHashTreeService hashTreeService; @Resource private ProjectApplicationService projectApplicationService; + @Resource + private ExtApiTestCaseMapper extApiTestCaseMapper; private ThreadLocal currentScenarioOrder = new ThreadLocal<>(); @@ -1367,15 +1370,64 @@ public class ApiAutomationService { result.setProjectId(request.getProjectId()); result.setVersion(System.getenv("MS_VERSION")); if (CollectionUtils.isNotEmpty(result.getData())) { - List names = result.getData().stream().map(ApiScenarioWithBLOBs::getName).collect(Collectors.toList()); + List names = new ArrayList<>(); + List ids = new ArrayList<>(); + checkDefinition(result,names,ids); request.setName(String.join(",", names)); - List ids = result.getData().stream().map(ApiScenarioWithBLOBs::getId).collect(Collectors.toList()); request.setId(JSON.toJSONString(ids)); } return result; } - public List exportJmx(ApiScenarioBatchRequest request) { + public void checkDefinition(ApiScenrioExportResult result, List names, List ids){ + for (ApiScenarioWithBLOBs scenario : result.getData()) { + if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) { + return; + } + JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); + JSONArray hashTree = element.getJSONArray("hashTree"); + ApiScenarioImportUtil.formatHashTree(hashTree); + setHashTree(hashTree); + scenario.setScenarioDefinition(JSONObject.toJSONString(element)); + names.add(scenario.getName()); + ids.add(scenario.getId()); + } + } + public void setHashTree(JSONArray hashTree){ + try { + if (CollectionUtils.isNotEmpty(hashTree)) { + for (int i = 0; i < hashTree.size(); i++) { + JSONObject object = (JSONObject) hashTree.get(i); + String referenced = object.getString("referenced"); + if (StringUtils.isNotBlank(referenced) && StringUtils.equals(referenced, "REF")) { + // 检测引用对象是否存在,若果不存在则改成复制对象 + String refType = object.getString("refType"); + if (StringUtils.isNotEmpty(refType)) { + if (refType.equals("CASE")) { + if (CollectionUtils.isEmpty(object.getJSONArray("hashTree"))) { + ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id")); + if (model != null) { + JSONObject element = JSON.parseObject(model.getRequest()); + object.put("hashTree",element.getJSONArray("hashTree")); + } + } + } + } + } + if(StringUtils.isNotEmpty(object.getString("refType"))){ + if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) { + setHashTree(object.getJSONArray("hashTree")); + } + } + + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public List exportJmx(ApiScenarioBatchRequest request) { List apiScenarioWithBLOBs = getExportResult(request); // 生成jmx List resList = new ArrayList<>();