feat(测试计划): 保存测试规划功能

This commit is contained in:
song-cc-rock 2024-06-04 10:37:48 +08:00 committed by 刘瑞斌
parent eb23e4b212
commit 2019042649
15 changed files with 636 additions and 335 deletions

View File

@ -20,7 +20,7 @@ public class TestPlanAllocation implements Serializable {
private String id; private String id;
@Schema(description = "测试计划ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "测试计划ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_plan_allocation.test_plan_id.not_blank}", groups = {Created.class}) @NotBlank(message = "{test_plan_allocation.id.not_blank}", groups = {Updated.class})
@Size(min = 1, max = 50, message = "{test_plan_allocation.test_plan_id.length_range}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{test_plan_allocation.test_plan_id.length_range}", groups = {Created.class, Updated.class})
private String testPlanId; private String testPlanId;

View File

@ -19,13 +19,16 @@ alter table test_plan
ALTER TABLE test_plan_config DROP `test_planning`; ALTER TABLE test_plan_config DROP `test_planning`;
-- 修改计划报告详情表字段 -- 修改计划报告详情表字段
UPDATE test_plan_report_summary SET bug_count = 0 WHERE bug_count IS NULL;
ALTER TABLE test_plan_report_summary MODIFY `bug_count` BIGINT NOT NULL DEFAULT 0 COMMENT '缺陷数量'; ALTER TABLE test_plan_report_summary MODIFY `bug_count` BIGINT NOT NULL DEFAULT 0 COMMENT '缺陷数量';
ALTER TABLE test_plan_report_summary DROP `report_count`; ALTER TABLE test_plan_report_summary DROP `report_count`;
-- 修改计划报告功能用例表字段 -- 修改计划报告功能用例表字段
UPDATE test_plan_report_function_case SET function_case_bug_count = 0 WHERE function_case_bug_count IS NULL;
ALTER TABLE test_plan_report_function_case MODIFY `function_case_bug_count` BIGINT NOT NULL DEFAULT 0 COMMENT '功能用例关联缺陷数'; ALTER TABLE test_plan_report_function_case MODIFY `function_case_bug_count` BIGINT NOT NULL DEFAULT 0 COMMENT '功能用例关联缺陷数';
-- 修改计划报告缺陷表字段 -- 修改计划报告缺陷表字段
UPDATE test_plan_report_bug SET bug_case_count = 0 WHERE bug_case_count IS NULL;
ALTER TABLE test_plan_report_bug MODIFY `bug_case_count` BIGINT NOT NULL DEFAULT 0 COMMENT '缺陷用例数'; ALTER TABLE test_plan_report_bug MODIFY `bug_case_count` BIGINT NOT NULL DEFAULT 0 COMMENT '缺陷用例数';
-- 修改测试计划关联接口表字段 -- 修改测试计划关联接口表字段

View File

@ -104,7 +104,6 @@ test_plan.batch.log={0}测试计划
test_plan_report_not_exist=测试计划报告不存在 test_plan_report_not_exist=测试计划报告不存在
test_plan_report_id.not_blank=测试计划报告id不能为空 test_plan_report_id.not_blank=测试计划报告id不能为空
test_plan_report_name.not_blank=测试计划报告名称不能为空 test_plan_report_name.not_blank=测试计划报告名称不能为空
run_functional_case=执行功能用例
test_plan_not_exist=测试计划不存在 test_plan_not_exist=测试计划不存在
test_plan.report_id.not_blank=测试计划报告ID不能为空 test_plan.report_id.not_blank=测试计划报告ID不能为空
test_plan.report.share_id.not_blank=测试计划报告分享ID不能为空 test_plan.report.share_id.not_blank=测试计划报告分享ID不能为空
@ -112,3 +111,4 @@ no_plan_to_archive=没有可归档的计划/计划组
test_plan.is.archived=测试计划已归档 test_plan.is.archived=测试计划已归档
test_plan_module_already_exists=同名模块已存在 test_plan_module_already_exists=同名模块已存在
test_plan_report_name_length_range=报告名称长度过长 test_plan_report_name_length_range=报告名称长度过长
test_plan_allocation_type_param_error=测试集所属分类参数错误

View File

@ -112,3 +112,4 @@ no_plan_to_archive=No plans/plan groups to archive
test_plan.is.archived=Test plan has been archived test_plan.is.archived=Test plan has been archived
test_plan_module_already_exists=The module with the same name already exists test_plan_module_already_exists=The module with the same name already exists
test_plan_report_name_length_range=The report name is too long test_plan_report_name_length_range=The report name is too long
test_plan_allocation_type_param_error=The parameter of the allocation type is not correct

View File

@ -112,3 +112,4 @@ no_plan_to_archive=没有可归档的计划/计划组
test_plan.is.archived=测试计划已归档 test_plan.is.archived=测试计划已归档
test_plan_module_already_exists=同名模块已存在 test_plan_module_already_exists=同名模块已存在
test_plan_report_name_length_range=报告名称长度过长 test_plan_report_name_length_range=报告名称长度过长
test_plan_allocation_type_param_error=测试集所属分类参数错误

View File

@ -112,3 +112,4 @@ no_plan_to_archive=沒有可歸檔的計劃/計劃組
test_plan.is.archived=測試計劃已歸檔 test_plan.is.archived=測試計劃已歸檔
test_plan_module_already_exists=同名模塊已存在 test_plan_module_already_exists=同名模塊已存在
test_plan_report_name_length_range=报告名称长度过长 test_plan_report_name_length_range=报告名称长度过长
test_plan_allocation_type_param_error=測試集所屬分類參數錯誤

View File

@ -35,6 +35,7 @@ public class AssociateFunctionalProvider implements BaseAssociateCaseProvider {
Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(ids, testCasePageProviderRequest.getProjectId()); Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(ids, testCasePageProviderRequest.getProjectId());
functionalCases.forEach(functionalCase -> { functionalCases.forEach(functionalCase -> {
List<FunctionalCaseCustomFieldDTO> customFields = caseCustomFiledMap.get(functionalCase.getId()); List<FunctionalCaseCustomFieldDTO> customFields = caseCustomFiledMap.get(functionalCase.getId());
if (CollectionUtils.isNotEmpty(customFields)) {
List<BaseCaseCustomFieldDTO> customs = new ArrayList<>(); List<BaseCaseCustomFieldDTO> customs = new ArrayList<>();
for (FunctionalCaseCustomFieldDTO customField : customFields) { for (FunctionalCaseCustomFieldDTO customField : customFields) {
BaseCaseCustomFieldDTO baseCaseCustomFieldDTO = new BaseCaseCustomFieldDTO(); BaseCaseCustomFieldDTO baseCaseCustomFieldDTO = new BaseCaseCustomFieldDTO();
@ -42,6 +43,7 @@ public class AssociateFunctionalProvider implements BaseAssociateCaseProvider {
customs.add(baseCaseCustomFieldDTO); customs.add(baseCaseCustomFieldDTO);
} }
functionalCase.setCustomFields(customs); functionalCase.setCustomFields(customs);
}
}); });
return functionalCases; return functionalCases;
} }

View File

@ -0,0 +1,24 @@
package io.metersphere.plan.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class TestPlanAllocationTypeDTO {
@Schema(description = "测试集类型ID")
private String id;
@Schema(description = "测试集名称", requiredMode = Schema.RequiredMode.REQUIRED)
private String name;
@Schema(description = "测试集类型", allowableValues = {"FUNCTIONAL", "API", "SCENARIO"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String type;
@Schema(description = "执行方式", allowableValues = {"SERIAL-串行", "PARALLEL-并行"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String executeMethod;
@Schema(description = "位置, 从1开始递增的整数即可", requiredMode = Schema.RequiredMode.REQUIRED)
private Long pos;
}

View File

@ -0,0 +1,29 @@
package io.metersphere.plan.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class TestPlanCollectionInitDTO {
@Schema(description = "测试集节点ID")
private String id;
@Schema(description = "所属测试集类型ID, 类型ID空时传递具体测试集类型名称即可", requiredMode = Schema.RequiredMode.REQUIRED)
private String testCollectionTypeId;
@Schema(description = "测试集名称", requiredMode = Schema.RequiredMode.REQUIRED)
private String name;
@Schema(description = "执行方式", allowableValues = {"SERIAL-串行", "PARALLEL-并行"}, requiredMode = Schema.RequiredMode.REQUIRED)
private String executeMethod;
@Schema(description = "是否使用环境组", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean grouped;
@Schema(description = "环境ID/环境组ID, 根据是否环境组来传递相应的值", requiredMode = Schema.RequiredMode.REQUIRED)
private String environmentId;
@Schema(description = "位置, 从1开始递增的整数即可", requiredMode = Schema.RequiredMode.REQUIRED)
private Long pos;
}

View File

@ -0,0 +1,27 @@
package io.metersphere.plan.dto.request;
import io.metersphere.plan.domain.TestPlanAllocation;
import io.metersphere.plan.dto.TestPlanAllocationTypeDTO;
import io.metersphere.plan.dto.TestPlanCollectionInitDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* 规划创建请求参数-脑图使用
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class TestPlanAllocationCreateRequest {
@Schema(description = "规划节点(分类/类型-第二级)")
private List<TestPlanAllocationTypeDTO> typeNodes;
@Schema(description = "规划节点(功能集-第三级)")
private List<TestPlanCollectionInitDTO> collectionNodes;
@Schema(description = "规划配置")
private TestPlanAllocation config;
}

View File

@ -75,4 +75,7 @@ public class TestPlanCreateRequest {
@Schema(description = "查询用例的条件") @Schema(description = "查询用例的条件")
private BaseAssociateCaseRequest baseAssociateCaseRequest; private BaseAssociateCaseRequest baseAssociateCaseRequest;
@Schema(description = "测试规划请求参数")
private TestPlanAllocationCreateRequest allocationRequest;
} }

View File

@ -53,4 +53,6 @@ public class TestPlanUpdateRequest {
@Schema(description = "测试计划组Id") @Schema(description = "测试计划组Id")
private String testPlanGroupId = TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID; private String testPlanGroupId = TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID;
@Schema(description = "测试规划请求参数")
private TestPlanAllocationCreateRequest allocationRequest;
} }

View File

@ -0,0 +1,14 @@
package io.metersphere.plan.enums;
public enum ExecuteMethod {
/**
* 串行
*/
SERIAL,
/**
* 并行
*/
PARALLEL
}

View File

@ -83,6 +83,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private TestPlanSendNoticeService testPlanSendNoticeService; private TestPlanSendNoticeService testPlanSendNoticeService;
@Resource @Resource
private TestPlanCaseExecuteHistoryMapper testPlanCaseExecuteHistoryMapper; private TestPlanCaseExecuteHistoryMapper testPlanCaseExecuteHistoryMapper;
private static final int MAX_TAG_SIZE = 10; private static final int MAX_TAG_SIZE = 10;
/** /**
@ -90,6 +91,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
*/ */
public TestPlan add(TestPlanCreateRequest testPlanCreateRequest, String operator, String requestUrl, String requestMethod) { public TestPlan add(TestPlanCreateRequest testPlanCreateRequest, String operator, String requestUrl, String requestMethod) {
TestPlan testPlan = savePlanDTO(testPlanCreateRequest, operator, null); TestPlan testPlan = savePlanDTO(testPlanCreateRequest, operator, null);
// 保存规划节点及配置
saveAllocation(testPlanCreateRequest.getAllocationRequest(), operator, testPlan.getId());
testPlanLogService.saveAddLog(testPlan, operator, requestUrl, requestMethod); testPlanLogService.saveAddLog(testPlan, operator, requestUrl, requestMethod);
return testPlan; return testPlan;
} }
@ -152,6 +155,82 @@ public class TestPlanService extends TestPlanBaseUtilsService {
} }
} }
/**
* 保存规划
*
* @param allocationRequest 规划的请求参数
* @param currentUser 当前用户
*/
private void saveAllocation(TestPlanAllocationCreateRequest allocationRequest, String currentUser, String planId) {
// 前置参数校验
checkAllocationParam(allocationRequest);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanAllocationTypeMapper allocationTypeBatchMapper = sqlSession.getMapper(TestPlanAllocationTypeMapper.class);
TestPlanCollectionMapper collectionBatchMapper = sqlSession.getMapper(TestPlanCollectionMapper.class);
// 处理测试集分类
Map<String, String> allocationTypeMap = new HashMap<>();
List<TestPlanAllocationType> addAllocationTypes = new ArrayList<>();
List<TestPlanAllocationType> updateAllocationTypes = new ArrayList<>();
allocationRequest.getTypeNodes().forEach(allocationTypeDTO -> {
TestPlanAllocationType allocationType = new TestPlanAllocationType();
BeanUtils.copyBean(allocationType, allocationTypeDTO);
allocationType.setTestPlanId(planId);
allocationType.setPos(allocationType.getPos() << 6);
if (allocationTypeDTO.getId() == null) {
allocationType.setId(IDGenerator.nextStr());
allocationTypeMap.put(allocationType.getType(), allocationType.getId());
addAllocationTypes.add(allocationType);
} else {
updateAllocationTypes.add(allocationType);
}
});
// 处理测试集
List<TestPlanCollection> addCollections = new ArrayList<>();
List<TestPlanCollection> updateCollections = new ArrayList<>();
if (CollectionUtils.isNotEmpty(allocationRequest.getCollectionNodes())) {
allocationRequest.getCollectionNodes().forEach(collectionNode -> {
TestPlanCollection collection = new TestPlanCollection();
BeanUtils.copyBean(collection, collectionNode);
collection.setTestPlanId(planId);
collection.setPos(collection.getPos() << 6);
if (collection.getId() == null) {
collection.setId(IDGenerator.nextStr());
collection.setTestCollectionTypeId(allocationTypeMap.get(collection.getTestCollectionTypeId()));
collection.setCreateUser(currentUser);
collection.setCreateTime(System.currentTimeMillis());
addCollections.add(collection);
} else {
updateCollections.add(collection);
}
});
}
// 入库 { 测试集分类, 测试集, 规划配置项 }
if (CollectionUtils.isNotEmpty(addAllocationTypes)) {
allocationTypeBatchMapper.batchInsert(addAllocationTypes);
}
if (CollectionUtils.isNotEmpty(updateAllocationTypes)) {
// 仅有三条记录
updateAllocationTypes.forEach(allocationType -> allocationTypeBatchMapper.updateByPrimaryKey(allocationType));
}
if (CollectionUtils.isNotEmpty(addCollections)) {
collectionBatchMapper.batchInsert(addCollections);
}
if (CollectionUtils.isNotEmpty(updateCollections)) {
updateCollections.forEach(collection -> collectionBatchMapper.updateByPrimaryKeySelective(collection));
}
if (allocationRequest.getConfig().getId() == null) {
TestPlanAllocation allocationConfig = allocationRequest.getConfig();
allocationConfig.setId(IDGenerator.nextStr());
allocationConfig.setTestPlanId(planId);
testPlanAllocationMapper.insert(allocationConfig);
} else {
testPlanAllocationMapper.updateByPrimaryKeySelective(allocationRequest.getConfig());
}
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
/** /**
* 删除测试计划 * 删除测试计划
@ -326,6 +405,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
testPlanConfig.setPassThreshold(request.getPassThreshold()); testPlanConfig.setPassThreshold(request.getPassThreshold());
testPlanConfigMapper.updateByPrimaryKeySelective(testPlanConfig); testPlanConfigMapper.updateByPrimaryKeySelective(testPlanConfig);
} }
// 保存规划节点及配置
saveAllocation(request.getAllocationRequest(), userId, testPlan.getId());
testPlanLogService.saveUpdateLog(testPlan, testPlanMapper.selectByPrimaryKey(request.getId()), testPlan.getProjectId(), userId, requestUrl, requestMethod); testPlanLogService.saveUpdateLog(testPlan, testPlanMapper.selectByPrimaryKey(request.getId()), testPlan.getProjectId(), userId, requestUrl, requestMethod);
return testPlan; return testPlan;
} }
@ -721,4 +802,10 @@ public class TestPlanService extends TestPlanBaseUtilsService {
return new TestPlanResourceSortResponse(1); return new TestPlanResourceSortResponse(1);
} }
private void checkAllocationParam(TestPlanAllocationCreateRequest request) {
if (CollectionUtils.size(request.getTypeNodes()) != 3) {
throw new MSException(Translator.get("test_plan_allocation_type_param_error"));
}
}
} }

View File

@ -5,12 +5,13 @@ import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.plan.constants.TestPlanResourceConfig; import io.metersphere.plan.constants.TestPlanResourceConfig;
import io.metersphere.plan.domain.*; import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.TestPlanAllocationTypeDTO;
import io.metersphere.plan.dto.TestPlanCollectionInitDTO;
import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse; import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.dto.response.TestPlanResponse; import io.metersphere.plan.dto.response.TestPlanResponse;
import io.metersphere.plan.mapper.ExtTestPlanMapper; import io.metersphere.plan.enums.ExecuteMethod;
import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.plan.mapper.*;
import io.metersphere.plan.mapper.TestPlanReportMapper;
import io.metersphere.plan.service.*; import io.metersphere.plan.service.*;
import io.metersphere.plan.utils.TestPlanTestUtils; import io.metersphere.plan.utils.TestPlanTestUtils;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
@ -89,6 +90,12 @@ public class TestPlanTests extends BaseTest {
private CommonProjectService commonProjectService; private CommonProjectService commonProjectService;
@Resource @Resource
private TestPlanTestService testPlanTestService; private TestPlanTestService testPlanTestService;
@Resource
private TestPlanAllocationTypeMapper testPlanAllocationTypeMapper;
@Resource
private TestPlanCollectionMapper testPlanCollectionMapper;
@Resource
private TestPlanAllocationMapper testPlanAllocationMapper;
private static final List<CheckLogModel> LOG_CHECK_LIST = new ArrayList<>(); private static final List<CheckLogModel> LOG_CHECK_LIST = new ArrayList<>();
@ -526,6 +533,7 @@ public class TestPlanTests extends BaseTest {
BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest(); BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest();
request.setBaseAssociateCaseRequest(associateCaseRequest); request.setBaseAssociateCaseRequest(associateCaseRequest);
request.setAllocationRequest(buildAllocationParam());
for (int i = 0; i < 999; i++) { for (int i = 0; i < 999; i++) {
String moduleId; String moduleId;
if (i < 50) { if (i < 50) {
@ -637,6 +645,7 @@ public class TestPlanTests extends BaseTest {
itemRequest.setGroupId(groupTestPlanId7); itemRequest.setGroupId(groupTestPlanId7);
itemRequest.setName("testPlan_group7_" + i); itemRequest.setName("testPlan_group7_" + i);
itemRequest.setBaseAssociateCaseRequest(associateCaseRequest); itemRequest.setBaseAssociateCaseRequest(associateCaseRequest);
itemRequest.setAllocationRequest(buildAllocationParam());
if (i == 0) { if (i == 0) {
//测试项目没有开启测试计划模块时能否使用 //测试项目没有开启测试计划模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan"); testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan");
@ -947,6 +956,7 @@ public class TestPlanTests extends BaseTest {
//修改名称 //修改名称
TestPlanUpdateRequest updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); TestPlanUpdateRequest updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setName(IDGenerator.nextStr()); updateRequest.setName(IDGenerator.nextStr());
updateRequest.setAllocationRequest(buildAllocationParam());
//测试项目没有开启测试计划模块时能否使用 //测试项目没有开启测试计划模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan"); testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan");
@ -965,6 +975,7 @@ public class TestPlanTests extends BaseTest {
//修改回来 //修改回来
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setName(testPlan.getName()); updateRequest.setName(testPlan.getName());
updateRequest.setAllocationRequest(buildAllocationParam());
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
returnStr = mvcResult.getResponse().getContentAsString(); returnStr = mvcResult.getResponse().getContentAsString();
holder = JSON.parseObject(returnStr, ResultHolder.class); holder = JSON.parseObject(returnStr, ResultHolder.class);
@ -983,6 +994,7 @@ public class TestPlanTests extends BaseTest {
BaseTreeNode a2Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a2"); BaseTreeNode a2Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a2");
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setModuleId(a2Node.getId()); updateRequest.setModuleId(a2Node.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
returnStr = mvcResult.getResponse().getContentAsString(); returnStr = mvcResult.getResponse().getContentAsString();
holder = JSON.parseObject(returnStr, ResultHolder.class); holder = JSON.parseObject(returnStr, ResultHolder.class);
@ -991,6 +1003,7 @@ public class TestPlanTests extends BaseTest {
testPlanTestService.checkTestPlanUpdateResult(testPlan, testPlanConfig, updateRequest); testPlanTestService.checkTestPlanUpdateResult(testPlan, testPlanConfig, updateRequest);
//修改回来 //修改回来
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setModuleId(testPlan.getModuleId()); updateRequest.setModuleId(testPlan.getModuleId());
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
returnStr = mvcResult.getResponse().getContentAsString(); returnStr = mvcResult.getResponse().getContentAsString();
@ -1001,6 +1014,7 @@ public class TestPlanTests extends BaseTest {
//修改标签 //修改标签
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setTags(new LinkedHashSet<>(Arrays.asList("tag1", "tag2", "tag3", "tag3"))); updateRequest.setTags(new LinkedHashSet<>(Arrays.asList("tag1", "tag2", "tag3", "tag3")));
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
returnStr = mvcResult.getResponse().getContentAsString(); returnStr = mvcResult.getResponse().getContentAsString();
@ -1012,6 +1026,7 @@ public class TestPlanTests extends BaseTest {
//修改计划开始结束时间 //修改计划开始结束时间
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setPlannedStartTime(System.currentTimeMillis()); updateRequest.setPlannedStartTime(System.currentTimeMillis());
updateRequest.setPlannedEndTime(updateRequest.getPlannedStartTime() - 10000); updateRequest.setPlannedEndTime(updateRequest.getPlannedStartTime() - 10000);
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
@ -1024,6 +1039,7 @@ public class TestPlanTests extends BaseTest {
//修改描述 //修改描述
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setDescription("This is desc"); updateRequest.setDescription("This is desc");
mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest); mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_UPDATE, updateRequest);
returnStr = mvcResult.getResponse().getContentAsString(); returnStr = mvcResult.getResponse().getContentAsString();
@ -1035,6 +1051,7 @@ public class TestPlanTests extends BaseTest {
//修改配置项 //修改配置项
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setAutomaticStatusUpdate(true); updateRequest.setAutomaticStatusUpdate(true);
updateRequest.setRepeatCase(true); updateRequest.setRepeatCase(true);
updateRequest.setPassThreshold(43.12); updateRequest.setPassThreshold(43.12);
@ -1046,6 +1063,7 @@ public class TestPlanTests extends BaseTest {
testPlanTestService.checkTestPlanUpdateResult(testPlan, testPlanConfig, updateRequest); testPlanTestService.checkTestPlanUpdateResult(testPlan, testPlanConfig, updateRequest);
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setAutomaticStatusUpdate(false); updateRequest.setAutomaticStatusUpdate(false);
updateRequest.setRepeatCase(false); updateRequest.setRepeatCase(false);
updateRequest.setPassThreshold(56.47); updateRequest.setPassThreshold(56.47);
@ -1060,16 +1078,19 @@ public class TestPlanTests extends BaseTest {
//修改a2节点下的数据91,92的所属测试计划组 //修改a2节点下的数据91,92的所属测试计划组
updateRequest = testPlanTestService.generateUpdateRequest(testPlanTestService.selectTestPlanByName("testPlan_91").getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlanTestService.selectTestPlanByName("testPlan_91").getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setTestPlanGroupId(groupTestPlanId7); updateRequest.setTestPlanGroupId(groupTestPlanId7);
this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest); this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest);
a2NodeCount--; a2NodeCount--;
updateRequest = testPlanTestService.generateUpdateRequest(testPlanTestService.selectTestPlanByName("testPlan_92").getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlanTestService.selectTestPlanByName("testPlan_92").getId());
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setTestPlanGroupId(groupTestPlanId7); updateRequest.setTestPlanGroupId(groupTestPlanId7);
this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest); this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest);
a2NodeCount--; a2NodeCount--;
//修改测试计划组信息 //修改测试计划组信息
updateRequest = testPlanTestService.generateUpdateRequest(groupTestPlanId7); updateRequest = testPlanTestService.generateUpdateRequest(groupTestPlanId7);
updateRequest.setAllocationRequest(buildAllocationParam());
updateRequest.setName(IDGenerator.nextStr()); updateRequest.setName(IDGenerator.nextStr());
updateRequest.setDescription("This is desc"); updateRequest.setDescription("This is desc");
updateRequest.setTags(new LinkedHashSet<>(Arrays.asList("tag1", "tag2", "tag3", "tag3"))); updateRequest.setTags(new LinkedHashSet<>(Arrays.asList("tag1", "tag2", "tag3", "tag3")));
@ -1079,6 +1100,7 @@ public class TestPlanTests extends BaseTest {
//什么都不修改 //什么都不修改
updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId()); updateRequest = testPlanTestService.generateUpdateRequest(testPlan.getId());
updateRequest.setAllocationRequest(buildAllocationParam());
this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest); this.requestPostWithOk(URL_POST_TEST_PLAN_UPDATE, updateRequest);
//因为有条数据被移动了测试计划组里所以检查一下moduleCount. //因为有条数据被移动了测试计划组里所以检查一下moduleCount.
@ -1838,7 +1860,7 @@ public class TestPlanTests extends BaseTest {
TestPlanCreateRequest request = new TestPlanCreateRequest(); TestPlanCreateRequest request = new TestPlanCreateRequest();
request.setProjectId(project.getId()); request.setProjectId(project.getId());
request.setTestPlanning(false); request.setTestPlanning(false);
request.setAllocationRequest(buildAllocationParam());
BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest(); BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest();
associateCaseRequest.setFunctionalSelectIds(Arrays.asList("wx_fc_1", "wx_fc_2")); associateCaseRequest.setFunctionalSelectIds(Arrays.asList("wx_fc_1", "wx_fc_2"));
request.setBaseAssociateCaseRequest(associateCaseRequest); request.setBaseAssociateCaseRequest(associateCaseRequest);
@ -2045,4 +2067,89 @@ public class TestPlanTests extends BaseTest {
this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request);
} }
@Test
@Order(308)
void testSaveAllocation() throws Exception {
TestPlanCreateRequest createRequest = new TestPlanCreateRequest();
BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest();
createRequest.setBaseAssociateCaseRequest(associateCaseRequest);
createRequest.setTestPlanning(true);
createRequest.setProjectId(project.getId());
createRequest.setName("测试一下关联");
createRequest.setPlannedEndTime(null);
createRequest.setPlannedStartTime(null);
createRequest.setRepeatCase(false);
createRequest.setAutomaticStatusUpdate(false);
createRequest.setPassThreshold(100);
createRequest.setDescription(null);
createRequest.setType(TestPlanConstants.TEST_PLAN_TYPE_PLAN);
createRequest.setAllocationRequest(buildAllocationParam());
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_ADD, createRequest);
String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder sortHolder = JSON.parseObject(sortData, ResultHolder.class);
TestPlan testPlan = JSON.parseObject(JSON.toJSONString(sortHolder.getData()), TestPlan.class);
TestPlanAllocationCreateRequest updateRequest = buildAllocationUpdateParam(testPlan.getId());
createRequest.setAllocationRequest(updateRequest);
this.requestPostWithOk(URL_POST_TEST_PLAN_ADD, createRequest);
TestPlanAllocationCreateRequest createRequest1 = buildAllocationParam();
createRequest1.setCollectionNodes(null);
createRequest.setAllocationRequest(createRequest1);
this.requestPostWithOk(URL_POST_TEST_PLAN_ADD, createRequest);
}
private TestPlanAllocationCreateRequest buildAllocationParam() {
TestPlanAllocationCreateRequest request = new TestPlanAllocationCreateRequest();
TestPlanAllocationTypeDTO functionalType = new TestPlanAllocationTypeDTO();
functionalType.setType(CaseType.FUNCTIONAL_CASE.getKey());
functionalType.setName("功能用例");
functionalType.setPos(1L);
functionalType.setExecuteMethod(ExecuteMethod.SERIAL.name());
request.setTypeNodes(List.of(functionalType, functionalType, functionalType));
TestPlanCollectionInitDTO collection = new TestPlanCollectionInitDTO();
collection.setName("默认测试集");
collection.setTestCollectionTypeId(CaseType.FUNCTIONAL_CASE.getKey());
collection.setExecuteMethod(ExecuteMethod.PARALLEL.name());
collection.setGrouped(false);
collection.setEnvironmentId(IDGenerator.nextStr());
collection.setPos(1L);
request.setCollectionNodes(List.of(collection));
TestPlanAllocation allocation = new TestPlanAllocation();
allocation.setTestResourcePoolId(IDGenerator.nextStr());
allocation.setRetryOnFail(true);
allocation.setRetryTimes(10);
allocation.setRetryInterval(1000);
allocation.setRetryType(CaseType.SCENARIO_CASE.getKey());
allocation.setStopOnFail(false);
request.setConfig(allocation);
return request;
}
private TestPlanAllocationCreateRequest buildAllocationUpdateParam(String planId) {
TestPlanAllocationCreateRequest updateParam = new TestPlanAllocationCreateRequest();
TestPlanAllocationTypeExample allocationTypeExample = new TestPlanAllocationTypeExample();
allocationTypeExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanAllocationType> testPlanAllocationTypes = testPlanAllocationTypeMapper.selectByExample(allocationTypeExample);
List<TestPlanAllocationTypeDTO> allocationTypeDTOS = new ArrayList<>();
testPlanAllocationTypes.forEach(allocationType -> {
TestPlanAllocationTypeDTO allocationTypeDTO = new TestPlanAllocationTypeDTO();
BeanUtils.copyBean(allocationTypeDTO, allocationType);
allocationTypeDTOS.add(allocationTypeDTO);
});
TestPlanCollectionExample collectionExample = new TestPlanCollectionExample();
collectionExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanCollection> collections = testPlanCollectionMapper.selectByExample(collectionExample);
List<TestPlanCollectionInitDTO> collectionInitDTOS = new ArrayList<>();
collections.forEach(collection -> {
TestPlanCollectionInitDTO collectionInitDTO = new TestPlanCollectionInitDTO();
BeanUtils.copyBean(collectionInitDTO, collection);
collectionInitDTOS.add(collectionInitDTO);
});
TestPlanAllocationExample example = new TestPlanAllocationExample();
example.createCriteria().andTestPlanIdEqualTo(planId);
TestPlanAllocation allocation = testPlanAllocationMapper.selectByExample(example).get(0);
updateParam.setTypeNodes(allocationTypeDTOS);
updateParam.setCollectionNodes(collectionInitDTOS);
updateParam.setConfig(allocation);
return updateParam;
}
} }