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) {
|
for (ApiTestCaseWithBLOBs apiTestCaseWithBLOBs : caseList) {
|
||||||
apiTestCaseWithBLOBs.setApiDefinitionId(apiDefinition.getId());
|
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());
|
apiTestCaseWithBLOBs.setVersionId(apiDefinition.getVersionId());
|
||||||
if (apiTestCaseWithBLOBs.getCreateTime() == null) {
|
if (apiTestCaseWithBLOBs.getCreateTime() == null) {
|
||||||
apiTestCaseWithBLOBs.setCreateTime(System.currentTimeMillis());
|
apiTestCaseWithBLOBs.setCreateTime(System.currentTimeMillis());
|
||||||
|
@ -1012,9 +1018,6 @@ public class ApiDefinitionService {
|
||||||
apiTestCaseWithBLOBs.setNum(testCaseService.getNextNum(apiDefinition.getId()));
|
apiTestCaseWithBLOBs.setNum(testCaseService.getNextNum(apiDefinition.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiDefinition.getToBeUpdated() != null) {
|
|
||||||
apiTestCaseWithBLOBs.setToBeUpdated(apiDefinition.getToBeUpdated());
|
|
||||||
}
|
|
||||||
if (apiDefinition.getToBeUpdateTime() != null) {
|
if (apiDefinition.getToBeUpdateTime() != null) {
|
||||||
apiTestCaseWithBLOBs.setToBeUpdateTime(apiDefinition.getToBeUpdateTime());
|
apiTestCaseWithBLOBs.setToBeUpdateTime(apiDefinition.getToBeUpdateTime());
|
||||||
}
|
}
|
||||||
|
@ -1146,8 +1149,15 @@ 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 (StringUtils.isBlank(apiDefinition.getCaseTotal()) || Integer.parseInt(apiDefinition.getCaseTotal()) == 0) {
|
if (CollectionUtils.isEmpty(caseList)) {
|
||||||
apiDefinition.setToBeUpdated(false);
|
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 {
|
} else {
|
||||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||||
|
|
|
@ -615,6 +615,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||||
if (apiImport.getEsbApiParamsMap() != null) {
|
if (apiImport.getEsbApiParamsMap() != null) {
|
||||||
fullCoverage = true;
|
fullCoverage = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String updateVersionId = getUpdateVersionId(request);
|
String updateVersionId = getUpdateVersionId(request);
|
||||||
|
@ -783,9 +784,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
//处理数据
|
//处理数据
|
||||||
if (fullCoverage) {
|
if (fullCoverage) {
|
||||||
if (fullCoverageApi) {
|
if (fullCoverageApi) {
|
||||||
coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||||
} else {
|
} else {
|
||||||
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||||
}
|
}
|
||||||
} else {
|
} 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> 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));
|
Map<String, ApiDefinitionWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
|
||||||
if (fullCoverage) {
|
if (fullCoverage) {
|
||||||
cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap);
|
cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap());
|
||||||
} else {
|
} else {
|
||||||
//不覆盖,同一接口不做更新
|
//不覆盖,同一接口不做更新
|
||||||
removeRepeat(optionData, optionMap, repeatMap, moduleMap, versionId, definitionIdCaseMAp, optionDataCases);
|
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,
|
private Map<String, ApiModule> cover(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList,
|
||||||
Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap,
|
Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap,
|
||||||
String updateVersionId, Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp,
|
String updateVersionId, Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp,
|
||||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
|
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||||
//覆盖但不覆盖模块
|
//覆盖但不覆盖模块
|
||||||
if (nameModuleMap != null) {
|
if (nameModuleMap != null) {
|
||||||
//导入文件没有新增接口无需创建接口模块
|
//导入文件没有新增接口无需创建接口模块
|
||||||
|
@ -921,6 +922,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
}
|
}
|
||||||
//该接口的case
|
//该接口的case
|
||||||
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
||||||
|
updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId());
|
||||||
apiDefinitionWithBLOBs.setId(v.getId());
|
apiDefinitionWithBLOBs.setId(v.getId());
|
||||||
apiDefinitionWithBLOBs.setVersionId(updateVersionId);
|
apiDefinitionWithBLOBs.setVersionId(updateVersionId);
|
||||||
apiDefinitionWithBLOBs.setModuleId(v.getModuleId());
|
apiDefinitionWithBLOBs.setModuleId(v.getModuleId());
|
||||||
|
@ -943,6 +945,17 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
return moduleMap;
|
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) {
|
private Map<String, ApiModule> judgeModule(Map<String, ApiModule> moduleMap, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
|
||||||
AtomicBoolean remove = new AtomicBoolean(true);
|
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,
|
private void coverModule(List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap,
|
||||||
Map<String, ApiDefinitionWithBLOBs> repeatDataMap, String updateVersionId, Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp,
|
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) {
|
if (nameModuleMap != null) {
|
||||||
repeatDataMap.forEach((k, v) -> {
|
repeatDataMap.forEach((k, v) -> {
|
||||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
|
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
|
||||||
|
@ -974,6 +987,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
}
|
}
|
||||||
//该接口的case
|
//该接口的case
|
||||||
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
Map<String, ApiTestCaseWithBLOBs> caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs);
|
||||||
|
updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId());
|
||||||
apiDefinitionWithBLOBs.setId(v.getId());
|
apiDefinitionWithBLOBs.setId(v.getId());
|
||||||
setApiParam(apiDefinitionWithBLOBs, updateVersionId, v);
|
setApiParam(apiDefinitionWithBLOBs, updateVersionId, v);
|
||||||
//组合case
|
//组合case
|
||||||
|
@ -1175,6 +1189,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
if (apiTestCaseWithBLOBs1 != null) {
|
if (apiTestCaseWithBLOBs1 != null) {
|
||||||
caseWithBLOBs1.setId(apiTestCaseWithBLOBs1.getId());
|
caseWithBLOBs1.setId(apiTestCaseWithBLOBs1.getId());
|
||||||
caseWithBLOBs1.setVersion(apiTestCaseWithBLOBs1.getVersion() == null ? 0 : apiTestCaseWithBLOBs1.getVersion() + 1);
|
caseWithBLOBs1.setVersion(apiTestCaseWithBLOBs1.getVersion() == null ? 0 : apiTestCaseWithBLOBs1.getVersion() + 1);
|
||||||
|
//这里是用这个属性做一个临时标记,表明这个case已被覆盖,不需要同步
|
||||||
|
caseWithBLOBs1.setVersionId("cover");
|
||||||
oldCaseNameMap.remove(name);
|
oldCaseNameMap.remove(name);
|
||||||
} else {
|
} else {
|
||||||
caseWithBLOBs1.setVersion(0);
|
caseWithBLOBs1.setVersion(0);
|
||||||
|
|
Loading…
Reference in New Issue