fix: 接口导入选覆盖时未更新用例
This commit is contained in:
parent
3d12c11929
commit
2eed319309
|
@ -30,7 +30,7 @@ public abstract class PostmanAbstractParserParser<T> extends ApiImportAbstractPa
|
|||
}
|
||||
requestDesc.getAuth(); // todo 认证方式等待优化
|
||||
PostmanUrl url = requestDesc.getUrl();
|
||||
MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), url.getRaw(), requestDesc.getMethod());
|
||||
MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), url == null ? "" : url.getRaw(), requestDesc.getMethod());
|
||||
if (StringUtils.isNotBlank(request.getPath())) {
|
||||
String path = request.getPath().split("\\?")[0];
|
||||
path = parseVariable(path);
|
||||
|
@ -39,7 +39,7 @@ public abstract class PostmanAbstractParserParser<T> extends ApiImportAbstractPa
|
|||
request.setPath("/");
|
||||
}
|
||||
parseBody(request.getBody(), requestDesc);
|
||||
request.setArguments(parseKeyValue(url.getQuery()));
|
||||
request.setArguments(parseKeyValue(url == null ? new ArrayList<>() : url.getQuery()));
|
||||
request.setHeaders(parseKeyValue(requestDesc.getHeader()));
|
||||
addBodyHeader(request);
|
||||
addPreScript(request, requestItem.getEvent());
|
||||
|
|
|
@ -545,31 +545,18 @@ public class ApiDefinitionService {
|
|||
return request;
|
||||
}
|
||||
|
||||
private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession, ApiTestCaseMapper apiTestCaseMapper) {
|
||||
private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession, ApiTestCaseMapper apiTestCaseMapper,
|
||||
ApiTestImportRequest request) {
|
||||
List<ApiTestCaseWithBLOBs> cases = apiImport.getCases();
|
||||
SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest();
|
||||
if (CollectionUtils.isNotEmpty(cases)) {
|
||||
int batchCount = 0;
|
||||
int nextNum = 0;
|
||||
for (int i = 0; i < cases.size(); i++) {
|
||||
ApiTestCaseWithBLOBs item = cases.get(i);
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(item.getApiDefinitionId());
|
||||
if (apiDefinitionWithBLOBs == null) {
|
||||
continue;
|
||||
}
|
||||
nextNum = apiTestCaseService.getNextNum(item.getApiDefinitionId());
|
||||
checkRequest.setName(item.getName());
|
||||
checkRequest.setApiDefinitionId(item.getApiDefinitionId());
|
||||
if (!apiTestCaseService.hasSameCase(checkRequest)) {
|
||||
item.setId(UUID.randomUUID().toString());
|
||||
item.setCreateTime(System.currentTimeMillis());
|
||||
item.setUpdateTime(System.currentTimeMillis());
|
||||
item.setCreateUserId(SessionUtils.getUserId());
|
||||
item.setUpdateUserId(SessionUtils.getUserId());
|
||||
item.setProjectId(SessionUtils.getCurrentProjectId());
|
||||
item.setNum(nextNum);
|
||||
apiTestCaseMapper.insert(item);
|
||||
}
|
||||
insertOrUpdateImportCase(item, request);
|
||||
}
|
||||
if (batchCount % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
|
@ -587,30 +574,45 @@ public class ApiDefinitionService {
|
|||
if (StringUtils.equalsAnyIgnoreCase(apiTestImportRequest.getPlatform(), ApiImportPlatform.Plugin.name(), ApiImportPlatform.Postman.name())) {
|
||||
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
||||
BeanUtils.copyBean(apiTestCase, apiDefinition);
|
||||
apiTestCase.setId(UUID.randomUUID().toString());
|
||||
apiTestCase.setApiDefinitionId(apiDefinition.getId());
|
||||
apiTestCase.setCreateTime(System.currentTimeMillis());
|
||||
apiTestCase.setUpdateTime(System.currentTimeMillis());
|
||||
apiTestCase.setCreateUserId(SessionUtils.getUserId());
|
||||
apiTestCase.setUpdateUserId(SessionUtils.getUserId());
|
||||
apiTestCase.setNum(getNextNum(apiTestCase.getApiDefinitionId()));
|
||||
apiTestCase.setPriority("P0");
|
||||
if (apiTestCase.getName().length() > 255) {
|
||||
apiTestCase.setName(apiTestCase.getName().substring(0, 255));
|
||||
}
|
||||
/* if (!isInsert) {
|
||||
apiTestCase.setName(apiTestCase.getName() + "_" + apiTestCase.getId().substring(0, 5));
|
||||
}*/
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andApiDefinitionIdEqualTo(apiDefinition.getId());
|
||||
apiTestCaseMapper.deleteByExample(example);
|
||||
apiTestCaseMapper.insert(apiTestCase);
|
||||
insertOrUpdateImportCase(apiTestCase, apiTestImportRequest);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("导入创建用例异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertOrUpdateImportCase(ApiTestCaseWithBLOBs apiTestCase, ApiTestImportRequest apiTestImportRequest) {
|
||||
SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest();
|
||||
checkRequest.setName(apiTestCase.getName());
|
||||
checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId());
|
||||
ApiTestCase sameCase = apiTestCaseService.getSameCase(checkRequest);
|
||||
apiTestCase.setUpdateUserId(SessionUtils.getUserId());
|
||||
if (sameCase == null) {
|
||||
apiTestCase.setId(UUID.randomUUID().toString());
|
||||
apiTestCase.setNum(getNextNum(apiTestCase.getApiDefinitionId()));
|
||||
apiTestCase.setCreateTime(System.currentTimeMillis());
|
||||
apiTestCase.setUpdateTime(System.currentTimeMillis());
|
||||
apiTestCase.setCreateUserId(SessionUtils.getUserId());
|
||||
apiTestCase.setProjectId(SessionUtils.getCurrentProjectId());
|
||||
apiTestCaseMapper.insert(apiTestCase);
|
||||
} else if (StringUtils.equals("fullCoverage", apiTestImportRequest.getModeId())) {
|
||||
apiTestCase.setId(sameCase.getId());
|
||||
apiTestCase.setUpdateTime(System.currentTimeMillis());
|
||||
apiTestCase.setCreateTime(null);
|
||||
apiTestCase.setPriority(sameCase.getPriority());
|
||||
apiTestCase.setCreateUserId(sameCase.getCreateUserId());
|
||||
apiTestCase.setNum(sameCase.getNum());
|
||||
apiTestCase.setProjectId(sameCase.getProjectId());
|
||||
apiTestCase.setVersion((sameCase.getVersion() == null ? 0 : sameCase.getVersion()) + 1);
|
||||
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCase);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFileByTestId(String apiId) {
|
||||
ApiTestFileExample apiTestFileExample = new ApiTestFileExample();
|
||||
apiTestFileExample.createCriteria().andTestIdEqualTo(apiId);
|
||||
|
@ -875,7 +877,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(apiImport.getCases())) {
|
||||
importMsCase(apiImport, sqlSession, apiTestCaseMapper);
|
||||
importMsCase(apiImport, sqlSession, apiTestCaseMapper, request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -265,16 +265,24 @@ public class ApiTestCaseService {
|
|||
}
|
||||
|
||||
public Boolean hasSameCase(SaveApiTestCaseRequest request) {
|
||||
if (getSameCase(request) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ApiTestCase getSameCase(SaveApiTestCaseRequest request) {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
ApiTestCaseExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId());
|
||||
if (StringUtils.isNotBlank(request.getId())) {
|
||||
criteria.andIdNotEqualTo(request.getId());
|
||||
}
|
||||
if (apiTestCaseMapper.countByExample(example) > 0) {
|
||||
return true;
|
||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||
return apiTestCases.get(0);
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private ApiTestCase updateTest(SaveApiTestCaseRequest request) {
|
||||
|
|
Loading…
Reference in New Issue