fix(测试计划): 修复批量复制测试计划组的bug

This commit is contained in:
Jianguo-Genius 2024-06-04 21:14:55 +08:00 committed by 刘瑞斌
parent c2df6e04e2
commit 44e0fbac10
2 changed files with 47 additions and 61 deletions

View File

@ -88,7 +88,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
* 创建测试计划
*/
public TestPlan add(TestPlanCreateRequest testPlanCreateRequest, String operator, String requestUrl, String requestMethod) {
TestPlan testPlan = savePlanDTO(testPlanCreateRequest, operator, null);
TestPlan testPlan = savePlanDTO(testPlanCreateRequest, operator);
// 保存规划节点及配置
saveAllocation(testPlanCreateRequest.getAllocationRequest(), operator, testPlan.getId());
testPlanLogService.saveAddLog(testPlan, operator, requestUrl, requestMethod);
@ -101,9 +101,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
*
* @param createOrCopyRequest
* @param operator
* @param id 复制的计划/计划组id 判断新增还是复制
*/
private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator, String id) {
private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator) {
//检查模块的合法性
checkModule(createOrCopyRequest.getModuleId());
TestPlan createTestPlan = new TestPlan();
@ -125,12 +124,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
testPlanConfig.setRepeatCase(createOrCopyRequest.isRepeatCase());
testPlanConfig.setPassThreshold(createOrCopyRequest.getPassThreshold());
if (StringUtils.isBlank(id)) {
handleAssociateCase(createOrCopyRequest.getBaseAssociateCaseRequest(), operator, createTestPlan);
} else {
//复制
handleCopy(createTestPlan, id);
}
handleAssociateCase(createOrCopyRequest.getBaseAssociateCaseRequest(), operator, createTestPlan);
testPlanMapper.insert(createTestPlan);
testPlanConfigMapper.insert(testPlanConfig);
@ -507,43 +501,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
}
}
/**
* 处理复制
*
* @param testPlan
* @param id
*/
private void handleCopy(TestPlan testPlan, String id) {
if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
//计划组
TestPlanExample example = new TestPlanExample();
example.createCriteria().andGroupIdEqualTo(id);
List<TestPlan> testPlans = testPlanMapper.selectByExample(example);
if (CollectionUtils.isEmpty(testPlans)) {
return;
}
List<String> ids = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList());
doHandleAssociateCase(ids, testPlan);
} else {
//计划
doHandleAssociateCase(Arrays.asList(id), testPlan);
}
}
/**
* 处理复制 关联用例数据
*
* @param ids
*/
private void doHandleAssociateCase(List<String> ids, TestPlan testPlan) {
testPlanCaseService.saveTestPlanByPlanId(ids, testPlan);
//TODO 复制关联接口用例/接口场景用例
}
/**
* 获取单个测试计划或测试计划组详情用于编辑
*
@ -633,7 +590,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
List<TestPlan> copyTestPlanList = testPlanMapper.selectByExample(example);
//批量复制时不允许存在测试计划组下的测试计划
copyTestPlanList = copyTestPlanList.stream().filter(item -> !StringUtils.equalsIgnoreCase(item.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID))
copyTestPlanList = copyTestPlanList.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID))
.collect(Collectors.toList());
//日志
if (CollectionUtils.isNotEmpty(copyTestPlanList)) {

View File

@ -1324,6 +1324,49 @@ public class TestPlanTests extends BaseTest {
}
@Test
@Order(81)
public void copyTestPlan() throws Exception {
BaseTreeNode a1b1Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a1-b1");
// 批量赋值测试计划组下的测试计划其实不复制
TestPlanBatchRequest request = new TestPlanBatchRequest();
request.setProjectId(project.getId());
request.setTargetId(a1b1Node.getId());
request.setSelectIds(Collections.singletonList(simpleTestPlan.getId()));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_COPY, request);
TestPlanExample testPlanExample = new TestPlanExample();
testPlanExample.createCriteria().andNameLike("copy_" + simpleTestPlan.getName() + "%");
TestPlan copyTestPlan = testPlanMapper.selectByExample(testPlanExample).getFirst();
Assertions.assertTrue(copyTestPlan != null);
//删除
this.requestGet(String.format(URL_GET_TEST_PLAN_DELETE, copyTestPlan.getId())).andExpect(status().isOk());
//测试复制测试计划组下的测试计划
List<TestPlanResponse> childs = this.selectByGroupId(groupTestPlanId7);
TestPlanResponse firstChild = childs.getFirst();
request.setSelectIds(Collections.singletonList(firstChild.getId()));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_COPY, request);
copyTestPlan = testPlanTestService.selectTestPlanByName("copy_" + firstChild.getName());
Assertions.assertTrue(copyTestPlan == null);
//批量赋值测试计划组
TestPlan testPlanGroup7 = testPlanMapper.selectByPrimaryKey(groupTestPlanId7);
request.setSelectIds(Collections.singletonList(groupTestPlanId7));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_COPY, request);
testPlanExample.clear();
testPlanExample.createCriteria().andNameLike("copy_" + testPlanGroup7.getName() + "%").andTypeEqualTo(TestPlanConstants.TEST_PLAN_TYPE_GROUP);
TestPlan copyGroup = testPlanMapper.selectByExample(testPlanExample).getFirst();
Assertions.assertTrue(copyGroup != null);
List<TestPlanResponse> copyChild = this.selectByGroupId(copyGroup.getId());
childs = childs.stream().filter(item -> !StringUtils.equalsIgnoreCase(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)).collect(Collectors.toList());
Assertions.assertTrue(copyChild.size() == childs.size());
//删除
this.requestGet(String.format(URL_GET_TEST_PLAN_DELETE, copyGroup.getId())).andExpect(status().isOk());
}
@Test
@Order(91)
@ -2021,20 +2064,6 @@ public class TestPlanTests extends BaseTest {
}
@Test
@Order(304)
public void testBatchCopy() throws Exception {
TestPlanBatchRequest request = new TestPlanBatchRequest();
request.setProjectId("songtianyang-fix-wx");
request.setType("ALL");
request.setTargetId("2");
request.setSelectIds(Arrays.asList("wx_test_plan_id_1", "wx_test_plan_id_2"));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_COPY, request);
}
@Test
@Order(304)
public void testBatchMove() throws Exception {