From b4e59664d007598a425e8a850c8a0962c27e0c7c Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 23 May 2024 12:28:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=85=B3=E8=81=94=E7=94=A8=E4=BE=8B=E6=97=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=94=A8=E4=BE=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1040713 --user=宋天阳 【测试计划】模块树-当前项目与其他项目重名-创建模块树失败了 https://www.tapd.cn/55049933/s/1518669 --- .../service/FunctionalCaseService.java | 17 ++++++ .../FunctionalCaseControllerTests.java | 55 +++++++++++++++++++ .../TestPlanAssociateController.java | 4 +- .../plan/service/TestPlanConfigService.java | 2 +- 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 1591bbda1a..9b94d607f4 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -13,9 +13,11 @@ import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.*; import io.metersphere.functional.result.CaseManagementResultCode; import io.metersphere.plan.domain.TestPlanCaseExecuteHistoryExample; +import io.metersphere.plan.domain.TestPlanConfig; import io.metersphere.plan.domain.TestPlanFunctionalCase; import io.metersphere.plan.domain.TestPlanFunctionalCaseExample; import io.metersphere.plan.mapper.TestPlanCaseExecuteHistoryMapper; +import io.metersphere.plan.mapper.TestPlanConfigMapper; import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper; import io.metersphere.project.domain.*; import io.metersphere.project.dto.ModuleCountDTO; @@ -55,6 +57,7 @@ import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.utils.ServiceUtils; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -125,6 +128,9 @@ public class FunctionalCaseService { @Resource private UserLoginService userLoginService; + @Resource + private TestPlanConfigMapper testPlanConfigMapper; + private static final String CASE_MODULE_COUNT_ALL = "all"; private static final String ADD_FUNCTIONAL_CASE_FILE_LOG_URL = "/functional/case/add"; @@ -982,6 +988,9 @@ public class FunctionalCaseService { } public Map moduleCount(FunctionalCasePageRequest request, boolean delete) { + if (StringUtils.isNotEmpty(request.getTestPlanId())) { + this.checkTestPlanRepeatCase(request); + } //查出每个模块节点下的资源数量。 不需要按照模块进行筛选 request.setModuleIds(null); List moduleCountDTOList = extFunctionalCaseMapper.countModuleIdByRequest(request, delete); @@ -994,6 +1003,14 @@ public class FunctionalCaseService { } + private void checkTestPlanRepeatCase(FunctionalCasePageRequest request) { + TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(request.getTestPlanId()); + if (testPlanConfig != null && BooleanUtils.isTrue(testPlanConfig.getRepeatCase())) { + //测试计划允许重复用例,意思就是统计不受测试计划影响。去掉这个条件, + request.setTestPlanId(null); + } + } + public void editPos(PosRequest request) { ServiceUtils.updatePosField(request, FunctionalCase.class, diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java index 64d28909c8..b104f3890a 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseControllerTests.java @@ -13,6 +13,8 @@ import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper; import io.metersphere.functional.request.*; import io.metersphere.functional.result.CaseManagementResultCode; import io.metersphere.functional.utils.FileBaseUtils; +import io.metersphere.plan.domain.TestPlanConfig; +import io.metersphere.plan.mapper.TestPlanConfigMapper; import io.metersphere.project.domain.Notification; import io.metersphere.project.domain.NotificationExample; import io.metersphere.project.mapper.NotificationMapper; @@ -439,6 +441,9 @@ public class FunctionalCaseControllerTests extends BaseTest { Assertions.assertNotNull(editResultHolder); } + @Resource + private TestPlanConfigMapper testPlanConfigMapper; + @Test @Order(5) public void testGetPageList() throws Exception { @@ -494,6 +499,56 @@ public class FunctionalCaseControllerTests extends BaseTest { } Assertions.assertTrue(moduleCount.containsKey("all")); + + { + //测试count接口的入参中包含不存在的测试计划、存在的开启/关闭了重复用例的测试计划 + TestPlanConfig testPlanConfig = new TestPlanConfig(); + testPlanConfig.setTestPlanId(IDGenerator.nextStr()); + testPlanConfig.setRepeatCase(false); + testPlanConfig.setAutomaticStatusUpdate(false); + testPlanConfig.setTestPlanning(false); + testPlanConfig.setPassThreshold(100.00); + + request.setTestPlanId(testPlanConfig.getTestPlanId()); + + mvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_MODULE_COUNT, request); + returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + moduleCount = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Map.class); + Assertions.assertTrue(moduleCount.containsKey("all")); + + //不开启用例重复的测试计划入库,再次调用 + testPlanConfigMapper.insert(testPlanConfig); + + mvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_MODULE_COUNT, request); + returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + moduleCount = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Map.class); + Assertions.assertTrue(moduleCount.containsKey("all")); + + //开启用例重复的测试计划,再次调用 + testPlanConfig.setRepeatCase(true); + testPlanConfigMapper.updateByPrimaryKey(testPlanConfig); + + mvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_MODULE_COUNT, request); + returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + moduleCount = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Map.class); + Assertions.assertTrue(moduleCount.containsKey("all")); + + //使用完后删除该数据 + testPlanConfigMapper.deleteByPrimaryKey(testPlanConfig.getTestPlanId()); + + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java index 0e914a5f47..84d6772d67 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanAssociateController.java @@ -38,9 +38,9 @@ public class TestPlanAssociateController { @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public Pager> getFunctionalCasePage(@Validated @RequestBody FunctionalCasePageRequest request) { - Boolean isRepeat = false; + boolean isRepeat = false; if (StringUtils.isNotBlank(request.getTestPlanId())) { - isRepeat = testPlanConfigService.getConfigById(request.getTestPlanId()); + isRepeat = testPlanConfigService.isRepeatCase(request.getTestPlanId()); } Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java index e77208a97a..f2d7d627aa 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanConfigService.java @@ -27,7 +27,7 @@ public class TestPlanConfigService { testPlanConfigMapper.deleteByExample(example); } - public boolean getConfigById(String testPlanId) { + public boolean isRepeatCase(String testPlanId) { TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(testPlanId); return testPlanConfig.getRepeatCase(); }