fix(接口测试): 修复场景导入在某些情况下会重复创建api的问题
--bug=1048286 --user=宋天阳 【场景导入】-原场景中引用和复制相同的CASE作为步骤,导出这个场景然后导入到其他项目,会在项目下创建两个API https://www.tapd.cn/55049933/s/1600281
This commit is contained in:
parent
e73f6ae80c
commit
e0c8a5ddf6
|
@ -958,23 +958,23 @@ public class ApiScenarioDataTransferService {
|
||||||
|
|
||||||
Map<String, List<ApiTestCaseDTO>> apiIdMap = protocolList.stream().collect(Collectors.groupingBy(ApiTestCaseDTO::getApiDefinitionId));
|
Map<String, List<ApiTestCaseDTO>> apiIdMap = protocolList.stream().collect(Collectors.groupingBy(ApiTestCaseDTO::getApiDefinitionId));
|
||||||
for (Map.Entry<String, List<ApiTestCaseDTO>> apiIdEntry : apiIdMap.entrySet()) {
|
for (Map.Entry<String, List<ApiTestCaseDTO>> apiIdEntry : apiIdMap.entrySet()) {
|
||||||
ApiDefinitionDetail replaceApiDefinition = returnResource.getApi(apiIdEntry.getKey()) == null ? null : returnResource.getApi(apiIdEntry.getKey());
|
ApiDefinitionDetail replacedApiDefinition = returnResource.getApi(apiIdEntry.getKey()) == null ? null : returnResource.getApi(apiIdEntry.getKey());
|
||||||
List<ApiTestCaseDTO> testCaseList = apiIdEntry.getValue();
|
List<ApiTestCaseDTO> testCaseList = apiIdEntry.getValue();
|
||||||
if (replaceApiDefinition != null) {
|
if (replacedApiDefinition == null) {
|
||||||
// 用例对应的接口在上述步骤中有没有处理
|
// 用例对应的接口在上述步骤中有没有处理
|
||||||
boolean apiExistence = ApiScenarioImportUtils.isApiExistence(
|
ApiDefinitionDetail existenceApi = ApiScenarioImportUtils.isApiExistence(
|
||||||
protocol, testCaseList.getFirst().getMethod(), testCaseList.getFirst().getPath(),
|
protocol, testCaseList.getFirst().getMethod(), testCaseList.getFirst().getPath(),
|
||||||
testCaseList.getFirst().getModulePath(), testCaseList.getFirst().getApiDefinitionName(), existenceApiDefinitionList);
|
testCaseList.getFirst().getModulePath(), testCaseList.getFirst().getApiDefinitionName(), existenceApiDefinitionList);
|
||||||
|
|
||||||
if (!apiExistence && !StringUtils.equalsIgnoreCase(targetProjectId, projectId)) {
|
if (existenceApi == null && !StringUtils.equalsIgnoreCase(targetProjectId, projectId)) {
|
||||||
// 如果用例所在项目与当前导入项目不同,且在原项目中不存在时,判断是否在当前项目中存在
|
// 如果用例所在项目与当前导入项目不同,且在原项目中不存在时,判断是否在当前项目中存在
|
||||||
apiExistence = ApiScenarioImportUtils.isApiExistence(
|
existenceApi = ApiScenarioImportUtils.isApiExistence(
|
||||||
protocol, testCaseList.getFirst().getMethod(), testCaseList.getFirst().getPath(),
|
protocol, testCaseList.getFirst().getMethod(), testCaseList.getFirst().getPath(),
|
||||||
testCaseList.getFirst().getModulePath(), testCaseList.getFirst().getApiDefinitionName(), thisProjectExistenceApiDefinitionList);
|
testCaseList.getFirst().getModulePath(), testCaseList.getFirst().getApiDefinitionName(), thisProjectExistenceApiDefinitionList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiExistence) {
|
if (existenceApi != null) {
|
||||||
Map<Long, ApiTestCaseDTO> existenceApiCaseNumMap = extApiTestCaseMapper.selectBaseInfoByProjectIdAndApiId(targetProjectId, apiIdEntry.getKey())
|
Map<Long, ApiTestCaseDTO> existenceApiCaseNumMap = extApiTestCaseMapper.selectBaseInfoByProjectIdAndApiId(targetProjectId, existenceApi.getId())
|
||||||
.stream().collect(Collectors.toMap(ApiTestCaseDTO::getNum, Function.identity(), (k1, k2) -> k1));
|
.stream().collect(Collectors.toMap(ApiTestCaseDTO::getNum, Function.identity(), (k1, k2) -> k1));
|
||||||
for (ApiTestCaseDTO apiTestCaseDTO : apiIdEntry.getValue()) {
|
for (ApiTestCaseDTO apiTestCaseDTO : apiIdEntry.getValue()) {
|
||||||
if (existenceApiCaseNumMap.containsKey(apiTestCaseDTO.getNum())) {
|
if (existenceApiCaseNumMap.containsKey(apiTestCaseDTO.getNum())) {
|
||||||
|
@ -982,9 +982,10 @@ public class ApiScenarioDataTransferService {
|
||||||
} else {
|
} else {
|
||||||
String oldId = apiTestCaseDTO.getId();
|
String oldId = apiTestCaseDTO.getId();
|
||||||
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
||||||
apiTestCaseDTO.setProjectId(replaceApiDefinition.getProjectId());
|
apiTestCaseDTO.setName(apiTestCaseDTO.getName() + "_" + System.currentTimeMillis());
|
||||||
apiTestCaseDTO.setApiDefinitionId(replaceApiDefinition.getId());
|
apiTestCaseDTO.setProjectId(existenceApi.getProjectId());
|
||||||
returnResource.putApiTestCase(oldId, apiTestCaseDTO);
|
apiTestCaseDTO.setApiDefinitionId(existenceApi.getId());
|
||||||
|
returnResource.putApiTestCase(apiTestCaseDTO.getId(), apiTestCaseDTO);
|
||||||
analysisResult.setApiTestCase(apiTestCaseDTO);
|
analysisResult.setApiTestCase(apiTestCaseDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1006,6 +1007,7 @@ public class ApiScenarioDataTransferService {
|
||||||
for (ApiTestCaseDTO apiTestCaseDTO : testCaseList) {
|
for (ApiTestCaseDTO apiTestCaseDTO : testCaseList) {
|
||||||
String oldId = apiTestCaseDTO.getId();
|
String oldId = apiTestCaseDTO.getId();
|
||||||
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
||||||
|
apiTestCaseDTO.setName(apiTestCaseDTO.getName() + "_" + System.currentTimeMillis());
|
||||||
apiTestCaseDTO.setProjectId(apiDefinitionDetail.getProjectId());
|
apiTestCaseDTO.setProjectId(apiDefinitionDetail.getProjectId());
|
||||||
apiTestCaseDTO.setApiDefinitionId(apiDefinitionDetail.getId());
|
apiTestCaseDTO.setApiDefinitionId(apiDefinitionDetail.getId());
|
||||||
returnResource.putApiTestCase(oldId, apiTestCaseDTO);
|
returnResource.putApiTestCase(oldId, apiTestCaseDTO);
|
||||||
|
@ -1014,17 +1016,18 @@ public class ApiScenarioDataTransferService {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Map<Long, ApiTestCaseDTO> existenceApiCaseNumMap = extApiTestCaseMapper.selectBaseInfoByProjectIdAndApiId(targetProjectId, replaceApiDefinition.getId())
|
Map<Long, ApiTestCaseDTO> existenceApiCaseNumMap = extApiTestCaseMapper.selectBaseInfoByProjectIdAndApiId(targetProjectId, replacedApiDefinition.getId())
|
||||||
.stream().collect(Collectors.toMap(ApiTestCaseDTO::getNum, Function.identity(), (k1, k2) -> k1));
|
.stream().collect(Collectors.toMap(ApiTestCaseDTO::getNum, Function.identity(), (k1, k2) -> k1));
|
||||||
for (ApiTestCaseDTO apiTestCaseDTO : testCaseList) {
|
for (ApiTestCaseDTO apiTestCaseDTO : testCaseList) {
|
||||||
apiTestCaseDTO.setApiDefinitionId(replaceApiDefinition.getId());
|
apiTestCaseDTO.setApiDefinitionId(replacedApiDefinition.getId());
|
||||||
apiTestCaseDTO.setProjectId(replaceApiDefinition.getProjectId());
|
apiTestCaseDTO.setProjectId(replacedApiDefinition.getProjectId());
|
||||||
if (existenceApiCaseNumMap.containsKey(apiTestCaseDTO.getNum())) {
|
if (existenceApiCaseNumMap.containsKey(apiTestCaseDTO.getNum())) {
|
||||||
returnResource.putApiTestCase(apiTestCaseDTO.getId(), existenceApiCaseNumMap.get(apiTestCaseDTO.getNum()));
|
returnResource.putApiTestCase(apiTestCaseDTO.getId(), existenceApiCaseNumMap.get(apiTestCaseDTO.getNum()));
|
||||||
} else {
|
} else {
|
||||||
apiTestCaseDTO.setProjectId(targetProjectId);
|
apiTestCaseDTO.setProjectId(targetProjectId);
|
||||||
returnResource.putApiTestCase(apiTestCaseDTO.getId(), apiTestCaseDTO);
|
returnResource.putApiTestCase(apiTestCaseDTO.getId(), apiTestCaseDTO);
|
||||||
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
apiTestCaseDTO.setId(IDGenerator.nextStr());
|
||||||
|
apiTestCaseDTO.setName(apiTestCaseDTO.getName() + "_" + System.currentTimeMillis());
|
||||||
analysisResult.setApiTestCase(apiTestCaseDTO);
|
analysisResult.setApiTestCase(apiTestCaseDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,14 +108,19 @@ public class ApiScenarioImportUtils {
|
||||||
return apiIdDic;
|
return apiIdDic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isApiExistence(String protocol, String method, String path, String modulePath, String apiDefinitionName, List<ApiDefinitionDetail> existenceApiDefinitionList) {
|
public static ApiDefinitionDetail isApiExistence(String protocol, String method, String path, String modulePath, String apiDefinitionName, List<ApiDefinitionDetail> existenceApiDefinitionList) {
|
||||||
Map<String, ApiDefinitionDetail> existenceMap = null;
|
Map<String, ApiDefinitionDetail> existenceMap = null;
|
||||||
if (StringUtils.equalsIgnoreCase(protocol, ApiConstants.HTTP_PROTOCOL)) {
|
if (StringUtils.equalsIgnoreCase(protocol, ApiConstants.HTTP_PROTOCOL)) {
|
||||||
existenceMap = existenceApiDefinitionList.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t, (oldValue, newValue) -> newValue));
|
existenceMap = existenceApiDefinitionList.stream().collect(Collectors.toMap(t -> t.getMethod() + t.getPath(), t -> t, (oldValue, newValue) -> newValue));
|
||||||
return existenceMap.containsKey(method + path);
|
if (existenceMap.containsKey(method + path)) {
|
||||||
|
return existenceMap.get(method + path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
existenceMap = existenceApiDefinitionList.stream().collect(Collectors.toMap(t -> t.getModulePath() + t.getName(), t -> t, (oldValue, newValue) -> newValue));
|
existenceMap = existenceApiDefinitionList.stream().collect(Collectors.toMap(t -> t.getModulePath() + t.getName(), t -> t, (oldValue, newValue) -> newValue));
|
||||||
return existenceMap.containsKey(modulePath + apiDefinitionName);
|
if (existenceMap.containsKey(modulePath + apiDefinitionName)) {
|
||||||
|
return existenceMap.get(modulePath + apiDefinitionName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue