diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiCoverageConstants.java b/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiCoverageConstants.java new file mode 100644 index 0000000000..ce0ec9b370 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/constants/ApiCoverageConstants.java @@ -0,0 +1,11 @@ +package io.metersphere.api.constants; + +public class ApiCoverageConstants { + + public static final String COVER_FROM = "coverFrom"; + public static final String UN_COVER_FROM = "unCoverFrom"; + + public static final String API_DEFINITION = "apiDefinition"; + public static final String API_CASE = "apiCase"; + public static final String API_SCENARIO = "apiScenario"; +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java index d5ab676274..02b43ff7f1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java @@ -98,7 +98,7 @@ public class ApiDefinitionController { @CheckOwner(resourceId = "#projectId", resourceType = "project") public ApiCoverageDTO rage(@PathVariable String projectId) { // 筛选出所有 API 的 ID 和 HTTP 类型的 API - List apiDefinitions = extApiDefinitionMapper.selectBaseInfoByProjectId(projectId); + List apiDefinitions = extApiDefinitionMapper.selectBaseInfoByProjectId(projectId, null, null); List apiAllIds = apiDefinitions.stream().map(ApiDefinition::getId).toList(); List httpApiList = apiDefinitions.stream() .filter(api -> StringUtils.equalsIgnoreCase(api.getProtocol(), "http")) @@ -106,12 +106,12 @@ public class ApiDefinitionController { // 获取 API 定义、测试用例 ID 和场景步骤中的 API ID List apiDefinitionIdFromCase = extApiTestCaseMapper.selectApiId(projectId); - List apiInScenarioStep = new ArrayList<>(extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API.name())); - List apiCaseIdInStep = extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API_CASE.name()); + List apiInScenarioStep = new ArrayList<>(extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API.name(), null)); + List apiCaseIdInStep = extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API_CASE.name(), null); // 如果有场景步骤中的 API 用例 ID,追加相关 API ID if (CollectionUtils.isNotEmpty(apiCaseIdInStep)) { - List apiCaseIdInScenarioStep = extApiTestCaseMapper.selectApiIdByCaseId(apiCaseIdInStep); + List apiCaseIdInScenarioStep = extApiTestCaseMapper.selectApiIdByCaseId(apiCaseIdInStep, null, null); apiInScenarioStep.addAll(apiCaseIdInScenarioStep); } @@ -198,6 +198,7 @@ public class ApiDefinitionController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public Pager> getPage(@Validated @RequestBody ApiDefinitionPageRequest request) { + apiDefinitionService.initApiSelectIds(request); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString("id")) ? request.getSortString("id") : request.getDeleted() ? "delete_time desc, id desc" : "pos desc, id desc"); return PageUtils.setPageInfo(page, apiDefinitionService.getApiDefinitionPage(request, SessionUtils.getUserId())); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionPageRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionPageRequest.java index 827634fb05..b5f7c748fd 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionPageRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionPageRequest.java @@ -46,4 +46,10 @@ public class ApiDefinitionPageRequest extends BasePageRequest { @Schema(description = "删除状态(状态为 1 时为回收站数据)") private Boolean deleted = false; + + @Schema(description = "本次查询包含的ID(一般由后台计算后得出)") + private List includeIds = new ArrayList<>(); + + @Schema(description = "本次查询不包含的ID(一般由后台计算后得出)") + private List excludeIds = new ArrayList<>(); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiModuleRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiModuleRequest.java index 9b415fcbec..288d6b484a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiModuleRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiModuleRequest.java @@ -34,4 +34,11 @@ public class ApiModuleRequest extends BaseCondition { @Schema(description = "测试计划id") private String testPlanId; + + @Schema(description = "本次查询包含的ID(一般由后台计算后得出)") + private List includeIds = new ArrayList<>(); + + @Schema(description = "本次查询不包含的ID(一般由后台计算后得出)") + private List excludeIds = new ArrayList<>(); + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java index fb6ec96425..24d06b7795 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java @@ -35,7 +35,7 @@ public interface ExtApiDefinitionMapper { Long getPos(@Param("projectId") String projectId); @BaseConditionFilter - List getIds(@Param("request") TableBatchProcessDTO request, @Param("projectId") String projectId, @Param("protocols") List protocols, @Param("deleted") boolean deleted); + List getIds(@Param("request") TableBatchProcessDTO request, @Param("projectId") String projectId, @Param("protocols") List protocols, @Param("deleted") boolean deleted, @Param("includeIds") List includeIds, @Param("excludeIds") List excludeIds); @BaseConditionFilter List getIdsBySort(@Param("request") TableBatchProcessDTO request, @Param("projectId") String projectId, @Param("protocols") List protocols, @Param("orderColumns") String orderColumns, @Param("deleted") boolean deleted); @@ -129,5 +129,5 @@ public interface ExtApiDefinitionMapper { List getCreateApiList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); - List selectBaseInfoByProjectId(String projectId); + List selectBaseInfoByProjectId(@Param("projectId") String projectId, @Param("protocols") List protocols, @Param("ignoreApiIds") List ignoreApiIds); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml index 9765b718ae..8263123d8c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml @@ -86,6 +86,18 @@ #{item} + + and api_definition.id in + + #{includeId} + + + + and api_definition.id not in + + #{excludeId} + + @@ -264,6 +276,18 @@ and api_definition.project_id = #{request.projectId} + + and api_definition.id in + + #{includeId} + + + + and api_definition.id not in + + #{excludeId} + + and api_definition.protocol in @@ -843,7 +867,19 @@ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.java index 294b2a52ff..a775258480 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.java @@ -26,7 +26,7 @@ public interface ExtApiScenarioStepMapper { */ List getHasBlobRequestStepIds(@Param("scenarioId") String scenarioId); - List selectResourceId(@Param("projectId") String projectId, @Param("stepType") String stepType); + List selectResourceId(@Param("projectId") String projectId, @Param("stepType") String stepType, @Param("protocols") List apiProtocols); List selectCustomRequestConfigByProjectId(String projectId); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.xml index 04f61ac590..d5a8b0c611 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioStepMapper.xml @@ -36,6 +36,16 @@ where step.step_type = #{stepType} AND scenario.project_id = #{projectId} AND scenario.deleted IS FALSE + + AND step.resource_id IN ( + select distinct apiCase.id FROM api_definition api + INNER JOIN api_test_case apiCase ON api.id = apiCase.api_definition_id + WHERE api.project_id = #{projectId} AND api.deleted IS FALSE and api.deleted IS FALSE AND api.protocol IN + + #{protocol} + + ) + + \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java index 735da42a72..14cfe6eb8e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java @@ -18,6 +18,7 @@ import io.metersphere.project.dto.NodeSortDTO; import io.metersphere.project.service.ModuleTreeService; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.request.NodeMoveRequest; @@ -73,6 +74,9 @@ public class ApiDefinitionModuleService extends ModuleTreeService { if (!containRequest || CollectionUtils.isEmpty(request.getProtocols())) { return baseTreeNodes; } + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + request.setExcludeIds(apiDefinitionService.getQueryExcludeIds(request.getFilter(), request.getProjectId(), request.getProtocols())); + request.setIncludeIds(apiDefinitionService.getQueryIncludeIds(request.getFilter(), request.getProjectId(), request.getProtocols())); List apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted); return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index 777c07dbd0..77e6a40937 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -1,8 +1,6 @@ package io.metersphere.api.service.definition; -import io.metersphere.api.constants.ApiConstants; -import io.metersphere.api.constants.ApiDefinitionDocType; -import io.metersphere.api.constants.ApiResourceType; +import io.metersphere.api.constants.*; import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.domain.*; import io.metersphere.api.dto.*; @@ -16,6 +14,7 @@ import io.metersphere.api.mapper.*; import io.metersphere.api.service.ApiCommonService; import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.ApiFileResourceService; +import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.JsonSchemaBuilder; import io.metersphere.plugin.api.spi.AbstractMsTestElement; @@ -53,6 +52,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.collections4.ListUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; @@ -83,6 +83,9 @@ public class ApiDefinitionService extends MoveNodeService { @Resource private ExtApiDefinitionMapper extApiDefinitionMapper; + @Resource + private ExtApiScenarioStepMapper extApiScenarioStepMapper; + @Resource private ExtApiDefinitionModuleMapper extApiDefinitionModuleMapper; @@ -133,8 +136,10 @@ public class ApiDefinitionService extends MoveNodeService { @Resource private OperationLogBlobMapper operationLogBlobMapper; + @Resource private ApiExecuteService apiExecuteService; + @Resource private ApiDefinitionNoticeService apiDefinitionNoticeService; @@ -147,6 +152,77 @@ public class ApiDefinitionService extends MoveNodeService { return list; } + public void initApiSelectIds(ApiDefinitionPageRequest request) { + request.setExcludeIds(this.getQueryExcludeIds(request.getFilter(), request.getProjectId(), request.getProtocols())); + request.setIncludeIds(this.getQueryIncludeIds(request.getFilter(), request.getProjectId(), request.getProtocols())); + } + + public List getQueryIncludeIds(Map> queryFilter, String projectId, List protocol) { + if (queryFilter != null && CollectionUtils.isNotEmpty(queryFilter.get("coverFrom"))) { + String coverFrom = queryFilter.get("coverFrom").getFirst(); + if (ApiCoverageConstants.API_DEFINITION.equals(coverFrom)) { + return this.selectApiIdInCaseAndScenarioStep(projectId, protocol); + } else if (ApiCoverageConstants.API_CASE.equals(coverFrom)) { + return this.selectApiIdInCase(projectId, protocol); + } else if (ApiCoverageConstants.API_SCENARIO.equals(coverFrom)) { + return this.selectApiIdInScenarioStep(projectId, protocol, null); + } + } + return null; + } + + public List getQueryExcludeIds(Map> queryFilter, String projectId, List protocol) { + if (queryFilter != null && CollectionUtils.isNotEmpty(queryFilter.get("unCoverFrom"))) { + String unCoverFrom = queryFilter.get("unCoverFrom").getFirst(); + if (ApiCoverageConstants.API_DEFINITION.equals(unCoverFrom)) { + return this.selectApiIdInCaseAndScenarioStep(projectId, protocol); + } else if (ApiCoverageConstants.API_CASE.equals(unCoverFrom)) { + return this.selectApiIdInCase(projectId, protocol); + } else if (ApiCoverageConstants.API_SCENARIO.equals(unCoverFrom)) { + return this.selectApiIdInScenarioStep(projectId, protocol, null); + } + } + return null; + } + + private List selectApiIdInCaseAndScenarioStep(String projectId, List protocols) { + List apiInCase = this.selectApiIdInCase(projectId, protocols); + List apiInScenarioStep = this.selectApiIdInScenarioStep(projectId, protocols, apiInCase); + return ListUtils.union(apiInCase, apiInScenarioStep); + } + + private List selectApiIdInCase(String projectId, List protocols) { + if (CollectionUtils.isEmpty(protocols)) { + return new ArrayList<>(); + } + return extApiTestCaseMapper.selectApiIdByProjectAndProtocol(projectId, protocols); + } + + private List selectApiIdInScenarioStep(String projectId, List protocols, List ignoreApiIds) { + + List apiInScenarioStep = new ArrayList<>(extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API.name(), protocols)); + List apiCaseIdInStep = extApiScenarioStepMapper.selectResourceId(projectId, ApiScenarioStepType.API_CASE.name(), protocols); + // 如果有场景步骤中的 API 用例 ID,追加相关 API ID + if (CollectionUtils.isNotEmpty(apiCaseIdInStep)) { + List apiCaseIdInScenarioStep = extApiTestCaseMapper.selectApiIdByCaseId(apiCaseIdInStep, protocols, ignoreApiIds); + apiInScenarioStep.addAll(apiCaseIdInScenarioStep); + apiCaseIdInScenarioStep = null; + apiCaseIdInStep = null; + } + + if (protocols.contains("HTTP")) { + List apiDefinitions = extApiDefinitionMapper.selectBaseInfoByProjectId(projectId, List.of("HTTP"), ignoreApiIds); + List httpApiList = apiDefinitions.stream() + .filter(api -> StringUtils.equalsIgnoreCase(api.getProtocol(), "http")) + .toList(); + apiDefinitions = null; + List apiInStepList = new ArrayList<>(CommonBeanFactory.getBean(ApiScenarioService.class).selectApiIdInCustomRequest(projectId, httpApiList)); + apiInScenarioStep.addAll(apiInStepList); + } + + return apiInScenarioStep; + } + public List getDocPage(ApiDefinitionPageRequest request, String userId) { if (CollectionUtils.isEmpty(request.getProtocols())) { return new ArrayList<>(); @@ -907,7 +983,9 @@ public class ApiDefinitionService extends MoveNodeService { public List getBatchApiIds(T dto, String projectId, List protocols, boolean deleted, String userId) { TableBatchProcessDTO request = (TableBatchProcessDTO) dto; if (request.isSelectAll() && CollectionUtils.isNotEmpty(protocols)) { - List ids = extApiDefinitionMapper.getIds(request, projectId, protocols, deleted); + List includeIds = this.getQueryIncludeIds(request.getCondition().getFilter(), projectId, protocols); + List excludeIds = this.getQueryExcludeIds(request.getCondition().getFilter(), projectId, protocols); + List ids = extApiDefinitionMapper.getIds(request, projectId, protocols, deleted, includeIds, excludeIds); if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { ids.removeAll(request.getExcludeIds()); } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java index 2d3fa6b4c8..5ac0b065c5 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java @@ -5,10 +5,7 @@ import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.domain.ApiDefinitionExample; import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiTestCase; -import io.metersphere.api.dto.definition.ApiCoverageDTO; -import io.metersphere.api.dto.definition.ApiDefinitionAddRequest; -import io.metersphere.api.dto.definition.ApiTestCaseAddRequest; -import io.metersphere.api.dto.definition.HttpResponse; +import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.scenario.ApiScenarioAddRequest; import io.metersphere.api.dto.scenario.ApiScenarioStepRequest; @@ -22,16 +19,19 @@ import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.util.CalculateUtils; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.uid.IDGenerator; +import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MvcResult; +import java.nio.charset.StandardCharsets; import java.util.*; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -222,6 +222,31 @@ public class ApiCalculateTest extends BaseTest { } } + /* + 本次接口定义相关数据: + "GET":"/api/get-test/1", + "/api/get-test/2", + "/api/{/get-test}/3/withCase", + "/api/get-test/4/withCase",// 场景关联它的用例 + "/api/get-test/5/never-compare", + "/{api}/{/get-test}/{6}",//这个在接口程度覆盖率和场景程度覆盖率计算中一定会被匹配到 + "/api/get-test/{7}",// 这个在接口程度覆盖率和场景程度覆盖率计算中一定会被匹配到 + "/api/get-test/8",// 场景关联它的自定义请求 + "/api/get-test/9",// 场景关联这个接口 + "/api/get-test/10" + + "POST":"/post/api/test/1", + "/post/api/test/2", + "/post/api/{test}/3/withCase", + "/post/api/test/4/withCase",// 场景关联它的用例 + "/post/api/test/5/never-compare", + "/{post}/{api}/{/get-test}/{6}", //这个在接口程度覆盖率和场景程度覆盖率计算中一定会被匹配到 + "/post/api/test/{7}", // 这个在接口程度覆盖率和场景程度覆盖率计算中一定会被匹配到 + "/post/api/test/8", // 场景关联它的自定义请求 + "/post/api/test/9", // 场景关联这个接口 + "/post/api/test/10" + + */ @Test public void calculateTest() throws Exception { ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample(); @@ -244,6 +269,67 @@ public class ApiCalculateTest extends BaseTest { Assertions.assertEquals(apiCoverageDTO.getApiCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiDefinition(), apiCoverageDTO.getAllApiCount())); Assertions.assertEquals("0.00%", CalculateUtils.reportPercentage(0, 0)); + + // 表格筛选测试 + ApiDefinitionPageRequest request = new ApiDefinitionPageRequest(); + request.setProjectId(project.getId()); + request.setCurrent(1); + request.setPageSize(10); + request.setDeleted(false); + request.setSort(Map.of("createTime", "asc")); + request.setProtocols(List.of("HTTP")); + Map> filters = new HashMap<>(); + request.setSort(Map.of()); + filters.put("coverFrom", List.of(ApiCoverageConstants.API_DEFINITION)); + request.setFilter(filters); + + MvcResult pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + + Pager result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 10); + + filters = new HashMap<>(); + filters.put("unCoverFrom", List.of(ApiCoverageConstants.API_DEFINITION)); + request.setFilter(filters); + pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 10); + + + filters = new HashMap<>(); + filters.put("coverFrom", List.of(ApiCoverageConstants.API_CASE)); + request.setFilter(filters); + pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 4); + + filters = new HashMap<>(); + filters.put("unCoverFrom", List.of(ApiCoverageConstants.API_CASE)); + request.setFilter(filters); + pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 16); + + + filters = new HashMap<>(); + filters.put("coverFrom", List.of(ApiCoverageConstants.API_SCENARIO)); + request.setFilter(filters); + pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 8); + + filters = new HashMap<>(); + filters.put("unCoverFrom", List.of(ApiCoverageConstants.API_SCENARIO)); + request.setFilter(filters); + pageResult = this.requestPostWithOkAndReturn("/api/definition/page", request); + result = JSON.parseObject(JSON.toJSONString(JSON.parseObject( + pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), Pager.class); + Assertions.assertEquals(result.getTotal(), 12); } @Test