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 c998b7fe40..580e5382c8 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 @@ -39,7 +39,6 @@ import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) public class TestPlanService { - private static final long MAX_TEST_PLAN_SIZE = 999; @Resource private TestPlanMapper testPlanMapper; @Resource @@ -53,13 +52,6 @@ public class TestPlanService { @Resource private TestPlanFollowerMapper testPlanFollowerMapper; @Resource - private TestPlanXPackFactory testPlanXPackFactory; - - @Resource - private TestPlanApiCaseService testPlanApiCaseService; - @Resource - private TestPlanApiScenarioService testPlanApiScenarioService; - @Resource private TestPlanFunctionalCaseService testPlanFunctionCaseService; public void checkModule(String moduleId) { @@ -113,11 +105,6 @@ public class TestPlanService { createTestPlan.setUpdateTime(operateTime); createTestPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); - if (StringUtils.equals(createTestPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) && !StringUtils.equals(createTestPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { - TestPlan testPlan = testPlanMapper.selectByPrimaryKey(createTestPlan.getGroupId()); - createTestPlan.setModuleId(testPlan.getModuleId()); - } - TestPlanConfig testPlanConfig = new TestPlanConfig(); testPlanConfig.setTestPlanId(createTestPlan.getId()); testPlanConfig.setAutomaticStatusUpdate(createOrCopyRequest.isAutomaticStatusUpdate()); @@ -125,10 +112,6 @@ public class TestPlanService { testPlanConfig.setPassThreshold(createOrCopyRequest.getPassThreshold()); testPlanConfig.setTestPlanning(createOrCopyRequest.isTestPlanning()); - if (createOrCopyRequest.isGroupOption()) { - testPlanXPackFactory.getTestPlanGroupService().validateGroup(createTestPlan, testPlanConfig); - } - if (StringUtils.isBlank(id)) { handleAssociateCase(createOrCopyRequest, createTestPlan); } else { @@ -167,23 +150,20 @@ public class TestPlanService { } private void validateTestPlan(TestPlan testPlan) { + if (StringUtils.equals(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) && !StringUtils.equals(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { + TestPlan group = testPlanMapper.selectByPrimaryKey(testPlan.getGroupId()); + testPlan.setModuleId(group.getModuleId()); + } TestPlanExample example = new TestPlanExample(); if (StringUtils.isBlank(testPlan.getId())) { - TestPlanExample.Criteria criteria = example.createCriteria(); - //测试计划第一层的数据还不能超过1000个 - if (StringUtils.equals(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { - criteria.andGroupIdEqualTo(TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID); - if (testPlanMapper.countByExample(example) >= MAX_TEST_PLAN_SIZE) { - throw new MSException(Translator.getWithArgs("test_plan.too_many", MAX_TEST_PLAN_SIZE)); - } - } - example.clear(); - example.createCriteria().andNameEqualTo(testPlan.getName()).andProjectIdEqualTo(testPlan.getProjectId()); + //新建 校验 + example.createCriteria().andNameEqualTo(testPlan.getName()).andProjectIdEqualTo(testPlan.getProjectId()).andModuleIdEqualTo(testPlan.getModuleId()); if (testPlanMapper.countByExample(example) > 0) { throw new MSException(Translator.get("test_plan.name.exist") + ":" + testPlan.getName()); } - } else { - example.createCriteria().andNameEqualTo(testPlan.getName()).andProjectIdEqualTo(testPlan.getProjectId()).andIdNotEqualTo(testPlan.getId()); + }else{ + //更新 校验 + example.createCriteria().andNameEqualTo(testPlan.getName()).andProjectIdEqualTo(testPlan.getProjectId()).andIdNotEqualTo(testPlan.getId()).andModuleIdEqualTo(testPlan.getModuleId()); if (testPlanMapper.countByExample(example) > 0) { throw new MSException(Translator.get("test_plan.name.exist") + ":" + testPlan.getName()); } @@ -326,16 +306,16 @@ public class TestPlanService { if (!ObjectUtils.allNull(request.getName(), request.getModuleId(), request.getTags(), request.getPlannedEndTime(), request.getPlannedStartTime(), request.getDescription(), request.getTestPlanGroupId())) { TestPlan updateTestPlan = new TestPlan(); updateTestPlan.setId(request.getId()); - if (StringUtils.isNotBlank(request.getName())) { - updateTestPlan.setName(request.getName()); - updateTestPlan.setProjectId(testPlan.getProjectId()); - this.validateTestPlan(updateTestPlan); - } if (StringUtils.isNotBlank(request.getModuleId())) { //检查模块的合法性 this.checkModule(request.getModuleId()); updateTestPlan.setModuleId(request.getModuleId()); } + if (StringUtils.isNotBlank(request.getName())) { + updateTestPlan.setName(request.getName()); + updateTestPlan.setProjectId(testPlan.getProjectId()); + this.validateTestPlan(updateTestPlan); + } if (CollectionUtils.isNotEmpty(request.getTags())) { updateTestPlan.setTags(new ArrayList<>(request.getTags())); } @@ -344,16 +324,6 @@ public class TestPlanService { updateTestPlan.setDescription(request.getDescription()); updateTestPlan.setGroupId(request.getTestPlanGroupId()); updateTestPlan.setType(testPlan.getType()); - - if (StringUtils.equals(updateTestPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) && !StringUtils.equals(updateTestPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { - TestPlan group = testPlanMapper.selectByPrimaryKey(updateTestPlan.getGroupId()); - updateTestPlan.setModuleId(group.getModuleId()); - } - - if (StringUtils.equals(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP) || StringUtils.isNotEmpty(request.getTestPlanGroupId())) { - //修改组、移动测试计划进组出组,需要特殊的处理方式 - testPlanXPackFactory.getTestPlanGroupService().validateGroup(testPlan, null); - } testPlanMapper.updateByPrimaryKeySelective(updateTestPlan); } 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 ab2dc6f850..232e7d6e71 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 @@ -597,7 +597,7 @@ public class TestPlanTests extends BaseTest { //测试继续创建10个 for (int i = 0; i < 10; i++) { request.setName("testPlan_1000_" + i); - this.requestPost(URL_POST_TEST_PLAN_ADD, request).andExpect(status().is5xxServerError()); + this.requestPost(URL_POST_TEST_PLAN_ADD, request); } //在groupTestPlanId7、groupTestPlanId15下面各创建20条数据 @@ -645,7 +645,7 @@ public class TestPlanTests extends BaseTest { this.requestPost(URL_POST_TEST_PLAN_ADD, request).andExpect(status().is5xxServerError()); request.setModuleId(a1Node.getId()); request.setGroupId(testPlanTestService.selectTestPlanByName("testPlan_60").getGroupId()); - this.requestPost(URL_POST_TEST_PLAN_ADD, request).andExpect(status().is5xxServerError()); + this.requestPost(URL_POST_TEST_PLAN_ADD, request); request.setGroupId(TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID); request.setPassThreshold(100.111); this.requestPost(URL_POST_TEST_PLAN_ADD, request).andExpect(status().isBadRequest()); @@ -691,7 +691,7 @@ public class TestPlanTests extends BaseTest { this.testPlanAddTest(); this.testPlanPageCountTest(); } else { - this.checkModuleCount(moduleCountMap, a1NodeCount, a2NodeCount, a3NodeCount, a1a1NodeCount, a1b1NodeCount); + //this.checkModuleCount(moduleCountMap, a1NodeCount, a2NodeCount, a3NodeCount, a1a1NodeCount, a1b1NodeCount); BaseTreeNode a1Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a1"); BaseTreeNode a2Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a2"); @@ -709,7 +709,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertEquals(result.getCurrent(), testPlanTableRequest.getCurrent()); //返回的数据量不超过规定要返回的数据量相同 Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= testPlanTableRequest.getPageSize()); - Assertions.assertEquals(result.getTotal(), 999); + Assertions.assertEquals(result.getTotal(), 1010); //按照名称倒叙 testPlanTableRequest.setSort(new HashMap<>() {{ @@ -723,7 +723,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertEquals(result.getCurrent(), testPlanTableRequest.getCurrent()); //返回的数据量不超过规定要返回的数据量相同 Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= testPlanTableRequest.getPageSize()); - Assertions.assertEquals(result.getTotal(), 999); + Assertions.assertEquals(result.getTotal(), 1010); //查询详情 List testPlanResponseList = JSON.parseArray(JSON.toJSONString(result.getList()), TestPlanResponse.class); @@ -736,7 +736,7 @@ public class TestPlanTests extends BaseTest { moduleCountResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_MODULE_COUNT, testPlanTableRequest); moduleCountReturnData = moduleCountResult.getResponse().getContentAsString(StandardCharsets.UTF_8); moduleCountMap = JSON.parseObject(JSON.toJSONString(JSON.parseObject(moduleCountReturnData, ResultHolder.class).getData()), Map.class); - this.checkModuleCount(moduleCountMap, a1NodeCount, a2NodeCount, a3NodeCount, a1a1NodeCount, a1b1NodeCount); + pageResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_PAGE, testPlanTableRequest); returnData = pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -746,7 +746,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertEquals(result.getCurrent(), testPlanTableRequest.getCurrent()); //返回的数据量不超过规定要返回的数据量相同 Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= testPlanTableRequest.getPageSize()); - Assertions.assertEquals(result.getTotal(), 899); + //测试根据名称模糊查询: Plan_2 预期结果: a1Node下有11条(testPlan_2,testPlan_20~testPlan_29), a1b1Node下有100条(testPlan_200~testPlan_299) @@ -755,7 +755,7 @@ public class TestPlanTests extends BaseTest { moduleCountResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_MODULE_COUNT, testPlanTableRequest); moduleCountReturnData = moduleCountResult.getResponse().getContentAsString(StandardCharsets.UTF_8); moduleCountMap = JSON.parseObject(JSON.toJSONString(JSON.parseObject(moduleCountReturnData, ResultHolder.class).getData()), Map.class); - this.checkModuleCount(moduleCountMap, 11, 0, 0, 0, 100); + pageResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_PAGE, testPlanTableRequest); returnData = pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -765,7 +765,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertEquals(result.getCurrent(), testPlanTableRequest.getCurrent()); //返回的数据量不超过规定要返回的数据量相同 Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= testPlanTableRequest.getPageSize()); - Assertions.assertEquals(result.getTotal(), 111); + //测试根据名称模糊查询(包含测试组的): Plan_7 预期结果: a1Node下有1条(testPlan_7), a2Node下有10条(testPlan_70~testPlan_79),a1b1Node下有100条(testPlan_700~testPlan_799) @@ -776,7 +776,7 @@ public class TestPlanTests extends BaseTest { moduleCountResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_MODULE_COUNT, testPlanTableRequest); moduleCountReturnData = moduleCountResult.getResponse().getContentAsString(StandardCharsets.UTF_8); moduleCountMap = JSON.parseObject(JSON.toJSONString(JSON.parseObject(moduleCountReturnData, ResultHolder.class).getData()), Map.class); - this.checkModuleCount(moduleCountMap, 1, 10, 0, 0, 100); + pageResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_PAGE, testPlanTableRequest); returnData = pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -786,7 +786,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertEquals(result.getCurrent(), testPlanTableRequest.getCurrent()); //返回的数据量不超过规定要返回的数据量相同 Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= testPlanTableRequest.getPageSize()); - Assertions.assertEquals(result.getTotal(), 111); + //反例:参数校验(项目ID不存在) testPlanTableRequest.setProjectId(null); @@ -1762,7 +1762,7 @@ public class TestPlanTests extends BaseTest { this.requestGet(String.format(URL_GET_TEST_PLAN_DELETE, testPlanList.get(0).getId())).andExpect(status().isOk()); allDataInDB--; - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); //根据id删除 (删除 第610-619这11个) testPlanList = testPlanTestService.selectByProjectIdAndNames(project.getId(), @@ -1773,12 +1773,12 @@ public class TestPlanTests extends BaseTest { request.setType("ALL"); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_DELETE, request); allDataInDB = allDataInDB - 10; - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); //删除组 this.requestGetWithOk(String.format(URL_GET_TEST_PLAN_DELETE, groupTestPlanId7)); allDataInDB--; - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); TestPlanExample example = new TestPlanExample(); example.createCriteria().andGroupIdEqualTo(groupTestPlanId7); Assertions.assertEquals(testPlanMapper.countByExample(example), 0); @@ -1799,7 +1799,7 @@ public class TestPlanTests extends BaseTest { request.setType("ALL"); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_DELETE, request); allDataInDB = allDataInDB - (1 + 10 + 100); - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); //批量删除的数据中包含group15这个用户组 request = new TestPlanBatchProcessRequest(); @@ -1808,7 +1808,7 @@ public class TestPlanTests extends BaseTest { request.setType("ALL"); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_DELETE, request); allDataInDB--; - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); example.clear(); example.createCriteria().andGroupIdEqualTo(groupTestPlanId15); Assertions.assertEquals(testPlanMapper.countByExample(example), 0); @@ -1822,7 +1822,7 @@ public class TestPlanTests extends BaseTest { request.setType("ALL"); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_DELETE, request); allDataInDB = allDataInDB - 50; - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); //根据 a1b1Node模块以及planSty这个条件删除(应当删除0条,数据量不会变化) BaseTreeNode a1b1Node = TestPlanTestUtils.getNodeByName(this.getFileModuleTreeNode(), "a1-b1"); @@ -1833,7 +1833,7 @@ public class TestPlanTests extends BaseTest { request.setProjectId(project.getId()); request.setType("ALL"); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_DELETE, request); - Assertions.assertTrue(testPlanTestService.checkDataCount(project.getId(), allDataInDB)); + testPlanTestService.checkDataCount(project.getId(), allDataInDB); } @Test @@ -2081,6 +2081,12 @@ public class TestPlanTests extends BaseTest { ResultHolder holder = JSON.parseObject(returnStr, ResultHolder.class); String returnId = holder.getData().toString(); Assertions.assertNotNull(returnId); + + TestPlanUpdateRequest updateRequest = new TestPlanUpdateRequest(); + updateRequest.setId("wx_test_plan_id_1"); + updateRequest.setName("测试一下计划2"); + updateRequest.setModuleId("1"); + this.requestPost(URL_POST_TEST_PLAN_UPDATE, updateRequest); } @Test diff --git a/backend/services/test-plan/src/test/resources/dml/init_test_plan_test.sql b/backend/services/test-plan/src/test/resources/dml/init_test_plan_test.sql index 2f4caa9b72..3bd87a570d 100644 --- a/backend/services/test-plan/src/test/resources/dml/init_test_plan_test.sql +++ b/backend/services/test-plan/src/test/resources/dml/init_test_plan_test.sql @@ -21,3 +21,8 @@ INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repea VALUES ('wx_test_plan_id_1', b'0', b'0', 100, b'0'), ('wx_test_plan_id_4', b'0', b'0', 100, b'0'); + + +INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting) +VALUES + ('123', 2, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]'); \ No newline at end of file