From b33c859ff7144d478ef17050217c93223bcb9250 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 8 Jun 2022 11:49:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5=E4=B8=8D?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=B7=B2=E5=AD=98=E5=9C=A8=E7=9A=84case?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1013504 导入存在引用关系的接口定义和自动化场景json文件,额外创建了新的接口用例 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001013504 --- .../parse/ApiScenarioImportUtil.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java index 31caec98f8..072d04f2f4 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java @@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; import io.metersphere.api.dto.definition.ApiDefinitionResult; +import io.metersphere.api.dto.definition.ApiTestCaseDTO; +import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.parse.ms.NodeTree; import io.metersphere.api.dto.definition.response.HttpResponse; import io.metersphere.api.dto.scenario.Body; @@ -140,16 +142,23 @@ public class ApiScenarioImportUtil { if(apiDefinition==null){ if(MapUtils.isEmpty(definitionMap)){ return null; + }else { + return definitionMap.get(object.getString("path") + object.getString("method") + object.getString("protocol")); + } + } else { + if(MapUtils.isEmpty(definitionMap)){ + definitionMap.put(object.getString("path") + object.getString("method") + object.getString("protocol"),apiDefinition); + return apiDefinition; }else { ApiDefinition apiDefinition1 = definitionMap.get(object.getString("path") + object.getString("method") + object.getString("protocol")); - if(apiDefinition1!=null){ + if (apiDefinition1 == null) { + definitionMap.put(object.getString("path") + object.getString("method") + object.getString("protocol"),apiDefinition); + return apiDefinition; + } else { return apiDefinition1; - }else{ - return null; } } } - return apiDefinition; } public static void checkCase(int i,JSONObject object, String versionId, String projectId, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper,MapdefinitionMap) { @@ -162,7 +171,20 @@ public class ApiScenarioImportUtil { ApiDefinition apiDefinition = getApiDefinitionResult(object,apiDefinitionService,definitionMap,userRelatedProjectIds); if(apiDefinition!=null){ if(MapUtils.isNotEmpty(definitionMap)||definitionMap.size()==0){ - structureCaseByJson(i,object,testCaseService, apiDefinition,apiTestCaseMapper); + ApiTestCaseRequest request = new ApiTestCaseRequest(); + request.setApiDefinitionId(apiDefinition.getId()); + request.setName(object.getString("name")); + List apiTestCaseDTOS = testCaseService.listSimple(request); + if (apiTestCaseDTOS ==null || apiTestCaseDTOS.isEmpty()) { + structureCaseByJson(i,object,testCaseService, apiDefinition,apiTestCaseMapper); + } else { + ApiTestCaseDTO apiTestCase = apiTestCaseDTOS.get(0); + object.put("id", apiTestCase.getId()); + object.put("resourceId", apiTestCase.getId()); + object.put("projectId", projectId); + object.put("useEnvironment",""); + object.put("environmentId",""); + } } }else{ ApiDefinitionResult apiDefinitionResult = structureApiDefinitionByJson(i,apiDefinitionService, object, versionId, projectId, apiDefinitionMapper,definitionMap);