fix(接口测试): 解决其他协议在没有任何接口时导入会报错问题

This commit is contained in:
guoyuqi 2022-10-13 10:37:49 +08:00 committed by xiaomeinvG
parent 079b569742
commit 660df9a548
1 changed files with 28 additions and 26 deletions

View File

@ -1013,33 +1013,35 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Map<String, ApiDefinitionWithBLOBs> repeatDataMap, Map<String, ApiModule> moduleMap,
String versionId,
List<ApiTestCaseWithBLOBs> optionDataCases) {
if (nameModuleMap != null) {
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionDatas.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
if (apiDefinitionWithBLOBs != null) {
Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp = optionDataCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
List<ApiTestCaseWithBLOBs> distinctNameCases = definitionIdCaseMAp.get(apiDefinitionWithBLOBs.getId());
String modulePath = apiDefinitionWithBLOBs.getModulePath();
List<ApiDefinitionWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
if (moduleDatas != null && moduleDatas.size() <= 1) {
moduleMap.remove(modulePath);
removeModulePath(moduleMap, moduleOptionData, modulePath);
moduleDatas.remove(apiDefinitionWithBLOBs);
}
//不覆盖选择版本如果被选版本有同接口不导入否则创建新版本接口
if (v.getVersionId().equals(versionId)) {
optionDatas.remove(apiDefinitionWithBLOBs);
if (CollectionUtils.isNotEmpty(distinctNameCases)) {
distinctNameCases.forEach(optionDataCases::remove);
}
} else {
//这里是为了标识当前数据是需要创建版本的不是全新增的数据
addNewVersionApi(apiDefinitionWithBLOBs, v, "new");
}
}
});
if (MapUtils.isEmpty(nameModuleMap) || MapUtils.isEmpty(repeatDataMap)) {
return;
}
Map<String, List<ApiDefinitionWithBLOBs>> moduleOptionData = optionDatas.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath));
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
if (apiDefinitionWithBLOBs == null){
return;
}
Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp = optionDataCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
List<ApiTestCaseWithBLOBs> distinctNameCases = definitionIdCaseMAp.get(apiDefinitionWithBLOBs.getId());
String modulePath = apiDefinitionWithBLOBs.getModulePath();
List<ApiDefinitionWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
if (moduleDatas != null && moduleDatas.size() <= 1) {
moduleMap.remove(modulePath);
removeModulePath(moduleMap, moduleOptionData, modulePath);
moduleDatas.remove(apiDefinitionWithBLOBs);
}
//不覆盖选择版本如果被选版本有同接口不导入否则创建新版本接口
if (v.getVersionId().equals(versionId)) {
optionDatas.remove(apiDefinitionWithBLOBs);
if (CollectionUtils.isNotEmpty(distinctNameCases)) {
distinctNameCases.forEach(optionDataCases::remove);
}
} else {
//这里是为了标识当前数据是需要创建版本的不是全新增的数据
addNewVersionApi(apiDefinitionWithBLOBs, v, "new");
}
});
}
private void addNewVersionApi(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs, ApiDefinitionWithBLOBs v, String version) {