fix(测试计划): 测试计划关联接口用例增加协议

This commit is contained in:
WangXu10 2024-07-19 17:21:16 +08:00 committed by 刘瑞斌
parent 043776f9b7
commit f66600db11
5 changed files with 40 additions and 11 deletions

View File

@ -10,7 +10,6 @@ import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.dto.NodeSortQueryParam; import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.AssociateOtherCaseRequest;
import io.metersphere.request.TestCasePageProviderRequest; import io.metersphere.request.TestCasePageProviderRequest;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -103,11 +102,11 @@ public interface ExtApiTestCaseMapper {
ApiTestCase getCaseByReportId(String resourceId); ApiTestCase getCaseByReportId(String resourceId);
List<ApiTestCase> selectAllApiCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId); List<ApiTestCase> selectAllApiCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
List<ApiTestCase> getListBySelectModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("moduleIds") List<String> moduleIds, @Param("testPlanId") String testPlanId); List<ApiTestCase> getListBySelectModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("moduleIds") List<String> moduleIds, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
List<ApiTestCase> getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId); List<ApiTestCase> getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
List<ApiTestCase> getCaseListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId); List<ApiTestCase> getCaseListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
} }

View File

@ -624,8 +624,15 @@
api_test_case.create_user, api_test_case.create_user,
api_test_case.environment_id api_test_case.environment_id
from api_test_case from api_test_case
INNER JOIN api_definition ON api_test_case.api_definition_id = api_definition.id
where api_test_case.deleted = false where api_test_case.deleted = false
and api_test_case.project_id = #{projectId} and api_test_case.project_id = #{projectId}
<if test="protocols != null and protocols.size() > 0">
and api_definition.protocol in
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
#{protocol}
</foreach>
</if>
<if test="!isRepeat"> <if test="!isRepeat">
AND api_test_case.id not in ( 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} 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 @@
<foreach collection="moduleIds" item="moduleId" open="(" separator="," close=")"> <foreach collection="moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId} #{moduleId}
</foreach> </foreach>
<if test="protocols != null and protocols.size() > 0">
and api_definition.protocol in
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
#{protocol}
</foreach>
</if>
<if test="!isRepeat"> <if test="!isRepeat">
AND api_test_case.id not in ( AND api_test_case.id not in (
select api_case_id from test_plan_api_case where test_plan_id = #{testPlanId} select api_case_id from test_plan_api_case where test_plan_id = #{testPlanId}
@ -670,6 +683,12 @@
<foreach collection="ids" item="id" separator="," open="(" close=")"> <foreach collection="ids" item="id" separator="," open="(" close=")">
#{id} #{id}
</foreach> </foreach>
<if test="protocols != null and protocols.size() > 0">
and api_definition.protocol in
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
#{protocol}
</foreach>
</if>
</select> </select>
@ -687,6 +706,12 @@
<foreach collection="ids" item="id" separator="," open="(" close=")"> <foreach collection="ids" item="id" separator="," open="(" close=")">
#{id} #{id}
</foreach> </foreach>
<if test="protocols != null and protocols.size() > 0">
and api_definition.protocol in
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
#{protocol}
</foreach>
</if>
</select> </select>

View File

@ -40,5 +40,8 @@ public class TestPlanCollectionAssociateDTO implements Serializable {
@Schema(description = "场景计划集id") @Schema(description = "场景计划集id")
private String apiScenarioCollectionId; private String apiScenarioCollectionId;
@Schema(description = "协议")
private List<String> protocols;
} }

View File

@ -589,20 +589,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
moduleMaps.remove(MODULE_ALL); moduleMaps.remove(MODULE_ALL);
if (selectAllModule) { if (selectAllModule) {
// 选择了全部模块 // 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId()); List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId(), apiCase.getModules().getProtocols());
buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList); buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList);
} else { } else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps); AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<ApiTestCase> apiTestCaseList = new ArrayList<>(); List<ApiTestCase> apiTestCaseList = new ArrayList<>();
//获取全选的模块数据 //获取全选的模块数据
if (CollectionUtils.isNotEmpty(dto.getModuleIds())) { 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())) { if (CollectionUtils.isNotEmpty(dto.getSelectIds())) {
CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList()); CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList());
//获取选中的ids数据 //获取选中的ids数据
List<ApiTestCase> selectIdList = extApiTestCaseMapper.getListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId()); List<ApiTestCase> selectIdList = extApiTestCaseMapper.getListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId(), apiCase.getModules().getProtocols());
apiTestCaseList.addAll(selectIdList); apiTestCaseList.addAll(selectIdList);
} }
@ -631,20 +631,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
Map<String, ModuleSelectDTO> moduleMaps = apiCase.getModules().getModuleMaps(); Map<String, ModuleSelectDTO> moduleMaps = apiCase.getModules().getModuleMaps();
if (selectAllModule) { if (selectAllModule) {
// 选择了全部模块 // 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId()); List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId(), apiCase.getModules().getProtocols());
buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList); buildTestPlanApiCaseDTO(apiCase.getCollectionId(), apiTestCaseList, testPlan, user, testPlanApiCaseList);
} else { } else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps); AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<ApiTestCase> apiTestCaseList = new ArrayList<>(); List<ApiTestCase> apiTestCaseList = new ArrayList<>();
//获取全选的模块数据 //获取全选的模块数据
if (CollectionUtils.isNotEmpty(dto.getModuleIds())) { 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())) { if (CollectionUtils.isNotEmpty(dto.getSelectIds())) {
CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList()); CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList());
//获取选中的ids数据 //获取选中的ids数据
List<ApiTestCase> selectIdList = extApiTestCaseMapper.getCaseListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId()); List<ApiTestCase> selectIdList = extApiTestCaseMapper.getCaseListBySelectIds(apiCase.getModules().getProjectId(), dto.getSelectIds(), testPlan.getId(), apiCase.getModules().getProtocols());
apiTestCaseList.addAll(selectIdList); apiTestCaseList.addAll(selectIdList);
} }

View File

@ -303,6 +303,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
associateDTO.setAssociateType(type); associateDTO.setAssociateType(type);
associateDTO.setProjectId("wxx_1234"); associateDTO.setProjectId("wxx_1234");
associateDTO.setModuleMaps(buildModuleMap()); associateDTO.setModuleMaps(buildModuleMap());
associateDTO.setProtocols(List.of("HTTP"));
return associateDTO; return associateDTO;
} }
@ -320,6 +321,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
associateDTO.setSelectAllModule(true); associateDTO.setSelectAllModule(true);
associateDTO.setAssociateType(type); associateDTO.setAssociateType(type);
associateDTO.setProjectId("wxx_1234"); associateDTO.setProjectId("wxx_1234");
associateDTO.setProtocols(List.of("HTTP"));
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>(); Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO(); ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();