fix(接口测试): 非HTTP接口重名校验
--bug=1046273 --user=陈建星 【接口测试】TCP请求-未校验同名接口-两个TCP接口名称一样保存成功了 https://www.tapd.cn/55049933/s/1579907
This commit is contained in:
parent
8dd0fe9e30
commit
2b4a5fcda3
|
@ -261,9 +261,8 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
BeanUtils.copyBean(apiDefinition, request);
|
||||
apiDefinition.setTags(ServiceUtils.parseTags(apiDefinition.getTags()));
|
||||
checkResponseNameCode(request.getResponse());
|
||||
if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) {
|
||||
checkUpdateExist(apiDefinition, originApiDefinition);
|
||||
}
|
||||
checkUpdateExist(apiDefinition, originApiDefinition);
|
||||
|
||||
apiDefinition.setUpdateUser(userId);
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
|
@ -537,39 +536,59 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
}
|
||||
|
||||
private void checkAddExist(ApiDefinition apiDefinition) {
|
||||
if (!StringUtils.equals(apiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||
return;
|
||||
}
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria()
|
||||
.andPathEqualTo(apiDefinition.getPath())
|
||||
.andMethodEqualTo(apiDefinition.getMethod())
|
||||
.andProtocolEqualTo(apiDefinition.getProtocol())
|
||||
.andProjectIdEqualTo(apiDefinition.getProjectId())
|
||||
.andDeletedEqualTo(false);
|
||||
if (StringUtils.equals(apiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||
example.createCriteria()
|
||||
.andPathEqualTo(apiDefinition.getPath())
|
||||
.andMethodEqualTo(apiDefinition.getMethod())
|
||||
.andProtocolEqualTo(apiDefinition.getProtocol())
|
||||
.andProjectIdEqualTo(apiDefinition.getProjectId())
|
||||
.andDeletedEqualTo(false);
|
||||
} else {
|
||||
example.createCriteria()
|
||||
.andNameEqualTo(apiDefinition.getName())
|
||||
.andProtocolEqualTo(apiDefinition.getProtocol())
|
||||
.andModuleIdEqualTo(apiDefinition.getModuleId())
|
||||
.andProjectIdEqualTo(apiDefinition.getProjectId())
|
||||
.andDeletedEqualTo(false);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(apiDefinitionMapper.selectByExample(example))) {
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdateExist(ApiDefinition apiDefinition, ApiDefinition originApiDefinition) {
|
||||
if (!StringUtils.equals(originApiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(apiDefinition.getPath()) || StringUtils.isNotEmpty(apiDefinition.getMethod())) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
String method = StringUtils.isBlank(apiDefinition.getMethod()) ? originApiDefinition.getMethod() : apiDefinition.getMethod();
|
||||
String path = StringUtils.isBlank(apiDefinition.getPath()) ? originApiDefinition.getPath() : apiDefinition.getPath();
|
||||
example.createCriteria()
|
||||
.andPathEqualTo(path)
|
||||
.andMethodEqualTo(method)
|
||||
.andIdNotEqualTo(originApiDefinition.getId())
|
||||
.andProtocolEqualTo(originApiDefinition.getProtocol())
|
||||
.andProjectIdEqualTo(originApiDefinition.getProjectId())
|
||||
.andRefIdNotEqualTo(originApiDefinition.getRefId())
|
||||
.andDeletedEqualTo(false);
|
||||
if (apiDefinitionMapper.countByExample(example) > 0) {
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||
if (StringUtils.equals(originApiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||
if (StringUtils.isNotEmpty(apiDefinition.getPath()) || StringUtils.isNotEmpty(apiDefinition.getMethod())) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
String method = StringUtils.isBlank(apiDefinition.getMethod()) ? originApiDefinition.getMethod() : apiDefinition.getMethod();
|
||||
String path = StringUtils.isBlank(apiDefinition.getPath()) ? originApiDefinition.getPath() : apiDefinition.getPath();
|
||||
example.createCriteria()
|
||||
.andPathEqualTo(path)
|
||||
.andMethodEqualTo(method)
|
||||
.andIdNotEqualTo(originApiDefinition.getId())
|
||||
.andProtocolEqualTo(originApiDefinition.getProtocol())
|
||||
.andProjectIdEqualTo(originApiDefinition.getProjectId())
|
||||
.andRefIdNotEqualTo(originApiDefinition.getRefId())
|
||||
.andDeletedEqualTo(false);
|
||||
if (apiDefinitionMapper.countByExample(example) > 0) {
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(apiDefinition.getName())) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria()
|
||||
.andNameEqualTo(apiDefinition.getName())
|
||||
.andIdNotEqualTo(originApiDefinition.getId())
|
||||
.andProtocolEqualTo(originApiDefinition.getProtocol())
|
||||
.andModuleIdEqualTo(originApiDefinition.getModuleId())
|
||||
.andProjectIdEqualTo(originApiDefinition.getProjectId())
|
||||
.andRefIdNotEqualTo(originApiDefinition.getRefId())
|
||||
.andDeletedEqualTo(false);
|
||||
if (apiDefinitionMapper.countByExample(example) > 0) {
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
private static final String EXPORT = "/export/";
|
||||
private static ApiDefinition apiDefinition;
|
||||
private static ApiDefinition tcpApiDefinition;
|
||||
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
|
@ -302,7 +303,12 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
request.setProtocol("TCP");
|
||||
request.setMethod(null);
|
||||
request.setPath(null);
|
||||
this.requestPostWithOk(ADD, request);
|
||||
mvcResult = this.requestPostWithOkAndReturn(ADD, request);
|
||||
resultData = getResultData(mvcResult, ApiDefinition.class);
|
||||
tcpApiDefinition = apiDefinitionMapper.selectByPrimaryKey(resultData.getId());
|
||||
|
||||
// @@TCP重名校验异常
|
||||
assertErrorCode(this.requestPost(ADD, request), ApiResultCode.API_DEFINITION_EXIST);
|
||||
|
||||
// @@响应名+响应码唯一校验异常
|
||||
request.setName("test123-response");
|
||||
|
@ -557,6 +563,11 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(updateStatusRequest.getId());
|
||||
Assertions.assertEquals(apiDefinition.getStatus(), ApiDefinitionStatus.DONE.name());
|
||||
|
||||
ApiDefinitionUpdateRequest tcpRequest = new ApiDefinitionUpdateRequest();
|
||||
tcpRequest.setId(tcpApiDefinition.getId());
|
||||
tcpRequest.setDescription("TEST");
|
||||
this.requestPostWithOk(UPDATE, tcpRequest);
|
||||
|
||||
// @@重名校验异常
|
||||
ApiDefinitionUpdateRequest repeatRequest = new ApiDefinitionUpdateRequest();
|
||||
repeatRequest.setId(apiDefinition.getId());
|
||||
|
|
Loading…
Reference in New Issue