From 8ca4f2743299d760a1b5c687567e0c621086952b Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 23 Jan 2024 19:00:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=9F=A5=E8=AF=A2=E5=A4=84?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=84?= =?UTF-8?q?=E5=86=85=E6=95=B0=E6=8D=AE=E7=9A=84=E6=9F=A5=E8=AF=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/dto/response/TestPlanResponse.java | 4 +++- .../service/TestPlanManagementService.java | 20 ++++++++++++++++-- .../plan/service/TestPlanService.java | 1 - .../plan/controller/TestPlanTests.java | 21 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java index d29eb8a436..c5c0cdf783 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java @@ -17,6 +17,8 @@ public class TestPlanResponse { private String name; @Schema(description = "状态") private String status; + @Schema(description = "测试计划类型 测试计划/测试计划组") + private String type; @Schema(description = "标签") private List tags; @Schema(description = "定时任务") @@ -30,7 +32,7 @@ public class TestPlanResponse { @Schema(description = "模块Id") private String moduleId; @Schema(description = "测试计划组内的测试计划") - List testPlanItem; + List children; @Schema(description = "测试计划组Id") private String testPlanGroupId; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java index 71b45c336c..21ffc22bea 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java @@ -11,6 +11,7 @@ import io.metersphere.plan.mapper.ExtTestPlanModuleMapper; import io.metersphere.project.domain.Project; import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.mapper.ProjectMapper; +import io.metersphere.sdk.constants.TestPlanConstants; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; @@ -18,6 +19,7 @@ import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,12 +76,26 @@ public class TestPlanManagementService { private List getTableList(TestPlanQueryConditions request) { List testPlanResponses = extTestPlanMapper.selectByConditions(request); testPlanResponses.forEach(item -> { - item.setModuleName(testPlanModuleService.getNameById(item.getModuleId())); - //todo 定时任务相关信息处理 + if (StringUtils.equals(item.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + TestPlanQueryConditions childrenCondition = new TestPlanQueryConditions(); + childrenCondition.setProjectId(request.getProjectId()); + childrenCondition.setGroupId(item.getId()); + item.setChildren(extTestPlanMapper.selectByConditions(childrenCondition)); + } + this.initTestPlanResponse(item); }); return testPlanResponses; } + private void initTestPlanResponse(TestPlanResponse testPlanResponse) { + testPlanResponse.setModuleName(testPlanModuleService.getNameById(testPlanResponse.getModuleId())); + //todo 定时任务相关信息处理 + + if (CollectionUtils.isNotEmpty(testPlanResponse.getChildren())) { + testPlanResponse.getChildren().forEach(this::initTestPlanResponse); + } + } + public void checkModuleIsOpen(String resourceId, String resourceType, List moduleMenus) { Project project; 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 41326cb2b1..f619b2535d 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 @@ -229,7 +229,6 @@ public class TestPlanService { response.setId(id); /* todo 统计:测试进度、通过率、用例数、Bug数量(这些比较慢的查询,是否需要另开接口查询) - Q:测试计划组需要查询这些数据吗? */ response.setFunctionalCaseCount(0); 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 1d49bf9aec..14ac924854 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 @@ -749,6 +749,27 @@ public class TestPlanTests extends BaseTest { 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) + testPlanTableRequest.setKeyword("Plan_7"); + testPlanTableRequest.setSort(new HashMap<>() {{ + this.put("num", "asc"); + }}); + 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); + resultHolder = JSON.parseObject(returnData, ResultHolder.class); + result = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Pager.class); + //返回值的页码和当前页码相同 + 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); this.requestPost(URL_POST_TEST_PLAN_MODULE_COUNT, testPlanTableRequest).andExpect(status().isBadRequest());