refactor(接口测试): 优化接口协议选择

This commit is contained in:
wxg0103 2024-06-07 13:03:53 +08:00 committed by 刘瑞斌
parent f43f23ae7b
commit 3aac154c77
24 changed files with 192 additions and 65 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.api.controller.definition;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.constants.ApiConstants;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.api.dto.ReferenceDTO;
import io.metersphere.api.dto.ReferenceRequest;
@ -92,6 +93,7 @@ public class ApiTestCaseController {
ids.add(id);
request.setSelectIds(ids);
request.setProjectId(SessionUtils.getCurrentProjectId());
request.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
apiTestCaseRecoverService.batchRecover(request, SessionUtils.getUserId());
}

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -29,8 +28,7 @@ public class ApiDefinitionBatchRequest extends TableBatchProcessDTO implements S
private String projectId;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_debug.protocol.not_blank}")
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
private List<@NotBlank String> moduleIds;

View File

@ -2,7 +2,6 @@ package io.metersphere.api.dto.definition;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
@ -33,8 +32,7 @@ public class ApiDefinitionDocRequest implements Serializable {
private String projectId;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition.protocol.not_blank}")
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
private List<@NotBlank String> moduleIds;

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -27,8 +26,7 @@ public class ApiDefinitionPageRequest extends BasePageRequest {
private String name;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition.protocol.not_blank}")
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_definition.project_id.not_blank}")

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.sdk.BaseCondition;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
@ -16,8 +15,7 @@ public class ApiModuleRequest extends BaseCondition {
private List<@NotBlank String> moduleIds;
@Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition_module.protocol.not_blank}")
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_definition_module.project_id.not_blank}")
@Size(min = 1, max = 50, message = "{api_definition_module.project_id.length_range}")

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -28,7 +27,6 @@ public class ApiTestCaseBatchRequest extends TableBatchProcessDTO implements Ser
private String projectId;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition.protocol.not_blank}")
private List<String> protocols = new ArrayList<>();
@Schema(description = "模块ID")

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -30,8 +29,7 @@ public class ApiTestCasePageRequest extends BasePageRequest implements Serializa
private String projectId;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition.protocol.not_blank}")
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "模块ID")
private List<@NotBlank String> moduleIds;

View File

@ -3,7 +3,6 @@ package io.metersphere.api.dto.definition.request;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -35,8 +34,7 @@ public class ApiDefinitionMockPageRequest extends BasePageRequest {
private String apiDefinitionId;
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "模块ID")
private List<@NotBlank String> moduleIds;

View File

@ -2,7 +2,6 @@ package io.metersphere.api.dto.scenario;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -24,8 +23,7 @@ public class ScenarioSystemRequest {
@Size(min = 1, max = 50, message = "{api_scenario.project_id.length_range}")
private String projectId;
@Schema(description = "协议 接口和用例的时候 是必传的", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty
private List<@NotBlank String> protocols = new ArrayList<>();
private List<String> protocols = new ArrayList<>();
@Schema(description = "版本id")
private String versionId;
}

View File

@ -101,6 +101,9 @@ public class ApiDefinitionMockService {
private static final String MOCK_TABLE = "api_definition_mock";
public List<ApiDefinitionMockDTO> getPage(ApiDefinitionMockPageRequest request) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
return extApiDefinitionMockMapper.list(request);
}
@ -369,6 +372,9 @@ public class ApiDefinitionMockService {
}
public void batchDelete(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
SubListUtils.dealForSubList(ids, 500, subList -> deleteResourceByIds(subList, request.getProjectId(), userId));
@ -394,6 +400,9 @@ public class ApiDefinitionMockService {
}
public void batchEdit(ApiMockBatchEditRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
SubListUtils.dealForSubList(ids, 500, subList -> batchEditByType(request, subList, userId, request.getProjectId()));

View File

@ -70,7 +70,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
//接口的树结构是 模块子模块+接口 接口为非delete状态的
List<BaseTreeNode> fileModuleList = extApiDefinitionModuleMapper.selectBaseByRequest(request);
List<BaseTreeNode> baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED_API));
if (!containRequest) {
if (!containRequest || CollectionUtils.isEmpty(request.getProtocols())) {
return baseTreeNodes;
}
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted);
@ -263,6 +263,9 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
}
public Map<String, Long> moduleCount(ApiModuleRequest request, boolean deleted) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return Collections.emptyMap();
}
boolean isRepeat = true;
if (StringUtils.isNotEmpty(request.getTestPlanId())) {
isRepeat = this.checkTestPlanRepeatCase(request);
@ -282,6 +285,9 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
}
public List<BaseTreeNode> getTrashTree(ApiModuleRequest request) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria()
.andProjectIdEqualTo(request.getProjectId())

View File

@ -136,6 +136,9 @@ public class ApiDefinitionService extends MoveNodeService {
private ApiDefinitionNoticeService apiDefinitionNoticeService;
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, String userId) {
if (CollectionUtils.isNotEmpty(request.getProtocols())) {
return new ArrayList<>();
}
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId);
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request);
processApiDefinitions(list);
@ -143,6 +146,9 @@ public class ApiDefinitionService extends MoveNodeService {
}
public List<ApiDefinitionDTO> getDocPage(ApiDefinitionPageRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId);
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request);
if (!CollectionUtils.isEmpty(list)) {
@ -291,41 +297,54 @@ public class ApiDefinitionService extends MoveNodeService {
public void batchUpdate(ApiDefinitionBatchUpdateRequest request, String userId) {
ProjectService.checkResourceExist(request.getProjectId());
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
// 记录更新前的数据
apiDefinitionLogService.batchUpdateLog(ids, userId, request.getProjectId());
if (CollectionUtils.isNotEmpty(ids)) {
if ("tags".equals(request.getType())) {
handleTags(request, userId, ids);
} else if ("customs".equals(request.getType())) {
// 自定义字段处理
ApiDefinitionCustomFieldDTO customField = request.getCustomField();
List<ApiDefinitionCustomField> list = new ArrayList<>();
ApiDefinitionCustomField apiDefinitionCustomField = new ApiDefinitionCustomField();
apiDefinitionCustomField.setFieldId(customField.getId());
apiDefinitionCustomField.setValue(customField.getValue());
list.add(apiDefinitionCustomField);
ApiDefinitionUpdateRequest apiDefinitionUpdateRequest = new ApiDefinitionUpdateRequest();
BeanUtils.copyBean(apiDefinitionUpdateRequest, request);
apiDefinitionUpdateRequest.setCustomFields(list);
ids.forEach(id -> {
apiDefinitionUpdateRequest.setId(id);
handleUpdateCustomFields(apiDefinitionUpdateRequest, request.getProjectId());
});
} else {
ApiDefinition apiDefinition = new ApiDefinition();
BeanUtils.copyBean(apiDefinition, request);
apiDefinition.setUpdateUser(userId);
apiDefinition.setUpdateTime(System.currentTimeMillis());
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
apiDefinitionExample.createCriteria().andIdIn(ids);
apiDefinitionMapper.updateByExampleSelective(apiDefinition, apiDefinitionExample);
ApiDefinition apiDefinition = new ApiDefinition();
BeanUtils.copyBean(apiDefinition, request);
apiDefinition.setUpdateUser(userId);
apiDefinition.setUpdateTime(System.currentTimeMillis());
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
switch (request.getType()) {
case "tags" -> handleTags(request, userId, ids);
case "customs" -> detailCustoms(request, ids);
case "method" -> handleMethod(request, userId, ids, apiDefinition, apiDefinitionExample);
default -> {
apiDefinitionExample.createCriteria().andIdIn(ids);
apiDefinitionMapper.updateByExampleSelective(apiDefinition, apiDefinitionExample);
}
}
//发送通知
apiDefinitionNoticeService.batchSendNotice(ids, userId, request.getProjectId(), NoticeConstants.Event.UPDATE);
}
}
private void handleMethod(ApiDefinitionBatchUpdateRequest request, String userId, List<String> ids, ApiDefinition apiDefinition, ApiDefinitionExample apiDefinitionExample) {
apiDefinitionExample.createCriteria().andIdIn(ids).andProtocolEqualTo(ApiConstants.HTTP_PROTOCOL);
apiDefinitionMapper.updateByExampleSelective(apiDefinition, apiDefinitionExample);
}
private void detailCustoms(ApiDefinitionBatchUpdateRequest request, List<String> ids) {
// 自定义字段处理
ApiDefinitionCustomFieldDTO customField = request.getCustomField();
List<ApiDefinitionCustomField> list = new ArrayList<>();
ApiDefinitionCustomField apiDefinitionCustomField = new ApiDefinitionCustomField();
apiDefinitionCustomField.setFieldId(customField.getId());
apiDefinitionCustomField.setValue(customField.getValue());
list.add(apiDefinitionCustomField);
ApiDefinitionUpdateRequest apiDefinitionUpdateRequest = new ApiDefinitionUpdateRequest();
BeanUtils.copyBean(apiDefinitionUpdateRequest, request);
apiDefinitionUpdateRequest.setCustomFields(list);
ids.forEach(id -> {
apiDefinitionUpdateRequest.setId(id);
handleUpdateCustomFields(apiDefinitionUpdateRequest, request.getProjectId());
});
}
private void handleUpdateCustomFields(ApiDefinitionUpdateRequest request, String projectId) {
List<ApiDefinitionCustomField> customFields = request.getCustomFields();
@ -417,6 +436,9 @@ public class ApiDefinitionService extends MoveNodeService {
}
public void batchDeleteToGc(ApiDefinitionBatchDeleteRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
if (CollectionUtils.isNotEmpty(ids)) {
handleDeleteApiDefinition(ids, request.getDeleteAllVersion(), request.getProjectId(), userId, true);
@ -424,6 +446,9 @@ public class ApiDefinitionService extends MoveNodeService {
}
public void batchMove(ApiDefinitionBatchMoveRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
if (!ids.isEmpty()) {
// 移动接口所有版本引用的数据
@ -805,6 +830,9 @@ public class ApiDefinitionService extends MoveNodeService {
}
public void batchRecover(ApiDefinitionBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId);
if (CollectionUtils.isNotEmpty(ids)) {
handleRecoverApiDefinition(ids, userId, request.getProjectId(), true);
@ -812,6 +840,9 @@ public class ApiDefinitionService extends MoveNodeService {
}
public void batchDelete(ApiDefinitionBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocols(), true, userId);
if (CollectionUtils.isNotEmpty(ids)) {
handleTrashDelApiDefinition(ids, userId, request.getProjectId(), true);

View File

@ -29,6 +29,9 @@ public class ApiTestCaseRecoverService {
private ApiTestCaseService apiTestCaseService;
public void batchRecover(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, true);
if (CollectionUtils.isEmpty(ids)) {
return;

View File

@ -316,6 +316,9 @@ public class ApiTestCaseService extends MoveNodeService {
}
public List<ApiTestCaseDTO> page(ApiTestCasePageRequest request, boolean deleted, boolean isRepeat) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
List<ApiTestCaseDTO> apiCaseLists = extApiTestCaseMapper.listByRequest(request, deleted, isRepeat);
buildApiTestCaseDTO(apiCaseLists);
return apiCaseLists;
@ -379,6 +382,9 @@ public class ApiTestCaseService extends MoveNodeService {
}
public void batchDelete(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, true);
if (CollectionUtils.isEmpty(ids)) {
return;
@ -431,6 +437,9 @@ public class ApiTestCaseService extends MoveNodeService {
}
public void batchMoveGc(ApiTestCaseBatchRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, false);
batchDeleteToGc(ids, userId, request.getProjectId(), true);
}
@ -453,6 +462,9 @@ public class ApiTestCaseService extends MoveNodeService {
}
public void batchEdit(ApiCaseBatchEditRequest request, String userId) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return;
}
List<String> ids = doSelectIds(request, false);
if (CollectionUtils.isEmpty(ids)) {
return;
@ -881,7 +893,7 @@ public class ApiTestCaseService extends MoveNodeService {
}
public void moveNode(PosRequest posRequest) {
NodeMoveRequest request = super.getNodeMoveRequest(posRequest,true);
NodeMoveRequest request = super.getNodeMoveRequest(posRequest, true);
MoveNodeSortDTO sortDTO = super.getNodeSortDTO(
posRequest.getProjectId(),
request,

View File

@ -2154,6 +2154,9 @@ public class ApiScenarioService extends MoveNodeService {
}
private void getCaseStep(ApiScenarioSystemRequest request, ScenarioSystemRequest caseRequest, List<ApiScenarioStepDTO> steps) {
if (CollectionUtils.isEmpty(caseRequest.getProtocols())) {
return;
}
if (CollectionUtils.isNotEmpty(caseRequest.getModuleIds())) {
caseRequest.getSelectedIds().addAll(extApiTestCaseMapper.getIdsByModules(caseRequest));
}
@ -2178,6 +2181,9 @@ public class ApiScenarioService extends MoveNodeService {
}
private void getApiStep(ApiScenarioSystemRequest request, ScenarioSystemRequest apiRequest, List<ApiScenarioStepDTO> steps) {
if (CollectionUtils.isEmpty(apiRequest.getProtocols())) {
return;
}
if (CollectionUtils.isNotEmpty(apiRequest.getModuleIds())) {
apiRequest.getSelectedIds().addAll(extApiDefinitionMapper.getIdsByModules(apiRequest));
}
@ -2332,7 +2338,8 @@ public class ApiScenarioService extends MoveNodeService {
resourceInfo.setDelete(apiTestCase.getDeleted());
resourceInfo.setProjectId(apiTestCase.getProjectId());
});
default -> {}
default -> {
}
}
Optional.ofNullable(apiStepResourceInfo).ifPresent(resourceInfo -> {
Project project = projectMapper.selectByPrimaryKey(resourceInfo.getProjectId());

View File

@ -892,6 +892,13 @@ public class ApiDefinitionControllerTests extends BaseTest {
//doApiDefinitionPage("FILTER", PAGE);
assertPateDate(doApiDefinitionPage("COMBINE", PAGE));
assertPateDate(doApiDefinitionPage("DELETED", PAGE));
ApiDefinitionPageRequest request = new ApiDefinitionPageRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setCurrent(1);
request.setPageSize(10);
request.setDeleted(false);
request.setSort(Map.of("createTime", "asc"));
this.requestPostWithOkAndReturn(PAGE, request);
}
private void assertPateDate(Pager pageData) {
@ -1022,6 +1029,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
request.setApiId(apiDefinition.getId());
request.setProjectId(DEFAULT_PROJECT_ID);
this.requestPostWithOkAndReturn(DOC, request);
request.setProtocols(List.of("HTTP"));
request.setType(ApiDefinitionDocType.API.name());
// @@请求成功
@ -1115,9 +1123,10 @@ public class ApiDefinitionControllerTests extends BaseTest {
// @@模块查看文档
request.setApiId(null);
request.setProjectId(DEFAULT_PROJECT_ID);
request.setProtocols(List.of("HTTP"));
request.setType(ApiDefinitionDocType.MODULE.name());
request.setModuleIds(List.of("1001001"));
this.requestPostWithOkAndReturn(DOC, request);
request.setProtocols(List.of("HTTP"));
MvcResult mvcResultModule = this.requestPostWithOkAndReturn(DOC, request);
ApiDefinitionDocDTO moduleApiDefinitionDocDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResultModule).get("data")), ApiDefinitionDocDTO.class);
// 校验数据是否正确
@ -1330,6 +1339,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setSelectIds(List.of("1004"));
request.setDeleteAllVersion(false);
request.setSelectAll(false);
this.requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
request.setProtocols(List.of("HTTP"));
this.requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
// @@校验日志
@ -1405,12 +1415,14 @@ public class ApiDefinitionControllerTests extends BaseTest {
LogUtils.info("batch recover api test");
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setProtocols(List.of("HTTP"));
// 恢复选中
request.setSelectIds(List.of("1002", "1004", "1005"));
request.setExcludeIds(List.of("1005"));
request.setSelectAll(false);
this.requestPostWithOk(BATCH_RESTORE, request);
request.setProtocols(List.of("HTTP"));
this.requestPostWithOk(BATCH_RESTORE, request);
// 效验数据结果
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
@ -1487,12 +1499,13 @@ public class ApiDefinitionControllerTests extends BaseTest {
LogUtils.info("batch trash delete api test");
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setProtocols(List.of("HTTP"));
// 删除选中
request.setSelectIds(List.of("1003"));
request.setSelectAll(false);
this.requestPostWithOk(BATCH_DELETE, request);
request.setProtocols(List.of("HTTP"));
this.requestPostWithOk(BATCH_DELETE, request);
// 效验数据结果
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
apiDefinitionExample.createCriteria().andIdIn(request.getSelectIds());

View File

@ -517,6 +517,13 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
public void getPage() throws Exception {
doApiDefinitionPage("KEYWORD");
doApiDefinitionPage("FILTER");
ApiDefinitionMockPageRequest request = new ApiDefinitionMockPageRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setApiDefinitionId(apiDefinitionMock.getApiDefinitionId());
request.setCurrent(1);
request.setPageSize(10);
request.setSort(Map.of("createTime", "asc"));
this.requestPostWithOkAndReturn(PAGE, request);
}
private void doApiDefinitionPage(String search) throws Exception {
@ -601,9 +608,10 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
request.setType("Tags");
request.setAppend(true);
request.setSelectAll(true);
request.setProtocols(List.of("HTTP"));
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag3", "tag4")));
requestPostWithOkAndReturn(BATCH_EDIT, request);
request.setProtocols(List.of("HTTP"));
requestPostWithOkAndReturn(BATCH_EDIT, request);
ApiDefinitionMockExample example = new ApiDefinitionMockExample();
List<String> ids = extApiDefinitionMockMapper.getIds(request);
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andIdIn(ids);

View File

@ -814,6 +814,9 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
@Order(8)
public void TestModuleCountSuccess() throws Exception {
this.preliminaryData();
this.requestPostWithOkAndReturn(URL_FILE_MODULE_COUNT, new ApiModuleRequest() {{
this.setProjectId(project.getId());
}});
ApiModuleRequest request = new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());
@ -878,6 +881,9 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
ApiDefinition apiDefinition = new ApiDefinition();
apiDefinition.setDeleted(true);
apiDefinitionMapper.updateByExampleSelective(apiDefinition, example);
this.requestPostWithOkAndReturn(URL_MODULE_TRASH_TREE, new ApiModuleRequest() {{
this.setProjectId(project.getId());
}});
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TRASH_TREE, new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());
@ -891,6 +897,10 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
@Test
@Order(12)
public void getModuleTrashTreeCount() throws Exception {
this.requestPostWithOkAndReturn(URL_MODULE_TRASH_COUNT, new ApiModuleRequest() {{
this.setProjectId(project.getId());
}});
ApiModuleRequest request = new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());
@ -953,10 +963,16 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
private List<BaseTreeNode> getModuleTreeNode() throws Exception {
this.requestPostWithOkAndReturn(URL_MODULE_TREE, new ApiModuleRequest() {{
this.setProjectId(project.getId());
}});
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TREE, new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());
}});
this.requestPostWithOkAndReturn(URL_MODULE_ONLY_TREE, new ApiModuleRequest() {{
this.setProjectId(project.getId());
}});
this.requestPostWithOkAndReturn(URL_MODULE_ONLY_TREE, new ApiModuleRequest() {{
this.setProtocols(List.of(ApiConstants.HTTP_PROTOCOL));
this.setProjectId(project.getId());

View File

@ -2837,6 +2837,16 @@ public class ApiScenarioControllerTests extends BaseTest {
apiScenarioSystemRequest.setScenarioRequest(scenarioSystemRequest);
apiScenarioSystemRequest.setRefType(ApiScenarioStepRefType.COPY.name());
this.requestPostWithOkAndReturn("/get/system-request", apiScenarioSystemRequest);
scenarioSystemRequest = new ScenarioSystemRequest();
scenarioSystemRequest.setProjectId(DEFAULT_PROJECT_ID);
scenarioSystemRequest.setModuleIds(List.of("test-default"));
apiScenarioSystemRequest = new ApiScenarioSystemRequest();
apiScenarioSystemRequest.setApiRequest(scenarioSystemRequest);
apiScenarioSystemRequest.setCaseRequest(scenarioSystemRequest);
apiScenarioSystemRequest.setScenarioRequest(scenarioSystemRequest);
apiScenarioSystemRequest.setRefType(ApiScenarioStepRefType.COPY.name());
this.requestPostWithOkAndReturn("/get/system-request", apiScenarioSystemRequest);
}
@Test

View File

@ -508,6 +508,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
apiRunModeRequest.setIntegratedReportName("aaaa");
apiRunModeRequest.setPoolId("poolId");
request.setRunModeConfig(apiRunModeRequest);
this.requestPostWithOk(BATCH_RUN, request);
request.setProtocols(List.of("HTTP"));
this.requestPostWithOk(BATCH_RUN, request);
@ -834,6 +835,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
pageRequest.setProjectId(DEFAULT_PROJECT_ID);
pageRequest.setPageSize(10);
pageRequest.setCurrent(1);
requestPostWithOkAndReturn(PAGE, pageRequest);
pageRequest.setProtocols(List.of("HTTP"));
MvcResult mvcResult = requestPostWithOkAndReturn(PAGE, pageRequest);
Pager<?> returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
@ -914,9 +916,10 @@ public class ApiTestCaseControllerTests extends BaseTest {
request.setType("Tags");
request.setAppend(true);
request.setSelectAll(true);
request.setProtocols(List.of("HTTP"));
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag3", "tag4")));
requestPostWithOkAndReturn(BATCH_EDIT, request);
request.setProtocols(List.of("HTTP"));
requestPostWithOkAndReturn(BATCH_EDIT, request);
ApiTestCaseExample example = new ApiTestCaseExample();
List<String> ids = extApiTestCaseMapper.getIds(request, false);
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andDeletedEqualTo(false).andIdIn(ids);
@ -1057,8 +1060,10 @@ public class ApiTestCaseControllerTests extends BaseTest {
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(false);
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
request.setSelectIds(List.of(apiTestCase.getId()));
request.setExcludeIds(List.of(apiTestCase.getId()));
request.setProtocols(List.of("HTTP"));
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
request.setSelectAll(true);
@ -1089,6 +1094,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
pageRequest.setProjectId(DEFAULT_PROJECT_ID);
pageRequest.setPageSize(10);
pageRequest.setCurrent(1);
requestPostWithOkAndReturn(TRASH_PAGE, pageRequest);
pageRequest.setProtocols(List.of("HTTP"));
MvcResult mvcResult = requestPostWithOkAndReturn(TRASH_PAGE, pageRequest);
Pager<?> returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
@ -1139,9 +1145,10 @@ public class ApiTestCaseControllerTests extends BaseTest {
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(false);
requestPostWithOkAndReturn(BATCH_RECOVER, request);
request.setProtocols(List.of("HTTP"));
request.setSelectIds(List.of(apiTestCase.getId()));
request.setExcludeIds(List.of(apiTestCase.getId()));
request.setProtocols(List.of("HTTP"));
requestPostWithOkAndReturn(BATCH_RECOVER, request);
ApiDefinition apiDefinition = new ApiDefinition();
@ -1214,9 +1221,15 @@ public class ApiTestCaseControllerTests extends BaseTest {
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(false);
requestPostWithOkAndReturn(BATCH_DELETE, request);
request.setSelectIds(List.of(apiTestCase.getId()));
request.setExcludeIds(List.of(apiTestCase.getId()));
request.setProtocols(List.of("HTTP"));
requestPostWithOkAndReturn(BATCH_DELETE, request);
request.setSelectAll(true);
request.setExcludeIds(new ArrayList<>());
request.setApiDefinitionId("apiDefinitionId");
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(true);
request.setApiDefinitionId("apiDefinitionId");

View File

@ -1,8 +1,6 @@
package io.metersphere.plan.dto.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.List;
@ -13,6 +11,5 @@ import java.util.List;
@Data
public class TestPlanApiCaseBatchRequest extends BasePlanCaseBatchRequest {
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{api_definition.protocol.not_blank}")
private List<@NotBlank String> protocols;
private List<String> protocols;
}

View File

@ -161,6 +161,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
* @return
*/
public List<ApiDefinitionDTO> getApiPage(TestPlanApiRequest request, boolean isRepeat) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
List<ApiDefinitionDTO> list = extTestPlanApiCaseMapper.list(request, isRepeat);
apiDefinitionService.processApiDefinitions(list);
return list;
@ -175,8 +178,10 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
* @return
*/
public List<ApiTestCaseDTO> getApiCasePage(TestPlanApiCaseRequest request, boolean isRepeat) {
List<ApiTestCaseDTO> apiCaseLists = apiTestCaseService.page(request, isRepeat, false);
return apiCaseLists;
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
return apiTestCaseService.page(request, isRepeat, false);
}
@ -188,6 +193,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
* @return
*/
public List<TestPlanApiCasePageResponse> hasRelateApiCaseList(TestPlanApiCaseRequest request, boolean deleted) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new ArrayList<>();
}
List<TestPlanApiCasePageResponse> list = extTestPlanApiCaseMapper.relateApiCaseList(request, deleted);
buildApiCaseResponse(list);
return list;
@ -410,6 +418,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
* @return
*/
public TestPlanAssociationResponse disassociate(TestPlanApiCaseBatchRequest request, LogInsertModule logInsertModule) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return new TestPlanAssociationResponse();
}
List<String> selectIds = doSelectIds(request);
return super.disassociate(
TestPlanResourceConstants.RESOURCE_API_CASE,
@ -485,7 +496,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
List<ApiTestCase> apiTestCaseList = apiTestCaseMapper.selectByExample(example);
apiCaseList.forEach(apiCase -> {
List<String> apiCaseIds = apiCase.getIds();
if(CollectionUtils.isNotEmpty(apiCaseIds)){
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getApiDefinitionId())).collect(Collectors.toList());
buildTestPlanApiCase(planId, apiTestCases, apiCase.getCollectionId(), userId, testPlanApiCaseList);
}

View File

@ -44,6 +44,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
request.setPageSize(10);
request.setTestPlanId("wxxx_1");
request.setProjectId("wxx_1234");
this.requestPost(API_CASE_PAGE, request);
request.setProtocols(List.of("HTTP"));
this.requestPost(API_CASE_PAGE, request);
request.setSort(new HashMap<>() {{
@ -118,6 +119,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
request.setUserId("test_user");
request.setTestPlanId("wxxx_2");
request.setSelectAll(true);
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
request.setProtocols(List.of("HTTP"));
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
request.setTestPlanId("wxxx_1");
@ -132,8 +134,9 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
public void testApiCaseBatchDisassociate() throws Exception {
TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest();
request.setTestPlanId("wxxx_2");
request.setProtocols(List.of("HTTP"));
request.setSelectAll(true);
this.requestPostWithOkAndReturn(API_CASE_BATCH_DISASSOCIATE, request);
request.setProtocols(List.of("HTTP"));
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_BATCH_DISASSOCIATE, request);
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);

View File

@ -55,6 +55,7 @@ public class TestPlanAssociateControllerTests extends BaseTest {
request.setPageSize(10);
request.setTestPlanId("wxx_1");
request.setProjectId("1234567");
this.requestPost(API_ASSOCIATION_URL, request);
request.setProtocols(List.of("HTTP"));
this.requestPost(API_ASSOCIATION_URL, request);
request.setProjectId("wx_1234");
@ -76,6 +77,7 @@ public class TestPlanAssociateControllerTests extends BaseTest {
request.setPageSize(10);
request.setProjectId("1234567");
request.setTestPlanId("wxx_1");
this.requestPost(API_CASE_ASSOCIATION_URL, request);
request.setProtocols(List.of("HTTP"));
this.requestPost(API_CASE_ASSOCIATION_URL, request);
request.setProjectId("wx_1234");