refactor(功能用例、测试计划、缺陷管理): 重写功能用例、缺陷、测试计划的批量编辑追加标签逻辑

This commit is contained in:
Jianguo-Genius 2024-07-09 16:34:46 +08:00 committed by 建国
parent 86908a2dc6
commit 2ebdd5dfb4
10 changed files with 77 additions and 99 deletions

View File

@ -192,7 +192,7 @@ public class ApiDefinitionMockService {
apiDefinitionMock.setUpdateTime(System.currentTimeMillis()); apiDefinitionMock.setUpdateTime(System.currentTimeMillis());
apiDefinitionMock.setCreateUser(userId); apiDefinitionMock.setCreateUser(userId);
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
apiDefinitionMock.setTags(apiTestCaseService.parseTags(request.getTags())); apiDefinitionMock.setTags(ServiceUtils.parseTags(request.getTags()));
} }
apiDefinitionMock.setEnable(true); apiDefinitionMock.setEnable(true);
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionMock.getApiDefinitionId()); ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionMock.getApiDefinitionId());
@ -439,7 +439,7 @@ public class ApiDefinitionMockService {
if (CollectionUtils.isNotEmpty(v.getTags())) { if (CollectionUtils.isNotEmpty(v.getTags())) {
List<String> orgTags = v.getTags(); List<String> orgTags = v.getTags();
orgTags.addAll(request.getTags()); orgTags.addAll(request.getTags());
v.setTags(apiTestCaseService.parseTags(orgTags.stream().distinct().toList())); v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList()));
} else { } else {
v.setTags(request.getTags()); v.setTags(request.getTags());
} }
@ -449,7 +449,7 @@ public class ApiDefinitionMockService {
}); });
} }
} else { } else {
updateMock.setTags(apiTestCaseService.parseTags(request.getTags())); updateMock.setTags(ServiceUtils.parseTags(request.getTags()));
mapper.updateByExampleSelective(updateMock, example); mapper.updateByExampleSelective(updateMock, example);
} }
} }

View File

@ -207,7 +207,7 @@ public class ApiDefinitionService extends MoveNodeService {
apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setUpdateTime(System.currentTimeMillis());
apiDefinition.setRefId(apiDefinition.getId()); apiDefinition.setRefId(apiDefinition.getId());
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
apiDefinition.setTags(apiTestCaseService.parseTags(request.getTags())); apiDefinition.setTags(ServiceUtils.parseTags(request.getTags()));
} }
apiDefinitionMapper.insertSelective(apiDefinition); apiDefinitionMapper.insertSelective(apiDefinition);
ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob(); ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob();
@ -261,7 +261,7 @@ public class ApiDefinitionService extends MoveNodeService {
ApiDefinition originApiDefinition = checkApiDefinition(request.getId()); ApiDefinition originApiDefinition = checkApiDefinition(request.getId());
ApiDefinition apiDefinition = new ApiDefinition(); ApiDefinition apiDefinition = new ApiDefinition();
BeanUtils.copyBean(apiDefinition, request); BeanUtils.copyBean(apiDefinition, request);
apiDefinition.setTags(apiTestCaseService.parseTags(apiDefinition.getTags())); apiDefinition.setTags(ServiceUtils.parseTags(apiDefinition.getTags()));
checkResponseNameCode(request.getResponse()); checkResponseNameCode(request.getResponse());
if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) { if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) {
checkUpdateExist(apiDefinition, originApiDefinition); checkUpdateExist(apiDefinition, originApiDefinition);
@ -614,7 +614,7 @@ public class ApiDefinitionService extends MoveNodeService {
if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) {
List<String> tags = collect.get(id).getTags(); List<String> tags = collect.get(id).getTags();
tags.addAll(request.getTags()); tags.addAll(request.getTags());
apiDefinition.setTags(apiTestCaseService.parseTags(tags.stream().distinct().toList())); apiDefinition.setTags(ServiceUtils.parseTags(tags.stream().distinct().toList()));
} else { } else {
apiDefinition.setTags(request.getTags()); apiDefinition.setTags(request.getTags());
} }
@ -629,7 +629,7 @@ public class ApiDefinitionService extends MoveNodeService {
} else { } else {
//替换标签 //替换标签
ApiDefinition apiDefinition = new ApiDefinition(); ApiDefinition apiDefinition = new ApiDefinition();
apiDefinition.setTags(apiTestCaseService.parseTags(request.getTags())); apiDefinition.setTags(ServiceUtils.parseTags(request.getTags()));
apiDefinition.setProjectId(request.getProjectId()); apiDefinition.setProjectId(request.getProjectId());
apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setUpdateTime(System.currentTimeMillis());
apiDefinition.setUpdateUser(userId); apiDefinition.setUpdateUser(userId);

View File

@ -108,9 +108,7 @@ public class ApiTestCaseService extends MoveNodeService {
@Resource @Resource
private FunctionalCaseTestMapper functionalCaseTestMapper; private FunctionalCaseTestMapper functionalCaseTestMapper;
private static final String CASE_TABLE = "api_test_case"; private static final String CASE_TABLE = "api_test_case";
private static final int MAX_TAG_SIZE = 10;
private void checkProjectExist(String projectId) { private void checkProjectExist(String projectId) {
Project project = projectMapper.selectByPrimaryKey(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
@ -179,7 +177,7 @@ public class ApiTestCaseService extends MoveNodeService {
testCase.setCreateTime(System.currentTimeMillis()); testCase.setCreateTime(System.currentTimeMillis());
testCase.setUpdateTime(System.currentTimeMillis()); testCase.setUpdateTime(System.currentTimeMillis());
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
testCase.setTags(this.parseTags(request.getTags())); testCase.setTags(ServiceUtils.parseTags(request.getTags()));
} }
apiTestCaseMapper.insertSelective(testCase); apiTestCaseMapper.insertSelective(testCase);
@ -285,7 +283,7 @@ public class ApiTestCaseService extends MoveNodeService {
testCase.setUpdateUser(userId); testCase.setUpdateUser(userId);
testCase.setUpdateTime(System.currentTimeMillis()); testCase.setUpdateTime(System.currentTimeMillis());
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
testCase.setTags(this.parseTags(request.getTags())); testCase.setTags(ServiceUtils.parseTags(request.getTags()));
} else { } else {
testCase.setTags(null); testCase.setTags(null);
} }
@ -513,7 +511,7 @@ public class ApiTestCaseService extends MoveNodeService {
if (CollectionUtils.isNotEmpty(v.getTags())) { if (CollectionUtils.isNotEmpty(v.getTags())) {
List<String> orgTags = v.getTags(); List<String> orgTags = v.getTags();
orgTags.addAll(request.getTags()); orgTags.addAll(request.getTags());
v.setTags(this.parseTags(orgTags.stream().distinct().toList())); v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList()));
} else { } else {
v.setTags(request.getTags()); v.setTags(request.getTags());
} }
@ -523,7 +521,7 @@ public class ApiTestCaseService extends MoveNodeService {
}); });
} }
} else { } else {
updateCase.setTags(this.parseTags(request.getTags())); updateCase.setTags(ServiceUtils.parseTags(request.getTags()));
mapper.updateByExampleSelective(updateCase, example); mapper.updateByExampleSelective(updateCase, example);
} }
} }
@ -924,18 +922,4 @@ public class ApiTestCaseService extends MoveNodeService {
public List<ReferenceDTO> getReference(ReferenceRequest request) { public List<ReferenceDTO> getReference(ReferenceRequest request) {
return extApiDefinitionMapper.getReference(request); return extApiDefinitionMapper.getReference(request);
} }
/**
* 解析Tag只保留默认长度
*
* @param tags 标签集合
*/
public List<String> parseTags(List<String> tags) {
if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) {
List<String> returnTags = new ArrayList<>(tags);
return returnTags.subList(0, MAX_TAG_SIZE);
} else {
return tags;
}
}
} }

View File

@ -323,7 +323,7 @@ public class ApiScenarioService extends MoveNodeService {
if (CollectionUtils.isNotEmpty(v.getTags())) { if (CollectionUtils.isNotEmpty(v.getTags())) {
List<String> orgTags = v.getTags(); List<String> orgTags = v.getTags();
orgTags.addAll(request.getTags()); orgTags.addAll(request.getTags());
v.setTags(apiTestCaseService.parseTags(orgTags.stream().distinct().toList())); v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList()));
} else { } else {
v.setTags(request.getTags()); v.setTags(request.getTags());
} }
@ -333,7 +333,7 @@ public class ApiScenarioService extends MoveNodeService {
}); });
} }
} else { } else {
updateScenario.setTags(apiTestCaseService.parseTags(request.getTags().stream().distinct().toList())); updateScenario.setTags(ServiceUtils.parseTags(request.getTags().stream().distinct().toList()));
mapper.updateByExampleSelective(updateScenario, example); mapper.updateByExampleSelective(updateScenario, example);
} }
} }
@ -384,7 +384,7 @@ public class ApiScenarioService extends MoveNodeService {
public ApiScenario add(ApiScenarioAddRequest request, String creator) { public ApiScenario add(ApiScenarioAddRequest request, String creator) {
checkAddExist(request); checkAddExist(request);
request.setTags(apiTestCaseService.parseTags(request.getTags())); request.setTags(ServiceUtils.parseTags(request.getTags()));
ApiScenario scenario = getAddApiScenario(request, creator); ApiScenario scenario = getAddApiScenario(request, creator);
scenario.setStepTotal(request.getSteps().size()); scenario.setStepTotal(request.getSteps().size());
apiScenarioMapper.insert(scenario); apiScenarioMapper.insert(scenario);
@ -706,7 +706,7 @@ public class ApiScenarioService extends MoveNodeService {
public ApiScenario update(ApiScenarioUpdateRequest request, String updater) { public ApiScenario update(ApiScenarioUpdateRequest request, String updater) {
checkResourceExist(request.getId()); checkResourceExist(request.getId());
checkUpdateExist(request); checkUpdateExist(request);
request.setTags(apiTestCaseService.parseTags(request.getTags())); request.setTags(ServiceUtils.parseTags(request.getTags()));
// 更新基础信息 // 更新基础信息
ApiScenario scenario = BeanUtils.copyBean(new ApiScenario(), request); ApiScenario scenario = BeanUtils.copyBean(new ApiScenario(), request);
scenario.setUpdateUser(updater); scenario.setUpdateUser(updater);

View File

@ -168,8 +168,6 @@ public class BugService {
public static final Long INTERVAL_POS = 5000L; public static final Long INTERVAL_POS = 5000L;
private static final int MAX_TAG_SIZE = 10;
/** /**
* 缺陷列表查询 * 缺陷列表查询
* *
@ -197,8 +195,7 @@ public class BugService {
* @return 缺陷 * @return 缺陷
*/ */
public Bug addOrUpdate(BugEditRequest request, List<MultipartFile> files, String currentUser, String currentOrgId, boolean isUpdate) { public Bug addOrUpdate(BugEditRequest request, List<MultipartFile> files, String currentUser, String currentOrgId, boolean isUpdate) {
// 前置校验: 标签长度 request.setTags(ServiceUtils.parseTags(request.getTags()));
this.checkTagLength(request.getTags());
/* /*
* 缺陷创建或者修改逻辑: * 缺陷创建或者修改逻辑:
* 1. 判断所属项目是否关联第三方平台; * 1. 判断所属项目是否关联第三方平台;
@ -439,9 +436,6 @@ public class BugService {
* @param currentUser 当前用户 * @param currentUser 当前用户
*/ */
public void batchUpdate(BugBatchUpdateRequest request, String currentUser) { public void batchUpdate(BugBatchUpdateRequest request, String currentUser) {
//校验标签长度
this.checkTagLength(request.getTags());
List<String> batchIds = getBatchIdsByRequest(request); List<String> batchIds = getBatchIdsByRequest(request);
// 批量日志{修改之前} // 批量日志{修改之前}
List<LogDTO> logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-update", List<LogDTO> logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-update",
@ -457,17 +451,16 @@ public class BugService {
bugTagMap.forEach((k, v) -> { bugTagMap.forEach((k, v) -> {
Bug record = new Bug(); Bug record = new Bug();
record.setId(k); record.setId(k);
record.setTags(ListUtils.union(v, request.getTags())); record.setTags(ServiceUtils.parseTags(ListUtils.union(v, request.getTags())));
record.setUpdateUser(currentUser); record.setUpdateUser(currentUser);
record.setUpdateTime(System.currentTimeMillis()); record.setUpdateTime(System.currentTimeMillis());
//校验标签长度
this.checkTagLength(record.getTags());
//入库 //入库
batchMapper.updateByPrimaryKeySelective(record); batchMapper.updateByPrimaryKeySelective(record);
}); });
sqlSession.flushStatements(); sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} else { } else {
request.setTags(ServiceUtils.parseTags(request.getTags()));
// 标签(覆盖) // 标签(覆盖)
request.setUpdateUser(currentUser); request.setUpdateUser(currentUser);
request.setUpdateTime(System.currentTimeMillis()); request.setUpdateTime(System.currentTimeMillis());
@ -1861,17 +1854,6 @@ public class BugService {
return t -> keySet.add(function.apply(t)); return t -> keySet.add(function.apply(t));
} }
/**
* 校验TAG长度
*
* @param tags 标签集合
*/
private void checkTagLength(List<String> tags) {
if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) {
throw new MSException(Translator.getWithArgs("bug_tags_size_large_than", String.valueOf(MAX_TAG_SIZE)));
}
}
/** /**
* 构建缺陷本地附件 * 构建缺陷本地附件
* *

View File

@ -259,10 +259,10 @@ public class BugControllerTests extends BaseTest {
MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file); MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file);
this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest());
request.setProjectId("default-project-for-bug"); request.setProjectId("default-project-for-bug");
// 标签超过10个 // V3.1需求标签超过10个不会报错只会留下前10个
request.setTags(List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")); request.setTags(List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"));
paramMap = getMultiPartParam(request, file); paramMap = getMultiPartParam(request, file);
this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is5xxServerError()); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is2xxSuccessful());
request.setTags(null); request.setTags(null);
// 处理人为空 // 处理人为空
request.setTitle("default-bug-title"); request.setTitle("default-bug-title");

View File

@ -185,9 +185,6 @@ public class FunctionalCaseService {
@Resource @Resource
private FunctionalCaseNoticeService functionalCaseNoticeService; private FunctionalCaseNoticeService functionalCaseNoticeService;
private static final int MAX_TAG_SIZE = 10;
public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List<MultipartFile> files, String userId, String organizationId) { public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List<MultipartFile> files, String userId, String organizationId) {
String caseId = IDGenerator.nextStr(); String caseId = IDGenerator.nextStr();
//添加功能用例 //添加功能用例
@ -986,11 +983,9 @@ public class FunctionalCaseService {
if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) {
List<String> tags = collect.get(id).getTags(); List<String> tags = collect.get(id).getTags();
tags.addAll(request.getTags()); tags.addAll(request.getTags());
checkTagsLength(tags); functionalCase.setTags(ServiceUtils.parseTags(tags));
List<String> newTags = tags.stream().distinct().collect(Collectors.toList());
functionalCase.setTags(newTags);
} else { } else {
functionalCase.setTags(request.getTags()); functionalCase.setTags(ServiceUtils.parseTags(request.getTags()));
} }
functionalCase.setId(id); functionalCase.setId(id);
functionalCase.setUpdateTime(System.currentTimeMillis()); functionalCase.setUpdateTime(System.currentTimeMillis());
@ -1012,17 +1007,6 @@ public class FunctionalCaseService {
} }
/**
* 校验追加标签长度
*
* @param tags
*/
private void checkTagsLength(List<String> tags) {
if (tags.size() > MAX_TAG_SIZE) {
throw new MSException(Translator.getWithArgs("tags_length_large_than", String.valueOf(MAX_TAG_SIZE)));
}
}
public Map<String, Long> moduleCount(FunctionalCasePageRequest request, boolean delete) { public Map<String, Long> moduleCount(FunctionalCasePageRequest request, boolean delete) {
if (StringUtils.isNotEmpty(request.getTestPlanId())) { if (StringUtils.isNotEmpty(request.getTestPlanId())) {
this.checkTestPlanRepeatCase(request); this.checkTestPlanRepeatCase(request);

View File

@ -10,6 +10,8 @@ import jakarta.validation.Validator;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -125,4 +127,21 @@ public class ServiceUtils {
} }
return newName; return newName;
} }
/**
* 解析Tag只保留默认长度
*
* @param tags 标签集合
*/
private static final int MAX_TAG_SIZE = 10;
public static List<String> parseTags(List<String> tags) {
if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) {
List<String> returnTags = new ArrayList<>(tags.stream().distinct().toList());
return returnTags.subList(0, MAX_TAG_SIZE);
} else {
return tags;
}
}
} }

View File

@ -104,8 +104,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
@Resource @Resource
private TestPlanReportCaseService testPlanReportCaseService; private TestPlanReportCaseService testPlanReportCaseService;
private static final int MAX_TAG_SIZE = 10;
@Resource @Resource
private TestPlanReportService testPlanReportService; private TestPlanReportService testPlanReportService;
@Resource @Resource
@ -174,7 +172,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator) { private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator) {
//检查模块的合法性 //检查模块的合法性
checkModule(createOrCopyRequest.getModuleId()); checkModule(createOrCopyRequest.getModuleId());
this.checkTagsLength(createOrCopyRequest.getTags());
if (StringUtils.equalsIgnoreCase(createOrCopyRequest.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP) if (StringUtils.equalsIgnoreCase(createOrCopyRequest.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)
&& !StringUtils.equalsIgnoreCase(createOrCopyRequest.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { && !StringUtils.equalsIgnoreCase(createOrCopyRequest.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
throw new MSException(Translator.get("test_plan.group.error")); throw new MSException(Translator.get("test_plan.group.error"));
@ -182,7 +179,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
TestPlan createTestPlan = new TestPlan(); TestPlan createTestPlan = new TestPlan();
BeanUtils.copyBean(createTestPlan, createOrCopyRequest); BeanUtils.copyBean(createTestPlan, createOrCopyRequest);
createTestPlan.setTags(ServiceUtils.parseTags(createTestPlan.getTags()));
if (!StringUtils.equals(createTestPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { if (!StringUtils.equals(createTestPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
TestPlan groupPlan = testPlanGroupService.validateGroupCapacity(createTestPlan.getGroupId(), 1); TestPlan groupPlan = testPlanGroupService.validateGroupCapacity(createTestPlan.getGroupId(), 1);
// 判断测试计划组是否存在 // 判断测试计划组是否存在
@ -398,8 +395,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
//判断标签的变化 //判断标签的变化
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
List<String> tags = new ArrayList<>(request.getTags()); List<String> tags = new ArrayList<>(request.getTags());
this.checkTagsLength(tags); updateTestPlan.setTags(ServiceUtils.parseTags(tags));
updateTestPlan.setTags(tags);
} else { } else {
updateTestPlan.setTags(new ArrayList<>()); updateTestPlan.setTags(new ArrayList<>());
} }
@ -772,11 +768,9 @@ public class TestPlanService extends TestPlanBaseUtilsService {
if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) {
List<String> tags = collect.get(id).getTags(); List<String> tags = collect.get(id).getTags();
tags.addAll(request.getTags()); tags.addAll(request.getTags());
checkTagsLength(tags); testPlan.setTags(ServiceUtils.parseTags(tags));
List<String> newTags = tags.stream().distinct().collect(Collectors.toList());
testPlan.setTags(newTags);
} else { } else {
testPlan.setTags(request.getTags()); testPlan.setTags(ServiceUtils.parseTags(request.getTags()));
} }
testPlan.setId(id); testPlan.setId(id);
testPlan.setUpdateTime(System.currentTimeMillis()); testPlan.setUpdateTime(System.currentTimeMillis());
@ -788,7 +782,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
} else { } else {
//替换标签 //替换标签
TestPlan testPlan = new TestPlan(); TestPlan testPlan = new TestPlan();
testPlan.setTags(request.getTags()); testPlan.setTags(ServiceUtils.parseTags(request.getTags()));
testPlan.setProjectId(request.getProjectId()); testPlan.setProjectId(request.getProjectId());
testPlan.setUpdateTime(System.currentTimeMillis()); testPlan.setUpdateTime(System.currentTimeMillis());
testPlan.setUpdateUser(userId); testPlan.setUpdateUser(userId);
@ -798,18 +792,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
} }
/**
* 校验追加标签长度
*
* @param tags
*/
private void checkTagsLength(List<String> tags) {
if (CollectionUtils.size(tags) > MAX_TAG_SIZE) {
throw new MSException(Translator.getWithArgs("tags_length_large_than", String.valueOf(MAX_TAG_SIZE)));
}
}
//通过项目删除测试计划 //通过项目删除测试计划
public void deleteByProjectId(String projectId) { public void deleteByProjectId(String projectId) {

View File

@ -2380,16 +2380,43 @@ public class TestPlanTests extends BaseTest {
@Order(307) @Order(307)
public void testBatchEditTestPlan() throws Exception { public void testBatchEditTestPlan() throws Exception {
TestPlanBatchEditRequest request = new TestPlanBatchEditRequest(); TestPlanBatchEditRequest request = new TestPlanBatchEditRequest();
request.setTags(Arrays.asList("tag1", "tag2"));
request.setAppend(true);
request.setType("ALL"); request.setType("ALL");
request.setProjectId("songtianyang-fix-wx"); request.setProjectId("songtianyang-fix-wx");
request.setSelectIds(Arrays.asList("wx_test_plan_id_1")); request.setSelectIds(Arrays.asList("wx_test_plan_id_1"));
this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request);
request.setAppend(false); request.setAppend(false);
request.setTags(Arrays.asList("tag3", "tag4")); request.setTags(Arrays.asList("tag3", "tag4"));
request.setSelectIds(Arrays.asList("wx_test_plan_id_1"));
this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request);
//检查标签是否覆盖
TestPlan testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1");
Assertions.assertEquals(2, CollectionUtils.size(testPlan.getTags()));
Assertions.assertTrue(testPlan.getTags().contains("tag3"));
Assertions.assertTrue(testPlan.getTags().contains("tag4"));
request.setAppend(true);
request.setTags(Arrays.asList("tag1", "tag2"));
this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request);
testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1");
Assertions.assertEquals(4, CollectionUtils.size(testPlan.getTags()));
Assertions.assertTrue(testPlan.getTags().contains("tag1"));
Assertions.assertTrue(testPlan.getTags().contains("tag2"));
Assertions.assertTrue(testPlan.getTags().contains("tag3"));
Assertions.assertTrue(testPlan.getTags().contains("tag4"));
//超过10个
request.setTags(Arrays.asList("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag0", "tag11"));
this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request);
testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1");
Assertions.assertEquals(10, CollectionUtils.size(testPlan.getTags()));
Assertions.assertTrue(testPlan.getTags().contains("tag1"));
Assertions.assertTrue(testPlan.getTags().contains("tag2"));
Assertions.assertTrue(testPlan.getTags().contains("tag3"));
Assertions.assertTrue(testPlan.getTags().contains("tag4"));
Assertions.assertTrue(testPlan.getTags().contains("tag5"));
Assertions.assertTrue(testPlan.getTags().contains("tag6"));
Assertions.assertTrue(testPlan.getTags().contains("tag7"));
Assertions.assertTrue(testPlan.getTags().contains("tag8"));
Assertions.assertTrue(testPlan.getTags().contains("tag9"));
Assertions.assertTrue(testPlan.getTags().contains("tag0"));
} }
@Test @Test