refactor(接口测试): 优化接口标签保存
--bug=1038363 --user=王孝刚 【接口测试】API/CASE/场景-已有10个标签-批量编辑追加标签还是能继续添加标签 https://www.tapd.cn/55049933/s/1486207
This commit is contained in:
parent
4cc3569bd6
commit
d86b59f530
|
@ -428,5 +428,5 @@ api_scenario.environment_id.length_range=环境ID长度必须在0-50之间
|
|||
api_scenario_step.name.length_range=步骤名称长度必须在1-255之间
|
||||
api_scenario_step.name.not_blank=步骤名称不能为空
|
||||
api_scenario_step.resource_num.length_range=资源编号长度必须在1-50之间
|
||||
api_scenario_step.project_id.length_range
|
||||
api_scenario_step.version_id.length_range
|
||||
|
||||
tags_size_large_than=标签数量超过{0}个
|
|
@ -436,3 +436,4 @@ api_scenario.group_id.length_range=Group ID length must be between 0-50
|
|||
api_scenario.environment_id.length_range=Environment ID length must be between 0-50
|
||||
|
||||
api_report_default_env=Default environment
|
||||
tags_size_large_than=The number of tags cannot exceed 10
|
|
@ -404,3 +404,4 @@ api_scenario.group_id.length_range=环境组ID长度必须在0-50之间
|
|||
api_scenario.environment_id.length_range=环境ID长度必须在0-50之间
|
||||
|
||||
api_report_default_env=默认环境
|
||||
tags_size_large_than=标签数量超过{0}个
|
|
@ -403,3 +403,4 @@ api_scenario.group_id.length_range=环境組ID長度必須在0-50之間
|
|||
api_scenario.environment_id.length_range=環境ID長度必須在0-50之間
|
||||
|
||||
api_report_default_env=默认環境
|
||||
tags_size_large_than=標籤數量不能超過{max}
|
|
@ -41,7 +41,6 @@ import io.metersphere.sdk.util.*;
|
|||
import io.metersphere.system.dto.OperationHistoryDTO;
|
||||
import io.metersphere.system.dto.request.OperationHistoryRequest;
|
||||
import io.metersphere.system.dto.request.OperationHistoryVersionRequest;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||
|
@ -135,6 +134,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
private OperationLogBlobMapper operationLogBlobMapper;
|
||||
@Resource
|
||||
private ApiExecuteService apiExecuteService;
|
||||
private static final int MAX_TAG_SIZE = 10;
|
||||
|
||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, String userId) {
|
||||
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request, userId);
|
||||
|
@ -200,6 +200,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
apiDefinition.setRefId(apiDefinition.getId());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
apiTestCaseService.checkTagLength(request.getTags());
|
||||
apiDefinition.setTags(request.getTags());
|
||||
}
|
||||
apiDefinitionMapper.insertSelective(apiDefinition);
|
||||
|
@ -253,6 +254,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
public ApiDefinition update(ApiDefinitionUpdateRequest request, String userId) {
|
||||
ApiDefinition originApiDefinition = checkApiDefinition(request.getId());
|
||||
ApiDefinition apiDefinition = new ApiDefinition();
|
||||
apiTestCaseService.checkTagLength(request.getTags());
|
||||
BeanUtils.copyBean(apiDefinition, request);
|
||||
checkResponseNameCode(request.getResponse());
|
||||
if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) {
|
||||
|
@ -587,6 +589,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) {
|
||||
List<String> tags = collect.get(id).getTags();
|
||||
tags.addAll(request.getTags());
|
||||
apiTestCaseService.checkTagLength(tags);
|
||||
apiDefinition.setTags(tags);
|
||||
} else {
|
||||
apiDefinition.setTags(request.getTags());
|
||||
|
|
|
@ -101,6 +101,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
private EnvironmentService environmentService;
|
||||
|
||||
private static final String CASE_TABLE = "api_test_case";
|
||||
private static final int MAX_TAG_SIZE = 10;
|
||||
|
||||
private void checkProjectExist(String projectId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
|
@ -169,6 +170,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
testCase.setCreateTime(System.currentTimeMillis());
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
checkTagLength(request.getTags());
|
||||
testCase.setTags(request.getTags());
|
||||
}
|
||||
apiTestCaseMapper.insertSelective(testCase);
|
||||
|
@ -265,6 +267,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
testCase.setUpdateUser(userId);
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
checkTagLength(request.getTags());
|
||||
testCase.setTags(request.getTags());
|
||||
} else {
|
||||
testCase.setTags(null);
|
||||
|
@ -473,6 +476,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
if (CollectionUtils.isEmpty(request.getTags())) {
|
||||
throw new MSException(Translator.get("tags_is_null"));
|
||||
}
|
||||
checkTagLength(request.getTags());
|
||||
if (request.isAppend()) {
|
||||
Map<String, ApiTestCase> caseMap = extApiTestCaseMapper.getTagsByIds(ids, false)
|
||||
.stream()
|
||||
|
@ -482,6 +486,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
if (CollectionUtils.isNotEmpty(v.getTags())) {
|
||||
List<String> orgTags = v.getTags();
|
||||
orgTags.addAll(request.getTags());
|
||||
checkTagLength(orgTags.stream().distinct().toList());
|
||||
v.setTags(orgTags.stream().distinct().toList());
|
||||
} else {
|
||||
v.setTags(request.getTags());
|
||||
|
@ -795,4 +800,14 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
public List<ReferenceDTO> getReference(ReferenceRequest request) {
|
||||
return extApiDefinitionMapper.getReference(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验TAG长度
|
||||
* @param tags 标签集合
|
||||
*/
|
||||
public void checkTagLength(List<String> tags) {
|
||||
if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) {
|
||||
throw new MSException(Translator.getWithArgs("tags_size_large_than", String.valueOf(MAX_TAG_SIZE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,7 @@ import io.metersphere.sdk.dto.api.result.RequestResult;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.sdk.util.*;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
|
@ -201,7 +198,7 @@ public class ApiScenarioReportService {
|
|||
List<ApiScenarioReportStepDTO> deatilList = extApiScenarioReportMapper.selectStepDeatilByReportId(id);
|
||||
//根据stepId进行分组
|
||||
Map<String, List<ApiScenarioReportStepDTO>> detailMap = deatilList.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getStepId));
|
||||
scenarioReportSteps.forEach(step -> {
|
||||
scenarioReportSteps.parallelStream().forEach(step -> {
|
||||
List<ApiScenarioReportStepDTO> details = detailMap.get(step.getStepId());
|
||||
if (CollectionUtils.isNotEmpty(details)) {
|
||||
details.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getLoopIndex));
|
||||
|
@ -235,12 +232,14 @@ public class ApiScenarioReportService {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
//将scenarioReportSteps按照parentId进行分组 值为list 然后根据sort进行排序
|
||||
Map<String, List<ApiScenarioReportStepDTO>> scenarioReportStepMap = scenarioReportSteps.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getParentId));
|
||||
// TODO 查询修改
|
||||
List<ApiScenarioReportStepDTO> steps = scenarioReportStepMap.get("NONE");
|
||||
steps.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
||||
getStepTree(steps, scenarioReportStepMap);
|
||||
|
||||
scenarioReportDTO.setStepTotal(steps.size());
|
||||
scenarioReportDTO.setRequestTotal(scenarioReportDTO.getErrorCount() + scenarioReportDTO.getPendingCount() + scenarioReportDTO.getSuccessCount() + scenarioReportDTO.getFakeErrorCount());
|
||||
scenarioReportDTO.setChildren(steps);
|
||||
|
@ -281,7 +280,7 @@ public class ApiScenarioReportService {
|
|||
ApiScenarioStepType.LOOP_CONTROLLER.name(),
|
||||
ApiScenarioStepType.ONCE_ONLY_CONTROLLER.name(),
|
||||
ApiScenarioStepType.CONSTANT_TIMER.name());
|
||||
for (ApiScenarioReportStepDTO step : steps) {
|
||||
steps.parallelStream().forEach(step -> {
|
||||
List<ApiScenarioReportStepDTO> children = scenarioReportStepMap.get(step.getStepId());
|
||||
if (CollectionUtils.isNotEmpty(children)) {
|
||||
children.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
||||
|
@ -316,7 +315,7 @@ public class ApiScenarioReportService {
|
|||
step.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +355,7 @@ public class ApiScenarioReportService {
|
|||
|
||||
/**
|
||||
* 更新执行中的场景报告
|
||||
*
|
||||
* @param reportId
|
||||
*/
|
||||
public void updateReportStatus(String reportId, String status) {
|
||||
|
|
|
@ -337,6 +337,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
if (CollectionUtils.isEmpty(request.getTags())) {
|
||||
throw new MSException(Translator.get("tags_is_null"));
|
||||
}
|
||||
apiTestCaseService.checkTagLength(request.getTags());
|
||||
if (request.isAppend()) {
|
||||
Map<String, ApiScenario> scenarioMap = extApiScenarioMapper.getTagsByIds(ids, false)
|
||||
.stream()
|
||||
|
@ -346,6 +347,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
if (CollectionUtils.isNotEmpty(v.getTags())) {
|
||||
List<String> orgTags = v.getTags();
|
||||
orgTags.addAll(request.getTags());
|
||||
apiTestCaseService.checkTagLength(orgTags.stream().distinct().toList());
|
||||
v.setTags(orgTags.stream().distinct().toList());
|
||||
} else {
|
||||
v.setTags(request.getTags());
|
||||
|
@ -410,6 +412,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
|
||||
public ApiScenario add(ApiScenarioAddRequest request, String creator) {
|
||||
checkAddExist(request);
|
||||
apiTestCaseService.checkTagLength(request.getTags());
|
||||
ApiScenario scenario = getAddApiScenario(request, creator);
|
||||
scenario.setStepTotal(request.getSteps().size());
|
||||
apiScenarioMapper.insert(scenario);
|
||||
|
@ -655,6 +658,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
public ApiScenario update(ApiScenarioUpdateRequest request, String updater) {
|
||||
checkResourceExist(request.getId());
|
||||
checkUpdateExist(request);
|
||||
apiTestCaseService.checkTagLength(request.getTags());
|
||||
// 更新基础信息
|
||||
ApiScenario scenario = BeanUtils.copyBean(new ApiScenario(), request);
|
||||
scenario.setUpdateUser(updater);
|
||||
|
|
|
@ -929,6 +929,9 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
//标签为空 报错
|
||||
request.setTags(new LinkedHashSet<>());
|
||||
this.requestPost(BATCH_EDIT, request, ERROR_REQUEST_MATCHER);
|
||||
//标签超出10个报错
|
||||
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10", "tag11")));
|
||||
this.requestPost(BATCH_EDIT, request, ERROR_REQUEST_MATCHER);
|
||||
//ids为空的时候
|
||||
request.setTags(new LinkedHashSet<>(List.of("tag1")));
|
||||
request.setSelectAll(true);
|
||||
|
|
Loading…
Reference in New Issue