fix(接口测试): 接口分享重名校验问题
This commit is contained in:
parent
9051dec329
commit
b0974477c2
|
@ -466,4 +466,4 @@ api_doc_share.create_user.not_blank=创建人不能为空
|
||||||
api_doc_share.create_user.length_range=创建人长度必须在{min}和{max}之间
|
api_doc_share.create_user.length_range=创建人长度必须在{min}和{max}之间
|
||||||
api_doc_share.project_id.not_blank=项目ID不能为空
|
api_doc_share.project_id.not_blank=项目ID不能为空
|
||||||
api_doc_share.project_id.length_range=项目ID长度必须在{min}和{max}之间
|
api_doc_share.project_id.length_range=项目ID长度必须在{min}和{max}之间
|
||||||
|
api_doc_share.name_duplicate=分享名称重复
|
||||||
|
|
|
@ -476,4 +476,5 @@ api_doc_share.api_range.length_range=apiRange length must be between {min} and {
|
||||||
api_doc_share.create_user.not_blank=createUser cannot be empty
|
api_doc_share.create_user.not_blank=createUser cannot be empty
|
||||||
api_doc_share.create_user.length_range=createUser length must be between {min} and {max}
|
api_doc_share.create_user.length_range=createUser length must be between {min} and {max}
|
||||||
api_doc_share.project_id.not_blank=projectId cannot be empty
|
api_doc_share.project_id.not_blank=projectId cannot be empty
|
||||||
api_doc_share.project_id.length_range=projectId length must be between {min} and {max}
|
api_doc_share.project_id.length_range=projectId length must be between {min} and {max}
|
||||||
|
api_doc_share.name_duplicate=Share name duplicate
|
|
@ -444,4 +444,5 @@ api_doc_share.api_range.length_range=接口范围长度必须在{min}和{max}之
|
||||||
api_doc_share.create_user.not_blank=创建人不能为空
|
api_doc_share.create_user.not_blank=创建人不能为空
|
||||||
api_doc_share.create_user.length_range=创建人长度必须在{min}和{max}之间
|
api_doc_share.create_user.length_range=创建人长度必须在{min}和{max}之间
|
||||||
api_doc_share.project_id.not_blank=项目ID不能为空
|
api_doc_share.project_id.not_blank=项目ID不能为空
|
||||||
api_doc_share.project_id.length_range=项目ID长度必须在{min}和{max}之间
|
api_doc_share.project_id.length_range=项目ID长度必须在{min}和{max}之间
|
||||||
|
api_doc_share.name_duplicate=分享名称重复
|
|
@ -444,4 +444,5 @@ api_doc_share.api_range.length_range=接口范围長度必須在{min}和{max}之
|
||||||
api_doc_share.create_user.not_blank=创建人不能為空
|
api_doc_share.create_user.not_blank=创建人不能為空
|
||||||
api_doc_share.create_user.length_range=创建人長度必須在{min}和{max}之间
|
api_doc_share.create_user.length_range=创建人長度必須在{min}和{max}之间
|
||||||
api_doc_share.project_id.not_blank=项目ID不能為空
|
api_doc_share.project_id.not_blank=项目ID不能為空
|
||||||
api_doc_share.project_id.length_range=项目ID長度必須在{min}和{max}之间
|
api_doc_share.project_id.length_range=项目ID長度必須在{min}和{max}之间
|
||||||
|
api_doc_share.name_duplicate=分享名稱重複
|
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.api.service.definition;
|
package io.metersphere.api.service.definition;
|
||||||
|
|
||||||
import io.metersphere.api.domain.ApiDocShare;
|
import io.metersphere.api.domain.ApiDocShare;
|
||||||
|
import io.metersphere.api.domain.ApiDocShareExample;
|
||||||
import io.metersphere.api.dto.definition.ApiDocShareDTO;
|
import io.metersphere.api.dto.definition.ApiDocShareDTO;
|
||||||
import io.metersphere.api.dto.definition.ApiDocShareDetail;
|
import io.metersphere.api.dto.definition.ApiDocShareDetail;
|
||||||
import io.metersphere.api.dto.definition.request.*;
|
import io.metersphere.api.dto.definition.request.*;
|
||||||
|
@ -63,6 +64,7 @@ public class ApiDocShareService {
|
||||||
* @return 分享
|
* @return 分享
|
||||||
*/
|
*/
|
||||||
public ApiDocShare create(ApiDocShareEditRequest request, String currentUser) {
|
public ApiDocShare create(ApiDocShareEditRequest request, String currentUser) {
|
||||||
|
checkDuplicateName(request);
|
||||||
ApiDocShare docShare = new ApiDocShare();
|
ApiDocShare docShare = new ApiDocShare();
|
||||||
BeanUtils.copyBean(docShare, request);
|
BeanUtils.copyBean(docShare, request);
|
||||||
docShare.setId(IDGenerator.nextStr());
|
docShare.setId(IDGenerator.nextStr());
|
||||||
|
@ -79,6 +81,7 @@ public class ApiDocShareService {
|
||||||
*/
|
*/
|
||||||
public ApiDocShare update(ApiDocShareEditRequest request) {
|
public ApiDocShare update(ApiDocShareEditRequest request) {
|
||||||
checkExit(request.getId());
|
checkExit(request.getId());
|
||||||
|
checkDuplicateName(request);
|
||||||
ApiDocShare docShare = new ApiDocShare();
|
ApiDocShare docShare = new ApiDocShare();
|
||||||
BeanUtils.copyBean(docShare, request);
|
BeanUtils.copyBean(docShare, request);
|
||||||
apiDocShareMapper.updateByPrimaryKeySelective(docShare);
|
apiDocShareMapper.updateByPrimaryKeySelective(docShare);
|
||||||
|
@ -295,6 +298,23 @@ public class ApiDocShareService {
|
||||||
return docShare;
|
return docShare;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查分享名称是否重名
|
||||||
|
* @param request 请求参数
|
||||||
|
*/
|
||||||
|
private void checkDuplicateName(ApiDocShareEditRequest request) {
|
||||||
|
ApiDocShareExample example = new ApiDocShareExample();
|
||||||
|
ApiDocShareExample.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andNameEqualTo(request.getName());
|
||||||
|
criteria.andProjectIdEqualTo(request.getProjectId());
|
||||||
|
if (StringUtils.isNotBlank(request.getId())) {
|
||||||
|
criteria.andIdNotEqualTo(request.getId());
|
||||||
|
}
|
||||||
|
if (apiDocShareMapper.countByExample(example) > 0) {
|
||||||
|
throw new MSException(Translator.get("api_doc_share.name_duplicate"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组合左侧模块树的查询条件
|
* 组合左侧模块树的查询条件
|
||||||
* @param name 条件字段名
|
* @param name 条件字段名
|
||||||
|
|
|
@ -92,17 +92,19 @@ public class ApiDocShareControllerTests extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void page() throws Exception {
|
public void page() throws Exception {
|
||||||
ApiDocShareEditRequest request = new ApiDocShareEditRequest();
|
ApiDocShareEditRequest request = new ApiDocShareEditRequest();
|
||||||
request.setName("share-1");
|
request.setName("share-2");
|
||||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
request.setApiRange("ALL");
|
request.setApiRange("ALL");
|
||||||
request.setIsPrivate(false);
|
request.setIsPrivate(false);
|
||||||
request.setAllowExport(false);
|
request.setAllowExport(false);
|
||||||
this.requestPostWithOk(ADD, request);
|
this.requestPost(ADD, request);
|
||||||
|
request.setName("share-3");
|
||||||
request.setInvalidTime(1);
|
request.setInvalidTime(1);
|
||||||
request.setInvalidUnit("HOUR");
|
request.setInvalidUnit("HOUR");
|
||||||
request.setApiRange("MODULE");
|
request.setApiRange("MODULE");
|
||||||
request.setRangeMatchVal("module-1");
|
request.setRangeMatchVal("module-1");
|
||||||
this.requestPostWithOk(ADD, request);
|
this.requestPostWithOk(ADD, request);
|
||||||
|
request.setName("share-4");
|
||||||
request.setApiRange("PATH");
|
request.setApiRange("PATH");
|
||||||
request.setRangeMatchSymbol("EQUALS");
|
request.setRangeMatchSymbol("EQUALS");
|
||||||
request.setRangeMatchVal("path-1");
|
request.setRangeMatchVal("path-1");
|
||||||
|
@ -115,6 +117,7 @@ public class ApiDocShareControllerTests extends BaseTest {
|
||||||
moduleRequest.setProjectId(DEFAULT_PROJECT_ID);
|
moduleRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
moduleRequest.setProtocols(List.of("HTTP", "SPX", "Redis", "MongoDB"));
|
moduleRequest.setProtocols(List.of("HTTP", "SPX", "Redis", "MongoDB"));
|
||||||
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
||||||
|
request.setName("share-5");
|
||||||
request.setRangeMatchSymbol("CONTAINS");
|
request.setRangeMatchSymbol("CONTAINS");
|
||||||
MvcResult mvcResult1 = this.requestPostWithOk(ADD, request).andReturn();
|
MvcResult mvcResult1 = this.requestPostWithOk(ADD, request).andReturn();
|
||||||
String returnData1 = mvcResult1.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
String returnData1 = mvcResult1.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
@ -122,6 +125,7 @@ public class ApiDocShareControllerTests extends BaseTest {
|
||||||
ApiDocShare docShare1 = JSON.parseObject(JSON.toJSONString(resultHolder1.getData()), ApiDocShare.class);
|
ApiDocShare docShare1 = JSON.parseObject(JSON.toJSONString(resultHolder1.getData()), ApiDocShare.class);
|
||||||
moduleRequest.setShareId(docShare1.getId());
|
moduleRequest.setShareId(docShare1.getId());
|
||||||
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
||||||
|
request.setName("share-6");
|
||||||
request.setApiRange("TAG");
|
request.setApiRange("TAG");
|
||||||
request.setRangeMatchVal("tag-1,tag-2");
|
request.setRangeMatchVal("tag-1,tag-2");
|
||||||
MvcResult mvcResult2 = this.requestPostWithOk(ADD, request).andReturn();
|
MvcResult mvcResult2 = this.requestPostWithOk(ADD, request).andReturn();
|
||||||
|
@ -130,6 +134,7 @@ public class ApiDocShareControllerTests extends BaseTest {
|
||||||
ApiDocShare docShare2 = JSON.parseObject(JSON.toJSONString(resultHolder2.getData()), ApiDocShare.class);
|
ApiDocShare docShare2 = JSON.parseObject(JSON.toJSONString(resultHolder2.getData()), ApiDocShare.class);
|
||||||
moduleRequest.setShareId(docShare2.getId());
|
moduleRequest.setShareId(docShare2.getId());
|
||||||
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
this.requestPostWithOk(MODULE_COUNT, moduleRequest);
|
||||||
|
this.requestPost(ADD, request).andExpect(status().is5xxServerError());
|
||||||
ApiDocSharePageRequest pageRequest = new ApiDocSharePageRequest();
|
ApiDocSharePageRequest pageRequest = new ApiDocSharePageRequest();
|
||||||
pageRequest.setProjectId(DEFAULT_PROJECT_ID);
|
pageRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
pageRequest.setCurrent(1);
|
pageRequest.setCurrent(1);
|
||||||
|
|
Loading…
Reference in New Issue