diff --git a/backend/framework/provider/src/main/java/io/metersphere/provider/BaseTestPlanProvider.java b/backend/framework/provider/src/main/java/io/metersphere/provider/BaseTestPlanProvider.java new file mode 100644 index 0000000000..6946cca5d0 --- /dev/null +++ b/backend/framework/provider/src/main/java/io/metersphere/provider/BaseTestPlanProvider.java @@ -0,0 +1,7 @@ +package io.metersphere.provider; + +import java.util.List; + +public interface BaseTestPlanProvider { + List selectTestPlanIdByFunctionCaseAndStatus(String caseId, List statusList); +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseTestMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseTestMapper.xml index e8bb08b7ff..6820ac6551 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseTestMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseTestMapper.xml @@ -84,18 +84,23 @@ test_plan_functional_case tpfc LEFT JOIN test_plan tp ON tpfc.test_plan_id = tp.id LEFT JOIN project p ON tp.project_id = p.id - WHERE tpfc.functional_case_id = #{request.caseId} - - AND - ( - tp.name LIKE concat('%', #{request.keyword},'%') - OR tp.num LIKE concat('%', #{request.keyword},'%') - ) - - - - - order by tpfc.last_exec_time desc) as r group by r.test_plan_id + + tpfc.functional_case_id = #{request.caseId} + + + AND + ( + tp.name LIKE concat('%', #{request.keyword},'%') + OR tp.num LIKE concat('%', #{request.keyword},'%') + ) + + + + + + + order by tpfc.last_exec_time desc) as r + group by r.test_plan_id + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.java index 5bf5c101ef..a17345d9b4 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.java @@ -72,4 +72,6 @@ public interface ExtTestPlanApiScenarioMapper { List getPlanScenarioCaseNotDeletedByCollectionIds(@Param("collectionIds") List collectionIds); List selectDistinctExecResult(String projectId); + + List selectDistinctExecResultByTestPlanIds(@Param("testPlanIds") List testPlanIds); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.xml index 16866319b8..857fde8e99 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiScenarioMapper.xml @@ -504,6 +504,29 @@ where test_plan.project_id = #{projectId} AND test_plan.status != 'ARCHIVED' + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java index b33ce00702..102ffaac19 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java @@ -69,4 +69,8 @@ public interface ExtTestPlanFunctionalCaseMapper { List getPlanCaseNotDeletedByCollectionIds(@Param("collectionIds") List collectionIds); List selectDistinctExecResult(String projectId); + + List selectTestPlanIdByFunctionCaseId(String functionalCaseId); + + List selectDistinctExecResultByTestPlanIds(@Param("testPlanIds") List testPlanIds); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml index b39a869739..2d95c4cdc1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.xml @@ -597,4 +597,33 @@ where test_plan.project_id = #{projectId} AND test_plan.status != 'ARCHIVED' + + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index 12d0df67e3..7a42449159 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -118,10 +118,15 @@ public class TestPlanApiCaseService extends TestPlanResourceService { @Resource private ExtApiTestCaseMapper extApiTestCaseMapper; - public List selectDistinctExecResult(String projectId) { + public List selectDistinctExecResultByProjectId(String projectId) { return extTestPlanApiCaseMapper.selectDistinctExecResult(projectId); } + @Override + public List selectDistinctExecResultByTestPlanIds(List testPlanIds) { + return extTestPlanApiCaseMapper.selectDistinctExecResultByTestPlanIds(testPlanIds); + } + @Override public void deleteBatchByTestPlanId(List testPlanIdList) { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index 05a9a5a861..5dd71936bc 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -110,10 +110,15 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { private TestPlanConfigService testPlanConfigService; @Override - public List selectDistinctExecResult(String projectId) { + public List selectDistinctExecResultByProjectId(String projectId) { return extTestPlanApiScenarioMapper.selectDistinctExecResult(projectId); } + @Override + public List selectDistinctExecResultByTestPlanIds(List testPlanIds) { + return extTestPlanApiScenarioMapper.selectDistinctExecResultByTestPlanIds(testPlanIds); + } + @Override public void deleteBatchByTestPlanId(List testPlanIdList) { TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java index 10e3ec8751..7e16644974 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java @@ -76,9 +76,10 @@ public class TestPlanBaseUtilsService { } public String calculateTestPlanStatus(List resultList) { - //同时包含两种状态:进行中 - if (resultList.size() == 1) { - if (resultList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { + List calculateList = resultList.stream().distinct().toList(); + //目前只有三个状态。如果同时包含多种状态(进行中/未开始、进行中/已完成、已完成/未开始、进行中/未开始/已完成),根据算法可得测试计划都会是进行中 + if (calculateList.size() == 1) { + if (calculateList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { return TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED; } else return TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java index 784604eef0..7f00f46da7 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java @@ -64,7 +64,12 @@ public class TestPlanBugService extends TestPlanResourceService { } @Override - public List selectDistinctExecResult(String projectId) { + public List selectDistinctExecResultByProjectId(String projectId) { + return List.of(); + } + + @Override + public List selectDistinctExecResultByTestPlanIds(List testPlanIds) { return List.of(); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index 24c315f2b3..81ce45bf78 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -139,10 +139,15 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { private TestPlanApiScenarioMapper testPlanApiScenarioMapper; @Override - public List selectDistinctExecResult(String projectId) { + public List selectDistinctExecResultByProjectId(String projectId) { return extTestPlanFunctionalCaseMapper.selectDistinctExecResult(projectId); } + @Override + public List selectDistinctExecResultByTestPlanIds(List testPlanIds) { + return extTestPlanFunctionalCaseMapper.selectDistinctExecResultByTestPlanIds(testPlanIds); + } + @Override public long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime) { List copyList = new ArrayList<>(); 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 71693ad9cd..00517aefc1 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 @@ -9,6 +9,7 @@ import io.metersphere.plan.dto.TestPlanGroupCountDTO; import io.metersphere.plan.dto.TestPlanResourceExecResultDTO; import io.metersphere.plan.dto.request.TestPlanTableRequest; import io.metersphere.plan.dto.response.TestPlanResponse; +import io.metersphere.plan.mapper.ExtTestPlanFunctionalCaseMapper; import io.metersphere.plan.mapper.ExtTestPlanMapper; import io.metersphere.plan.mapper.ExtTestPlanModuleMapper; import io.metersphere.plan.mapper.TestPlanMapper; @@ -22,6 +23,7 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; +import jakarta.validation.constraints.NotEmpty; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -43,6 +45,8 @@ public class TestPlanManagementService { @Resource private ExtTestPlanModuleMapper extTestPlanModuleMapper; @Resource + private ExtTestPlanFunctionalCaseMapper extTestPlanFunctionalCaseMapper; + @Resource private TestPlanModuleService testPlanModuleService; @Resource private TestPlanStatisticsService testPlanStatisticsService; @@ -75,6 +79,110 @@ public class TestPlanManagementService { return PageUtils.setPageInfo(page, this.list(request)); } + public void filterTestPlanIdWithStatus(Map> testPlanExecMap, List completedTestPlanIds, List preparedTestPlanIds, List underwayTestPlanIds) { + testPlanExecMap.forEach((planId, resultList) -> { + String result = testPlanBaseUtilsService.calculateTestPlanStatus(resultList); + if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { + completedTestPlanIds.add(planId); + } else if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { + underwayTestPlanIds.add(planId); + } else if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { + preparedTestPlanIds.add(planId); + } + }); + } + + public List selectTestPlanIdByFuncCaseIdAndStatus(String functionalCaseId, @NotEmpty List statusList) { + List returnIdList = new ArrayList<>(); + + List testPlanIdList = extTestPlanFunctionalCaseMapper.selectTestPlanIdByFunctionCaseId(functionalCaseId); + if (CollectionUtils.isEmpty(testPlanIdList)) { + return new ArrayList<>(); + } + List completedTestPlanIds = new ArrayList<>(); + List preparedTestPlanIds = new ArrayList<>(); + List underwayTestPlanIds = new ArrayList<>(); + + Map beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class); + // 将当前项目下未归档的测试计划结果查询出来,进行下列符合条件的筛选 + List execResults = new ArrayList<>(); + beansOfType.forEach((k, v) -> execResults.addAll(v.selectDistinctExecResultByTestPlanIds(testPlanIdList))); + Map> testPlanExecMap = execResults.stream().collect( + Collectors.groupingBy(TestPlanResourceExecResultDTO::getTestPlanId, Collectors.mapping(TestPlanResourceExecResultDTO::getExecResult, Collectors.toList()))); + this.filterTestPlanIdWithStatus(testPlanExecMap, completedTestPlanIds, preparedTestPlanIds, underwayTestPlanIds); + + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { + // 已完成 + returnIdList.addAll(completedTestPlanIds); + } + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { + // 进行中 + returnIdList.addAll(underwayTestPlanIds); + } + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { + // 未开始 + returnIdList.addAll(preparedTestPlanIds); + } + return returnIdList; + } + + private List selectTestPlanIdByProjectIdAndStatus(String projectId, @NotEmpty List statusList) { + List innerIdList = new ArrayList<>(); + Map beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class); + // 将当前项目下未归档的测试计划结果查询出来,进行下列符合条件的筛选 + List execResults = new ArrayList<>(); + beansOfType.forEach((k, v) -> execResults.addAll(v.selectDistinctExecResultByProjectId(projectId))); + Map>> testPlanExecMap = testPlanBaseUtilsService.parseExecResult(execResults); + Map groupCountMap = extTestPlanMapper.countByGroupPlan(projectId) + .stream().collect(Collectors.toMap(TestPlanGroupCountDTO::getGroupId, TestPlanGroupCountDTO::getCount)); + + List completedTestPlanIds = new ArrayList<>(); + List preparedTestPlanIds = new ArrayList<>(); + List underwayTestPlanIds = new ArrayList<>(); + testPlanExecMap.forEach((groupId, planMap) -> { + if (StringUtils.equalsIgnoreCase(groupId, TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { + this.filterTestPlanIdWithStatus(planMap, completedTestPlanIds, preparedTestPlanIds, underwayTestPlanIds); + } else { + long itemPlanCount = groupCountMap.getOrDefault(groupId, 0L); + List itemStatusList = new ArrayList<>(); + if (itemPlanCount > planMap.size()) { + // 存在未执行或者没有用例的测试计划。 此时这种测试计划的状态为未开始 + itemStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED); + } + planMap.forEach((planId, resultList) -> { + itemStatusList.add(testPlanBaseUtilsService.calculateTestPlanStatus(resultList)); + }); + String groupStatus = testPlanBaseUtilsService.calculateStatusByChildren(itemStatusList); + if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { + completedTestPlanIds.add(groupId); + } else if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { + underwayTestPlanIds.add(groupId); + } else if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { + preparedTestPlanIds.add(groupId); + } + } + }); + + testPlanExecMap = null; + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { + // 已完成 + innerIdList.addAll(completedTestPlanIds); + } + + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { + // 进行中 + innerIdList.addAll(underwayTestPlanIds); + } + if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { + // 未开始 有一些测试计划/计划组没有用例 / 测试计划, 在上面的计算中无法过滤。所以用排除法机型处理 + List withoutList = new ArrayList<>(); + withoutList.addAll(completedTestPlanIds); + withoutList.addAll(underwayTestPlanIds); + innerIdList.addAll(extTestPlanMapper.selectIdByProjectIdAndWithoutList(projectId, withoutList)); + } + return innerIdList; + } + @Autowired private ApplicationContext applicationContext; private void initDefaultFilter(TestPlanTableRequest request) { @@ -92,72 +200,9 @@ public class TestPlanManagementService { } else if (!request.getFilter().get("status").contains(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { List statusList = request.getFilter().get("status"); request.getFilter().put("status", defaultStatusList); + //目前未归档的测试计划只有3中类型。所以这里判断如果是3个的话等于直接查询未归档 if (statusList.size() < 3) { - List innerIdList = new ArrayList<>(); - // 条件过滤 - Map beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class); - // 将当前项目下未归档的测试计划结果查询出来,进行下列符合条件的筛选 - List execResults = new ArrayList<>(); - beansOfType.forEach((k, v) -> execResults.addAll(v.selectDistinctExecResult(request.getProjectId()))); - Map>> testPlanExecMap = testPlanBaseUtilsService.parseExecResult(execResults); - Map groupCountMap = extTestPlanMapper.countByGroupPlan(request.getProjectId()) - .stream().collect(Collectors.toMap(TestPlanGroupCountDTO::getGroupId, TestPlanGroupCountDTO::getCount)); - - List completedTestPlanIds = new ArrayList<>(); - List preparedTestPlanIds = new ArrayList<>(); - List underwayTestPlanIds = new ArrayList<>(); - testPlanExecMap.forEach((groupId, planMap) -> { - if (StringUtils.equalsIgnoreCase(groupId, TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { - planMap.forEach((planId, resultList) -> { - String result = testPlanBaseUtilsService.calculateTestPlanStatus(resultList); - if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { - completedTestPlanIds.add(planId); - } else if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { - underwayTestPlanIds.add(planId); - } else if (StringUtils.equals(result, TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { - preparedTestPlanIds.add(planId); - } - }); - } else { - long itemPlanCount = groupCountMap.getOrDefault(groupId, 0L); - List itemStatusList = new ArrayList<>(); - if (itemPlanCount > planMap.size()) { - // 存在未执行或者没有用例的测试计划。 此时这种测试计划的状态为未开始 - itemStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED); - } - planMap.forEach((planId, resultList) -> { - itemStatusList.add(testPlanBaseUtilsService.calculateTestPlanStatus(resultList)); - }); - String groupStatus = testPlanBaseUtilsService.calculateStatusByChildren(itemStatusList); - if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { - completedTestPlanIds.add(groupId); - } else if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { - underwayTestPlanIds.add(groupId); - } else if (StringUtils.equals(groupStatus, TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { - preparedTestPlanIds.add(groupId); - } - } - }); - - testPlanExecMap = null; - if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED)) { - // 已完成 - innerIdList.addAll(completedTestPlanIds); - } - - if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY)) { - // 进行中 - innerIdList.addAll(underwayTestPlanIds); - } - if (statusList.contains(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED)) { - // 未开始 有一些测试计划/计划组没有用例 / 测试计划, 在上面的计算中无法过滤。所以用排除法机型处理 - List withoutList = new ArrayList<>(); - withoutList.addAll(completedTestPlanIds); - withoutList.addAll(underwayTestPlanIds); - innerIdList.addAll(extTestPlanMapper.selectIdByProjectIdAndWithoutList(request.getProjectId(), withoutList)); - withoutList = null; - } - request.setInnerIds(innerIdList); + request.setInnerIds(this.selectTestPlanIdByProjectIdAndStatus(request.getProjectId(), statusList)); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java index 78a480840a..edb93629e7 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java @@ -68,7 +68,9 @@ public abstract class TestPlanResourceService extends TestPlanSortService { public abstract long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime); - public abstract List selectDistinctExecResult(String projectId); + public abstract List selectDistinctExecResultByProjectId(String projectId); + + public abstract List selectDistinctExecResultByTestPlanIds(List testPlanIds); /** * 关联用例 diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanBugControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanBugControllerTests.java index 35fc35177a..f7edd7588d 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanBugControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanBugControllerTests.java @@ -2,6 +2,7 @@ package io.metersphere.plan.controller; import io.metersphere.plan.dto.request.TestPlanBugPageRequest; import io.metersphere.plan.dto.response.TestPlanBugPageResponse; +import io.metersphere.plan.service.TestPlanBugService; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.util.JSON; @@ -30,6 +31,8 @@ public class TestPlanBugControllerTests extends BaseTest { @Resource private ProjectMapper projectMapper; + @Resource + private TestPlanBugService testPlanBugService; public static final String TEST_PLAN_BUG_PAGE = "/test-plan/bug/page"; @@ -98,4 +101,13 @@ public class TestPlanBugControllerTests extends BaseTest { this.requestGet(TEST_PLAN_DELETE + "/test-plan-id-for-bug"); this.requestGet(TEST_PLAN_DELETE + "/test-plan-id-for-bug-1"); } + + @Test + @Order(4) + void emptyFunctionTest() throws Exception { + testPlanBugService.caseExecResultCount("testPlanId"); + testPlanBugService.selectDistinctExecResultByTestPlanIds(null); + testPlanBugService.updatePos(null, 0); + testPlanBugService.refreshPos(null); + } } 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 6376c51dd2..fa951fb536 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 @@ -2431,4 +2431,61 @@ public class TestPlanTests extends BaseTest { testPlanService.deletePlanCollectionResource(List.of("init_collection-delete-4")); testPlanService.deletePlanCollectionResource(List.of("init_collection-delete-1", "init_collection-delete-2", "init_collection-delete-3")); } + + @Test + @Order(310) + void testStatusSelectMethod() { + //initSQL中,功能用例id:oasis_fc_1 的数据关联到了测试计划 + List testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_PREPARED); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + testPlanStatusList = new ArrayList<>(); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED); + testPlanStatusList.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY); + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus("oasis_fc_1", testPlanStatusList); + + //测试不存在的数据 + testPlanManagementService.selectTestPlanIdByFuncCaseIdAndStatus(IDGenerator.nextStr(), testPlanStatusList); + + Map> testPlanExecMap = new HashMap<>(); + testPlanExecMap.put("test1", new ArrayList<>() {{ + this.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED); + }}); + testPlanExecMap.put("test2", new ArrayList<>() {{ + this.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY); + }}); + testPlanExecMap.put("test3", new ArrayList<>() {{ + this.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_UNDERWAY); + this.add(TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED); + }}); + List completedTestPlanIds = new ArrayList<>(); + List preparedTestPlanIds = new ArrayList<>(); + List underwayTestPlanIds = new ArrayList<>(); + testPlanManagementService.filterTestPlanIdWithStatus(testPlanExecMap, completedTestPlanIds, preparedTestPlanIds, underwayTestPlanIds); + Assertions.assertEquals(1, completedTestPlanIds.size()); + Assertions.assertEquals("test1", completedTestPlanIds.getFirst()); + + Assertions.assertEquals(1, preparedTestPlanIds.size()); + Assertions.assertEquals("test2", preparedTestPlanIds.getFirst()); + + Assertions.assertEquals(1, underwayTestPlanIds.size()); + Assertions.assertEquals("test3", underwayTestPlanIds.getFirst()); + } + }