diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index 22d622f272..1fd1f6b8f5 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -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 testPlans = testPlanMapper.selectByExample(example); - if (CollectionUtils.isEmpty(testPlans)) { - return; - } - List ids = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList()); - doHandleAssociateCase(ids, testPlan); - } else { - //计划 - doHandleAssociateCase(Arrays.asList(id), testPlan); - } - - } - - /** - * 处理复制 关联用例数据 - * - * @param ids - */ - private void doHandleAssociateCase(List ids, TestPlan testPlan) { - testPlanCaseService.saveTestPlanByPlanId(ids, testPlan); - //TODO 复制关联接口用例/接口场景用例 - - } - - /** * 获取单个测试计划或测试计划组详情(用于编辑) * @@ -633,7 +590,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { List 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)) { diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index 87614a18f1..35724cc88e 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -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 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 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 {