diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java index 70a47cb645..f2b752a8d7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java @@ -10,7 +10,6 @@ import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.dto.NodeSortQueryParam; import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.TestCasePageProviderRequest; -import io.metersphere.sdk.dto.AssociateCaseDTO; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.OptionDTO; import org.apache.ibatis.annotations.Mapper; @@ -103,11 +102,11 @@ public interface ExtApiTestCaseMapper { ApiTestCase getCaseByReportId(String resourceId); - List selectAllApiCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId); + List selectAllApiCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId, @Param("protocols") List protocols); - List getListBySelectModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("moduleIds") List moduleIds, @Param("testPlanId") String testPlanId); + List getListBySelectModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("moduleIds") List moduleIds, @Param("testPlanId") String testPlanId, @Param("protocols") List protocols); - List getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List ids, @Param("testPlanId") String testPlanId); + List getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List ids, @Param("testPlanId") String testPlanId, @Param("protocols") List protocols); - List getCaseListBySelectIds(@Param("projectId") String projectId, @Param("ids") List ids, @Param("testPlanId") String testPlanId); + List getCaseListBySelectIds(@Param("projectId") String projectId, @Param("ids") List ids, @Param("testPlanId") String testPlanId, @Param("protocols") List protocols); } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml index 72e72ac72c..baec5ee9f1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml @@ -624,8 +624,15 @@ api_test_case.create_user, api_test_case.environment_id from api_test_case + INNER JOIN api_definition ON api_test_case.api_definition_id = api_definition.id where api_test_case.deleted = false and api_test_case.project_id = #{projectId} + + and api_definition.protocol in + + #{protocol} + + AND api_test_case.id not in ( select test_plan_api_case.api_case_id from test_plan_api_case where test_plan_api_case.test_plan_id = #{testPlanId} @@ -649,6 +656,12 @@ #{moduleId} + + and api_definition.protocol in + + #{protocol} + + AND api_test_case.id not in ( select api_case_id from test_plan_api_case where test_plan_id = #{testPlanId} @@ -670,6 +683,12 @@ #{id} + + and api_definition.protocol in + + #{protocol} + + @@ -687,6 +706,12 @@ #{id} + + and api_definition.protocol in + + #{protocol} + + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanCollectionAssociateDTO.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanCollectionAssociateDTO.java index 4ab80d33b7..71655ff4d0 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanCollectionAssociateDTO.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/TestPlanCollectionAssociateDTO.java @@ -40,5 +40,8 @@ public class TestPlanCollectionAssociateDTO implements Serializable { @Schema(description = "场景计划集id") private String apiScenarioCollectionId; + @Schema(description = "协议") + private List protocols; + } 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 e416701e39..cef8d34bfa 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 @@ -589,20 +589,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService { moduleMaps.remove(MODULE_ALL); if (selectAllModule) { // 选择了全部模块 - List apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId()); + List apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId(), apiCase.getModules().getProtocols()); buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList); } else { AssociateCaseDTO dto = super.getCaseIds(moduleMaps); List apiTestCaseList = new ArrayList<>(); //获取全选的模块数据 if (CollectionUtils.isNotEmpty(dto.getModuleIds())) { - apiTestCaseList = extApiTestCaseMapper.getListBySelectModules(isRepeat, apiCase.getModules().getProjectId(), dto.getModuleIds(), testPlan.getId()); + apiTestCaseList = extApiTestCaseMapper.getListBySelectModules(isRepeat, apiCase.getModules().getProjectId(), dto.getModuleIds(), testPlan.getId(), apiCase.getModules().getProtocols()); } if (CollectionUtils.isNotEmpty(dto.getSelectIds())) { CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList()); //获取选中的ids数据 - List selectIdList = extApiTestCaseMapper.getListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId()); + List selectIdList = extApiTestCaseMapper.getListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId(), apiCase.getModules().getProtocols()); apiTestCaseList.addAll(selectIdList); } @@ -631,20 +631,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService { Map moduleMaps = apiCase.getModules().getModuleMaps(); if (selectAllModule) { // 选择了全部模块 - List apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId()); + List apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId(), apiCase.getModules().getProtocols()); buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList); } else { AssociateCaseDTO dto = super.getCaseIds(moduleMaps); List apiTestCaseList = new ArrayList<>(); //获取全选的模块数据 if (CollectionUtils.isNotEmpty(dto.getModuleIds())) { - apiTestCaseList = extApiTestCaseMapper.getListBySelectModules(isRepeat, apiCase.getModules().getProjectId(), dto.getModuleIds(), testPlan.getId()); + apiTestCaseList = extApiTestCaseMapper.getListBySelectModules(isRepeat, apiCase.getModules().getProjectId(), dto.getModuleIds(), testPlan.getId(), apiCase.getModules().getProtocols()); } if (CollectionUtils.isNotEmpty(dto.getSelectIds())) { CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList()); //获取选中的ids数据 - List selectIdList = extApiTestCaseMapper.getCaseListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId()); + List selectIdList = extApiTestCaseMapper.getCaseListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId(), apiCase.getModules().getProtocols()); apiTestCaseList.addAll(selectIdList); } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java index 1ae413ace3..b25eb23ea7 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java @@ -303,6 +303,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest { associateDTO.setAssociateType(type); associateDTO.setProjectId("wxx_1234"); associateDTO.setModuleMaps(buildModuleMap()); + associateDTO.setProtocols(List.of("HTTP")); return associateDTO; } @@ -320,6 +321,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest { associateDTO.setSelectAllModule(true); associateDTO.setAssociateType(type); associateDTO.setProjectId("wxx_1234"); + associateDTO.setProtocols(List.of("HTTP")); Map moduleMap = new HashMap<>(); ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();