feat(接口测试): 导入的接口名称过长截断

--user=郭雨琦
This commit is contained in:
guoyuqi 2022-07-01 17:53:44 +08:00 committed by xiaomeinvG
parent d50e1c0ee9
commit 18defbfa05
2 changed files with 16 additions and 4 deletions

View File

@ -247,6 +247,9 @@ public class ApiScenarioImportUtil {
test.setUserId(SessionUtils.getUserId());
test.setLatest(true);
test.setOrder(apiDefinitionService.getImportNextOrder(projectId));
if (test.getName().length() > 255) {
test.setName(test.getName().substring(0, 255));
}
apiDefinitionMapper.insert(test);
definitionMap.put(object.getString("path") + object.getString("method") + object.getString("protocol"), test);
return test;
@ -279,6 +282,9 @@ public class ApiScenarioImportUtil {
objectNew.remove("referenced");
apiTestCase.setRequest(objectNew.toJSONString());
apiTestCase.setOrder(apiDefinitionService.getImportNextCaseOrder(projectId));
if (apiTestCase.getName().length() > 255) {
apiTestCase.setName(apiTestCase.getName().substring(0, 255));
}
apiTestCaseMapper.insert(apiTestCase);
}

View File

@ -1131,11 +1131,12 @@ public class ApiDefinitionService {
int batchCount = 0;
for (int i = 0; i < cases.size(); i++) {
ApiTestCaseWithBLOBs item = cases.get(i);
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(item.getApiDefinitionId());
if (apiDefinitionWithBLOBs == null) {
List<ApiDefinitionWithBLOBs> data = apiImport.getData();
List<ApiDefinitionWithBLOBs> collect = data.stream().filter(t -> t.getId().equals(item.getApiDefinitionId())).collect(toList());
if (collect.isEmpty()) {
continue;
}
insertOrUpdateImportCase(item, request, apiDefinitionWithBLOBs, apiTestCaseMapper);
insertOrUpdateImportCase(item, request, collect.get(0), apiTestCaseMapper);
}
if (batchCount % 300 == 0) {
sqlSession.flushStatements();
@ -1166,7 +1167,12 @@ public class ApiDefinitionService {
private void insertOrUpdateImportCase(ApiTestCaseWithBLOBs apiTestCase, ApiTestImportRequest apiTestImportRequest, ApiDefinitionWithBLOBs apiDefinition, ApiTestCaseMapper apiTestCaseMapper) {
SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest();
checkRequest.setName(apiTestCase.getName());
if (apiTestCase.getName().length() > 255) {
apiTestCase.setName(apiTestCase.getName().substring(0, 255));
checkRequest.setName(apiTestCase.getName().substring(0, 255));
} else {
checkRequest.setName(apiTestCase.getName());
}
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
checkRequest.setId(apiTestCase.getId());
ApiTestCase sameCase = apiTestCaseService.getSameCase(checkRequest);