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);
|
BeanUtils.copyBean(apiDefinition, request);
|
||||||
apiDefinition.setTags(ServiceUtils.parseTags(apiDefinition.getTags()));
|
apiDefinition.setTags(ServiceUtils.parseTags(apiDefinition.getTags()));
|
||||||
checkResponseNameCode(request.getResponse());
|
checkResponseNameCode(request.getResponse());
|
||||||
if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) {
|
checkUpdateExist(apiDefinition, originApiDefinition);
|
||||||
checkUpdateExist(apiDefinition, originApiDefinition);
|
|
||||||
}
|
|
||||||
apiDefinition.setUpdateUser(userId);
|
apiDefinition.setUpdateUser(userId);
|
||||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||||
|
@ -537,39 +536,59 @@ public class ApiDefinitionService extends MoveNodeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAddExist(ApiDefinition apiDefinition) {
|
private void checkAddExist(ApiDefinition apiDefinition) {
|
||||||
if (!StringUtils.equals(apiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
example.createCriteria()
|
if (StringUtils.equals(apiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||||
.andPathEqualTo(apiDefinition.getPath())
|
example.createCriteria()
|
||||||
.andMethodEqualTo(apiDefinition.getMethod())
|
.andPathEqualTo(apiDefinition.getPath())
|
||||||
.andProtocolEqualTo(apiDefinition.getProtocol())
|
.andMethodEqualTo(apiDefinition.getMethod())
|
||||||
.andProjectIdEqualTo(apiDefinition.getProjectId())
|
.andProtocolEqualTo(apiDefinition.getProtocol())
|
||||||
.andDeletedEqualTo(false);
|
.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))) {
|
if (CollectionUtils.isNotEmpty(apiDefinitionMapper.selectByExample(example))) {
|
||||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUpdateExist(ApiDefinition apiDefinition, ApiDefinition originApiDefinition) {
|
private void checkUpdateExist(ApiDefinition apiDefinition, ApiDefinition originApiDefinition) {
|
||||||
if (!StringUtils.equals(originApiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
if (StringUtils.equals(originApiDefinition.getProtocol(), ApiConstants.HTTP_PROTOCOL)) {
|
||||||
return;
|
if (StringUtils.isNotEmpty(apiDefinition.getPath()) || StringUtils.isNotEmpty(apiDefinition.getMethod())) {
|
||||||
}
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
if (StringUtils.isNotEmpty(apiDefinition.getPath()) || StringUtils.isNotEmpty(apiDefinition.getMethod())) {
|
String method = StringUtils.isBlank(apiDefinition.getMethod()) ? originApiDefinition.getMethod() : apiDefinition.getMethod();
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
String path = StringUtils.isBlank(apiDefinition.getPath()) ? originApiDefinition.getPath() : apiDefinition.getPath();
|
||||||
String method = StringUtils.isBlank(apiDefinition.getMethod()) ? originApiDefinition.getMethod() : apiDefinition.getMethod();
|
example.createCriteria()
|
||||||
String path = StringUtils.isBlank(apiDefinition.getPath()) ? originApiDefinition.getPath() : apiDefinition.getPath();
|
.andPathEqualTo(path)
|
||||||
example.createCriteria()
|
.andMethodEqualTo(method)
|
||||||
.andPathEqualTo(path)
|
.andIdNotEqualTo(originApiDefinition.getId())
|
||||||
.andMethodEqualTo(method)
|
.andProtocolEqualTo(originApiDefinition.getProtocol())
|
||||||
.andIdNotEqualTo(originApiDefinition.getId())
|
.andProjectIdEqualTo(originApiDefinition.getProjectId())
|
||||||
.andProtocolEqualTo(originApiDefinition.getProtocol())
|
.andRefIdNotEqualTo(originApiDefinition.getRefId())
|
||||||
.andProjectIdEqualTo(originApiDefinition.getProjectId())
|
.andDeletedEqualTo(false);
|
||||||
.andRefIdNotEqualTo(originApiDefinition.getRefId())
|
if (apiDefinitionMapper.countByExample(example) > 0) {
|
||||||
.andDeletedEqualTo(false);
|
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||||
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 final String EXPORT = "/export/";
|
||||||
private static ApiDefinition apiDefinition;
|
private static ApiDefinition apiDefinition;
|
||||||
|
private static ApiDefinition tcpApiDefinition;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ApiDefinitionMapper apiDefinitionMapper;
|
private ApiDefinitionMapper apiDefinitionMapper;
|
||||||
|
@ -302,7 +303,12 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
request.setProtocol("TCP");
|
request.setProtocol("TCP");
|
||||||
request.setMethod(null);
|
request.setMethod(null);
|
||||||
request.setPath(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");
|
request.setName("test123-response");
|
||||||
|
@ -557,6 +563,11 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(updateStatusRequest.getId());
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(updateStatusRequest.getId());
|
||||||
Assertions.assertEquals(apiDefinition.getStatus(), ApiDefinitionStatus.DONE.name());
|
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();
|
ApiDefinitionUpdateRequest repeatRequest = new ApiDefinitionUpdateRequest();
|
||||||
repeatRequest.setId(apiDefinition.getId());
|
repeatRequest.setId(apiDefinition.getId());
|
||||||
|
|
Loading…
Reference in New Issue