refactor(接口测试): 接口重复下接口导入的逻辑修改

--bug=1020875 --user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001020875
This commit is contained in:
guoyuqi 2022-12-16 17:32:50 +08:00 committed by fit2-zhao
parent f7459c19f1
commit df00135286
1 changed files with 11 additions and 23 deletions

View File

@ -320,9 +320,8 @@ public class ApiDefinitionImportUtilService {
String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId);
//这样的过滤规则下可能存在重复接口如果是覆盖模块需要按照去重规则再次去重否则就加上接口原有的模块
if (fullCoverage) {
List<ApiDefinitionWithBLOBs> singleOptionData = new ArrayList<>();
removeHttpChooseModuleRepeat(optionData, singleOptionData, chooseModulePath);
optionData = singleOptionData;
removeHttpChooseModuleRepeat(optionData, chooseModulePath);
// optionData = singleOptionData;
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api));
} else {
getChooseModuleUrlRepeatOptionMap(optionData, optionMap, chooseModulePath);
@ -359,19 +358,6 @@ public class ApiDefinitionImportUtilService {
removeSameData(repeatDataMap, optionMap, optionData, moduleMap, optionDataCases);
}
}
//最后在整个体统内检查一遍防止在有选择的模块时未找到重复直接创建的情况
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath())));
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath()), api -> api));
if (fullCoverage) {
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,null);
} else {
//不覆盖,同一接口不做更新
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
removeSameData(repeatDataMap, optionMap, optionData, moduleMap, optionDataCases);
}
}
}
//将原来的case和更改的case组合在一起为了同步的设置
List<String> caseIds = optionDataCases.stream().map(ApiTestCase::getId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
buildCases(optionDataCases, oldCaseMap, caseIds);
@ -462,18 +448,20 @@ public class ApiDefinitionImportUtilService {
return s;
}
private static void removeHttpChooseModuleRepeat(List<ApiDefinitionWithBLOBs> optionData, List<ApiDefinitionWithBLOBs> singleOptionData, String chooseModulePath) {
private static void removeHttpChooseModuleRepeat(List<ApiDefinitionWithBLOBs> optionData, String chooseModulePath) {
LinkedHashMap<String, List<ApiDefinitionWithBLOBs>> methodPathMap = optionData.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), LinkedHashMap::new, Collectors.toList()));
methodPathMap.forEach((k, v) -> singleOptionData.add(v.get(v.size() - 1)));
methodPathMap.forEach((k, v) -> {
if (v.size() > 1) {
for (int i = 0; i < v.size() - 1; i++) {
optionData.remove(v.get(i));
}
}
});
}
private static void getChooseModuleUrlRepeatOptionMap(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> optionMap, String chooseModulePath) {
for (ApiDefinitionWithBLOBs optionDatum : optionData) {
if (optionDatum.getModulePath() == null) {
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(chooseModulePath), optionDatum);
} else {
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(chooseModulePath).concat(optionDatum.getModulePath()), optionDatum);
}
optionMap.put(optionDatum.getName().concat(optionDatum.getMethod()).concat(optionDatum.getPath()).concat(chooseModulePath), optionDatum);
}
}