fix(接口测试): 解决选择模块导入不覆盖时多创建的空模块问题

--user=郭雨琦
--bug=1014706
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014706
This commit is contained in:
guoyuqi 2022-07-07 10:20:40 +08:00 committed by xiaomeinvG
parent ae4743850d
commit a2debaf981
2 changed files with 71 additions and 12 deletions

View File

@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -677,7 +678,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
} else { } else {
//不覆盖,同一接口不做更新 //不覆盖,同一接口不做更新
if (!repeatApiDefinitionWithBLOBs.isEmpty()) { if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatMap, optionMap, optionData); removeSameData(repeatMap, optionMap, optionData, moduleMap);
} }
} }
} }
@ -707,7 +708,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
cover(moduleMap, toUpdateList, optionMap, repeatMap); cover(moduleMap, toUpdateList, optionMap, repeatMap);
} else { } else {
//不覆盖,同一接口不做更新 //不覆盖,同一接口不做更新
removeRepeat(optionData, optionMap, repeatMap); removeRepeat(optionData, optionMap, repeatMap, moduleMap);
} }
} }
} }
@ -740,7 +741,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
} }
} else { } else {
//不覆盖 //不覆盖
removeRepeat(optionData, nameModuleMap, repeatDataMap); removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap);
} }
return moduleMap; return moduleMap;
} }
@ -754,12 +755,21 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
return updateApiModuleDTO; return updateApiModuleDTO;
} }
private void removeRepeat(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) { private void removeRepeat(List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap, Map<String, ApiModule> moduleMap) {
if (nameModuleMap != null) { if (nameModuleMap != null) {
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap; Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap;
repeatDataMap.forEach((k, v) -> { repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k); ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k);
if (apiDefinitionWithBLOBs != null) { if (apiDefinitionWithBLOBs != null) {
String modulePath = apiDefinitionWithBLOBs.getModulePath();
List<ApiDefinitionWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
if (moduleDatas != null) {
if (moduleDatas.size() <= 1) {
moduleMap.remove(modulePath);
removeModulePath(moduleMap, moduleOptionData, modulePath);
}
}
optionData.remove(apiDefinitionWithBLOBs); optionData.remove(apiDefinitionWithBLOBs);
} }
}); });
@ -865,7 +875,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
} else { } else {
//不覆盖,同一接口不做更新 //不覆盖,同一接口不做更新
if (!repeatApiDefinitionWithBLOBs.isEmpty()) { if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatDataMap, methodPathMap, optionData); removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap);
} }
} }
return moduleMap; return moduleMap;
@ -903,7 +913,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
} else { } else {
//不覆盖,同一接口不做更新 //不覆盖,同一接口不做更新
if (!repeatApiDefinitionWithBLOBs.isEmpty()) { if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
removeSameData(repeatDataMap, methodPathMap, optionData); removeSameData(repeatDataMap, methodPathMap, optionData, moduleMap);
} }
} }
return moduleMap; return moduleMap;
@ -962,13 +972,37 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
return updateVersionId; return updateVersionId;
} }
private void removeSameData(Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, List<ApiDefinitionWithBLOBs> optionData) { private void removeSameData(Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap, Map<String, ApiDefinitionWithBLOBs> methodPathMap, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiModule> moduleMap) {
repeatDataMap.forEach((k, v) -> { Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
BiConsumer<String, List<ApiDefinitionWithBLOBs>> stringListBiConsumer = (k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k); ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k);
if (apiDefinitionWithBLOBs != null) { if (apiDefinitionWithBLOBs != null) {
String modulePath = apiDefinitionWithBLOBs.getModulePath();
List<ApiDefinitionWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
if (moduleDatas != null) {
if (moduleDatas.size() <= 1) {
moduleMap.remove(modulePath);
removeModulePath(moduleMap, moduleOptionData, modulePath);
}
}
optionData.remove(apiDefinitionWithBLOBs); optionData.remove(apiDefinitionWithBLOBs);
} }
}); };
repeatDataMap.forEach(stringListBiConsumer);
}
private void removeModulePath(Map<String, ApiModule> moduleMap, Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData, String modulePath) {
if (StringUtils.isBlank(modulePath)) {
return;
}
String[] pathTree = getPathTree(modulePath);
String lastPath = pathTree[pathTree.length - 1];
String substring = modulePath.substring(0, modulePath.indexOf("/" + lastPath));
if (moduleOptionData.get(substring) == null || moduleOptionData.get(substring).size() == 0) {
moduleMap.remove(substring);
removeModulePath(moduleMap, moduleOptionData, substring);
}
} }
private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap) { private void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap) {

View File

@ -534,7 +534,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
startCover(toUpdateList, optionMap, repeatMap); startCover(toUpdateList, optionMap, repeatMap);
} else { } else {
//不覆盖,同一接口不做更新 //不覆盖,同一接口不做更新
removeRepeat(optionData, optionMap, repeatMap); removeRepeat(optionData, optionMap, repeatMap, moduleMap);
} }
} }
@ -573,7 +573,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
} }
} else { } else {
//不覆盖 //不覆盖
removeRepeat(optionData, nameModuleMap, repeatDataMap); removeRepeat(optionData, nameModuleMap, repeatDataMap, moduleMap);
} }
return moduleMap; return moduleMap;
} }
@ -595,17 +595,42 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
versionSet.add(updateVersionId); versionSet.add(updateVersionId);
} }
private void removeRepeat(List<ApiScenarioWithBLOBs> optionData, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) { private void removeRepeat(List<ApiScenarioWithBLOBs> optionData, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap, Map<String, ApiScenarioModule> moduleMap) {
if (repeatDataMap != null) { if (repeatDataMap != null) {
Map<String, List<ApiScenarioWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiScenario::getModulePath));
repeatDataMap.forEach((k, v) -> { repeatDataMap.forEach((k, v) -> {
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k); ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
if (apiScenarioWithBLOBs != null) { if (apiScenarioWithBLOBs != null) {
if (apiScenarioWithBLOBs != null) {
String modulePath = apiScenarioWithBLOBs.getModulePath();
List<ApiScenarioWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
if (moduleDatas != null) {
if (moduleDatas.size() <= 1) {
moduleMap.remove(modulePath);
removeModulePath(moduleMap, moduleOptionData, modulePath);
}
}
}
optionData.remove(apiScenarioWithBLOBs); optionData.remove(apiScenarioWithBLOBs);
} }
}); });
} }
} }
private void removeModulePath(Map<String, ApiScenarioModule> moduleMap, Map<String, List<ApiScenarioWithBLOBs>> moduleOptionData, String modulePath) {
if (StringUtils.isBlank(modulePath)) {
return;
}
String[] pathTree = getTagTree(modulePath);
String lastPath = pathTree[pathTree.length - 1];
String substring = modulePath.substring(0, modulePath.indexOf("/" + lastPath));
if (moduleOptionData.get(substring) == null || moduleOptionData.get(substring).size() == 0) {
moduleMap.remove(substring);
removeModulePath(moduleMap, moduleOptionData, substring);
}
}
private void startCover(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) { private void startCover(List<ApiScenarioWithBLOBs> toUpdateList, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) {
repeatDataMap.forEach((k, v) -> { repeatDataMap.forEach((k, v) -> {
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k); ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);