fix(接口测试): 修复接口导入覆盖问题

https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001018819
--user=郭雨琦
This commit is contained in:
guoyuqi 2022-10-25 13:58:53 +08:00 committed by xiaomeinvG
parent 890b82b1a3
commit 72a7b40584
2 changed files with 14 additions and 15 deletions

View File

@ -1174,6 +1174,7 @@ public class ApiDefinitionService {
} else if (apiTestImportRequest.getCoverModule() != null && apiTestImportRequest.getCoverModule()) { } else if (apiTestImportRequest.getCoverModule() != null && apiTestImportRequest.getCoverModule()) {
apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setUpdateTime(System.currentTimeMillis());
} }
if (CollectionUtils.isEmpty(caseList)) { if (CollectionUtils.isEmpty(caseList)) {
apiDefinition.setToBeUpdated(false); apiDefinition.setToBeUpdated(false);
} else { } else {

View File

@ -1304,7 +1304,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
List<ApiTestCaseWithBLOBs> oldApiTestCases = oldCaseMap.get(definitionWithBLOBs.getId()); List<ApiTestCaseWithBLOBs> oldApiTestCases = oldCaseMap.get(definitionWithBLOBs.getId());
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseNameMap; Map<String, List<ApiTestCaseWithBLOBs>> oldCaseNameMap;
//如果重复用例有多个则覆盖最后的那个 //如果同名重复用例有多个则覆盖最后的那个
if (CollectionUtils.isNotEmpty(oldApiTestCases)) { if (CollectionUtils.isNotEmpty(oldApiTestCases)) {
oldCaseNameMap = oldApiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getName)); oldCaseNameMap = oldApiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getName));
caseNameMap.forEach((name, importCaseWithBLOBs) -> { caseNameMap.forEach((name, importCaseWithBLOBs) -> {
@ -1332,17 +1332,15 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
} }
oldCaseNameMap.remove(name); oldCaseNameMap.remove(name);
} }
});
//不同名的旧数据处理 //不同名的旧数据处理
oldCaseNameMap.forEach((k, v) -> { oldCaseNameMap.forEach((k, v) -> {
if (!StringUtils.equals(k, name)) {
if (CollectionUtils.isNotEmpty(v)) { if (CollectionUtils.isNotEmpty(v)) {
for (ApiTestCaseWithBLOBs apiTestCaseWithBLOBs : v) { for (ApiTestCaseWithBLOBs apiTestCaseWithBLOBs : v) {
apiTestCaseWithBLOBs.setVersionId("old_case"); apiTestCaseWithBLOBs.setVersionId("old_case");
optionDataCases.add(apiTestCaseWithBLOBs); optionDataCases.add(apiTestCaseWithBLOBs);
} }
} }
}
});
}); });
} else { } else {
//否则直接给新增用例赋值新的接口ID //否则直接给新增用例赋值新的接口ID