fix(接口测试): 插件导入默认生成case问题

--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001016605
This commit is contained in:
guoyuqi 2022-09-07 14:34:29 +08:00 committed by xiaomeinvG
parent ee553a8992
commit f6e5d0a8ed
3 changed files with 17 additions and 10 deletions

View File

@ -39,4 +39,6 @@ public class ApiTestImportRequest {
private Boolean coverModule; private Boolean coverModule;
// 当前协议 // 当前协议
private String protocol; private String protocol;
//上传文件来源目前用于辨别是否是idea插件
private String origin;
} }

View File

@ -25,6 +25,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) { public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
String testStr = getApiTestStr(source); String testStr = getApiTestStr(source);
this.projectId = request.getProjectId(); this.projectId = request.getProjectId();
boolean addCase = !StringUtils.equals("idea", request.getOrigin());
JSONObject jsonObject = JSON.parseObject(testStr); JSONObject jsonObject = JSON.parseObject(testStr);
Object info = jsonObject.get("info"); Object info = jsonObject.get("info");
if (info == null) { if (info == null) {
@ -40,14 +41,14 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
} }
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>(); List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
parseItem(postmanCollection.getItem(), modulePath, results, parseItem(postmanCollection.getItem(), modulePath, results,
cases); cases, addCase);
apiImport.setData(results); apiImport.setData(results);
apiImport.setCases(cases); apiImport.setCases(cases);
return apiImport; return apiImport;
} }
protected void parseItem(List<PostmanItem> items, String modulePath, List<ApiDefinitionWithBLOBs> results, protected void parseItem(List<PostmanItem> items, String modulePath, List<ApiDefinitionWithBLOBs> results,
List<ApiTestCaseWithBLOBs> cases) { List<ApiTestCaseWithBLOBs> cases, boolean addCase) {
for (PostmanItem item : items) { for (PostmanItem item : items) {
List<PostmanItem> childItems = item.getItem(); List<PostmanItem> childItems = item.getItem();
if (childItems != null) { if (childItems != null) {
@ -57,7 +58,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
} else { } else {
itemModulePath = item.getName(); itemModulePath = item.getName();
} }
parseItem(childItems, itemModulePath, results, cases); parseItem(childItems, itemModulePath, results, cases, addCase);
} else { } else {
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item); MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
HttpResponse response = parsePostmanResponse(item); HttpResponse response = parsePostmanResponse(item);
@ -71,11 +72,13 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
request.setModulePath(modulePath); request.setModulePath(modulePath);
} }
results.add(request); results.add(request);
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs(); if (addCase) {
BeanUtils.copyBean(apiTestCase, request); ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
apiTestCase.setApiDefinitionId(request.getId()); BeanUtils.copyBean(apiTestCase, request);
apiTestCase.setPriority("P0"); apiTestCase.setApiDefinitionId(request.getId());
cases.add(apiTestCase); apiTestCase.setPriority("P0");
cases.add(apiTestCase);
}
} }
} }
} }

View File

@ -937,7 +937,8 @@ public class ApiDefinitionService {
} }
boolean newCreate = !StringUtils.equals(ApiImportPlatform.Swagger2.name(), apiDefinitionImportParamDTO.getApiTestImportRequest().getPlatform()) boolean newCreate = !StringUtils.equals(ApiImportPlatform.Swagger2.name(), apiDefinitionImportParamDTO.getApiTestImportRequest().getPlatform())
&& !StringUtils.isNotBlank(apiDefinitionImportParamDTO.getApiTestImportRequest().getSwaggerUrl()); && !StringUtils.isNotBlank(apiDefinitionImportParamDTO.getApiTestImportRequest().getSwaggerUrl())
&& !StringUtils.equals("idea", apiDefinitionImportParamDTO.getApiTestImportRequest().getOrigin());
caseList = setRequestAndAddNewCase(apiDefinition, caseList, newCreate); caseList = setRequestAndAddNewCase(apiDefinition, caseList, newCreate);
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum()); reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
batchMapper.insert(apiDefinition); batchMapper.insert(apiDefinition);
@ -1074,7 +1075,8 @@ public class ApiDefinitionService {
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum()); reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
boolean newCreate = !StringUtils.equals(ApiImportPlatform.Swagger2.name(), apiDefinitionImportParamDTO.getApiTestImportRequest().getPlatform()) boolean newCreate = !StringUtils.equals(ApiImportPlatform.Swagger2.name(), apiDefinitionImportParamDTO.getApiTestImportRequest().getPlatform())
&& !StringUtils.isNotBlank(apiDefinitionImportParamDTO.getApiTestImportRequest().getSwaggerUrl()); && !StringUtils.isNotBlank(apiDefinitionImportParamDTO.getApiTestImportRequest().getSwaggerUrl())
&& !StringUtils.equals("idea", apiDefinitionImportParamDTO.getApiTestImportRequest().getOrigin());
caseList = setRequestAndAddNewCase(apiDefinition, caseList, newCreate); caseList = setRequestAndAddNewCase(apiDefinition, caseList, newCreate);
batchMapper.insert(apiDefinition); batchMapper.insert(apiDefinition);
ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false); ApiDefinitionResult apiDefinitionResult = getApiDefinitionResult(apiDefinition, false);