refactor(接口测试): 接口导入同步状态优化以及esb导入优化
--user=郭雨琦 --bug=1015240 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015240 --bug=1015178 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015178
This commit is contained in:
parent
4fbe42ee81
commit
0037bffce8
|
@ -993,6 +993,12 @@ public class ApiDefinitionService {
|
|||
}
|
||||
for (ApiTestCaseWithBLOBs apiTestCaseWithBLOBs : caseList) {
|
||||
apiTestCaseWithBLOBs.setApiDefinitionId(apiDefinition.getId());
|
||||
if (apiDefinition.getToBeUpdated() != null && !apiTestCaseWithBLOBs.getVersionId().equals("cover")) {
|
||||
apiTestCaseWithBLOBs.setToBeUpdated(true);
|
||||
//TODO:check setting
|
||||
} else {
|
||||
apiTestCaseWithBLOBs.setToBeUpdated(false);
|
||||
}
|
||||
apiTestCaseWithBLOBs.setVersionId(apiDefinition.getVersionId());
|
||||
if (apiTestCaseWithBLOBs.getCreateTime() == null) {
|
||||
apiTestCaseWithBLOBs.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -1012,9 +1018,6 @@ public class ApiDefinitionService {
|
|||
apiTestCaseWithBLOBs.setNum(testCaseService.getNextNum(apiDefinition.getId()));
|
||||
}
|
||||
|
||||
if (apiDefinition.getToBeUpdated() != null) {
|
||||
apiTestCaseWithBLOBs.setToBeUpdated(apiDefinition.getToBeUpdated());
|
||||
}
|
||||
if (apiDefinition.getToBeUpdateTime() != null) {
|
||||
apiTestCaseWithBLOBs.setToBeUpdateTime(apiDefinition.getToBeUpdateTime());
|
||||
}
|
||||
|
@ -1146,8 +1149,15 @@ public class ApiDefinitionService {
|
|||
} else if (apiTestImportRequest.getCoverModule() != null && apiTestImportRequest.getCoverModule()) {
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
}
|
||||
if (StringUtils.isBlank(apiDefinition.getCaseTotal()) || Integer.parseInt(apiDefinition.getCaseTotal()) == 0) {
|
||||
if (CollectionUtils.isEmpty(caseList)) {
|
||||
apiDefinition.setToBeUpdated(false);
|
||||
} else {
|
||||
List<ApiTestCaseWithBLOBs> cover = caseList.stream().filter(t -> !t.getVersionId().equals("cover") && StringUtils.isNotBlank(t.getId())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(cover)) {
|
||||
apiDefinition.setToBeUpdated(false);
|
||||
} else {
|
||||
apiDefinition.setToBeUpdated(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
|
|
|
@ -615,6 +615,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
fullCoverage = true;
|
||||
|
||||
}
|
||||
|
||||
String updateVersionId = getUpdateVersionId(request);
|
||||
|
@ -783,9 +784,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
||||
coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||
} else {
|
||||
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
||||
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
|
@ -796,7 +797,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
Map<String, ApiDefinitionWithBLOBs> repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
Map<String, ApiDefinitionWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||
if (fullCoverage) {
|
||||
cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
||||
cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap, versionId, definitionIdCaseMAp, optionDataCases);
|
||||
|
@ -906,7 +907,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
private Map<String, ApiModule> cover(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList,
|
||||
Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap,
|
||||
String updateVersionId, Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp,
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||
//覆盖但不覆盖模块
|
||||
if (nameModuleMap != null) {
|
||||
//导入文件没有新增接口无需创建接口模块
|
||||
|
@ -921,6 +922,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
//该接口的case
|
||||
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
||||
updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId());
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
apiDefinitionWithBLOBs.setVersionId(updateVersionId);
|
||||
apiDefinitionWithBLOBs.setModuleId(v.getModuleId());
|
||||
|
@ -943,6 +945,17 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
return moduleMap;
|
||||
}
|
||||
|
||||
private void updateEsb(Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap, String newId, String oldId) {
|
||||
if (MapUtils.isNotEmpty(esbApiParamsMap)) {
|
||||
EsbApiParamsWithBLOBs esbApiParamsWithBLOBs = esbApiParamsMap.get(oldId);
|
||||
if (esbApiParamsWithBLOBs != null) {
|
||||
esbApiParamsMap.remove(oldId);
|
||||
esbApiParamsWithBLOBs.setResourceId(newId);
|
||||
esbApiParamsMap.put(newId, esbApiParamsWithBLOBs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ApiModule> judgeModule(Map<String, ApiModule> moduleMap, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
|
||||
AtomicBoolean remove = new AtomicBoolean(true);
|
||||
|
||||
|
@ -962,7 +975,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
|
||||
private void coverModule(List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap,
|
||||
Map<String, ApiDefinitionWithBLOBs> repeatDataMap, String updateVersionId, Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp,
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||
if (nameModuleMap != null) {
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
|
||||
|
@ -974,6 +987,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
}
|
||||
//该接口的case
|
||||
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
||||
updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId());
|
||||
apiDefinitionWithBLOBs.setId(v.getId());
|
||||
setApiParam(apiDefinitionWithBLOBs, updateVersionId, v);
|
||||
//组合case
|
||||
|
@ -1175,6 +1189,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (apiTestCaseWithBLOBs1 != null) {
|
||||
caseWithBLOBs1.setId(apiTestCaseWithBLOBs1.getId());
|
||||
caseWithBLOBs1.setVersion(apiTestCaseWithBLOBs1.getVersion() == null ? 0 : apiTestCaseWithBLOBs1.getVersion() + 1);
|
||||
//这里是用这个属性做一个临时标记,表明这个case已被覆盖,不需要同步
|
||||
caseWithBLOBs1.setVersionId("cover");
|
||||
oldCaseNameMap.remove(name);
|
||||
} else {
|
||||
caseWithBLOBs1.setVersion(0);
|
||||
|
|
Loading…
Reference in New Issue