fix(接口测试): 修复接口导入用例ID生成问题

--user=郭雨琦
--bug=1014868
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014868
This commit is contained in:
guoyuqi 2022-07-28 11:58:37 +08:00 committed by xiaomeinvG
parent 042eb5d2bc
commit b5ec329860
2 changed files with 6 additions and 5 deletions

View File

@ -967,12 +967,10 @@ public class ApiDefinitionService {
} else {
apiDefinition.setVersionId(apiTestImportRequest.getDefaultVersion());
}
batchMapper.insert(apiDefinition);
String requestStr = setImportHashTree(apiDefinition);
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
apiDefinition.setRequest(requestStr);
batchMapper.insert(apiDefinition);
importCase(apiDefinition, apiTestCaseMapper, caseList);
extApiDefinitionMapper.clearLatestVersion(apiDefinition.getRefId());
extApiDefinitionMapper.addLatestVersion(apiDefinition.getRefId());
@ -1085,9 +1083,9 @@ public class ApiDefinitionService {
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) {
batchMapper.insert(apiDefinition);
String request = setImportHashTree(apiDefinition);
apiDefinition.setRequest(request);
batchMapper.insert(apiDefinition);
} else {
if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) {
setImportTCPHashTree(apiDefinition);

View File

@ -650,7 +650,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
//导入的case,导入的接口是有ID的所以导入的case已经标记过一遍接口ID了,这里是处理覆盖时接口ID的变动
List<ApiTestCaseWithBLOBs> importCases = apiImport.getCases();
List<ApiTestCaseWithBLOBs> optionDataCases = new ArrayList<>();
//将ID全部置于null,覆盖的时候会增加ID用以区分更新还是新增
//将ID,num全部置于null,覆盖的时候会增加ID用以区分更新还是新增
removeRepeatCase(fullCoverage, importCases, optionDataCases);
Map<String, List<ApiTestCaseWithBLOBs>> definitionIdCaseMAp = optionDataCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId));
@ -832,11 +832,13 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
if (fullCoverage) {
apiIdNameMap.forEach((k, v) -> {
v.get(v.size() - 1).setId(null);
v.get(v.size() - 1).setNum(null);
optionDataCases.add(v.get(v.size() - 1));
});
} else {
apiIdNameMap.forEach((k, v) -> {
v.get(0).setId(null);
v.get(0).setNum(null);
optionDataCases.add(v.get(0));
});
}
@ -1188,6 +1190,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs1 = oldCaseNameMap.get(name);
if (apiTestCaseWithBLOBs1 != null) {
caseWithBLOBs1.setId(apiTestCaseWithBLOBs1.getId());
caseWithBLOBs1.setNum(apiTestCaseWithBLOBs1.getNum());
caseWithBLOBs1.setVersion(apiTestCaseWithBLOBs1.getVersion() == null ? 0 : apiTestCaseWithBLOBs1.getVersion() + 1);
//这里是用这个属性做一个临时标记表明这个case已被覆盖不需要同步
caseWithBLOBs1.setVersionId("cover");