diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiDefinitionUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiDefinitionUtils.java index 73089d6455..6c295269f0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiDefinitionUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiDefinitionUtils.java @@ -31,8 +31,8 @@ public class ApiDefinitionUtils { if (StringUtils.isNotEmpty(customRequestUrl)) { String[] customUrlArr = customRequestUrl.split("/"); - if (customUrlArr.length >= urlParams.length) { - + if (StringUtils.startsWithAny(customRequestUrl.toLowerCase(), "https://", "http://") + && customUrlArr.length >= urlParams.length) { boolean isFetch = true; for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) { String urlItem = urlParams[urlIndex]; @@ -48,6 +48,23 @@ public class ApiDefinitionUtils { if (isFetch) { return true; } + } else if (customUrlArr.length == urlParams.length) { + boolean isFetch = true; + for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) { + String urlItem = urlParams[urlIndex]; + String customUrlItem = customUrlArr[urlIndex]; + // 不为rest参数的要进行全匹配。 而且忽略大小写 + if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) { + if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) { + isFetch = false; + break; + } + } + } + if (isFetch) { + return true; + } + } } } 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 080d24c9a9..046feddcee 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 @@ -15,6 +15,7 @@ import io.metersphere.api.dto.scenario.ApiScenarioStepRequest; import io.metersphere.api.dto.scenario.ApiScenarioUpdateRequest; import io.metersphere.api.mapper.ApiDefinitionMapper; import io.metersphere.api.utils.ApiDataUtils; +import io.metersphere.api.utils.ApiDefinitionUtils; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.mapper.ProjectMapper; @@ -220,20 +221,32 @@ public class ApiCalculateTest extends BaseTest { MvcResult mvcResult = this.requestGetWithOkAndReturn("/api/definition/rage/" + project.getId()); ApiCoverageDTO apiCoverageDTO = getResultData(mvcResult, ApiCoverageDTO.class); - Assertions.assertEquals(apiCoverageDTO.getAllApiCount(), 20); - Assertions.assertEquals(apiCoverageDTO.getCoverWithApiCase(), 4); - Assertions.assertEquals(apiCoverageDTO.getUnCoverWithApiCase(), 16); + Assertions.assertEquals(20, apiCoverageDTO.getAllApiCount()); + Assertions.assertEquals(4, apiCoverageDTO.getCoverWithApiCase()); + Assertions.assertEquals(16, apiCoverageDTO.getUnCoverWithApiCase()); Assertions.assertEquals(apiCoverageDTO.getApiCaseCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiCase(), apiCoverageDTO.getAllApiCount())); - Assertions.assertEquals(apiCoverageDTO.getCoverWithApiScenario(), 8); - Assertions.assertEquals(apiCoverageDTO.getUnCoverWithApiScenario(), 12); + Assertions.assertEquals(8, apiCoverageDTO.getCoverWithApiScenario()); + Assertions.assertEquals(12, apiCoverageDTO.getUnCoverWithApiScenario()); Assertions.assertEquals(apiCoverageDTO.getScenarioCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiScenario(), apiCoverageDTO.getAllApiCount())); - Assertions.assertEquals(apiCoverageDTO.getCoverWithApiDefinition(), 10); - Assertions.assertEquals(apiCoverageDTO.getUnCoverWithApiDefinition(), 10); + Assertions.assertEquals(10, apiCoverageDTO.getCoverWithApiDefinition()); + Assertions.assertEquals(10, apiCoverageDTO.getUnCoverWithApiDefinition()); Assertions.assertEquals(apiCoverageDTO.getApiCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiDefinition(), apiCoverageDTO.getAllApiCount())); Assertions.assertEquals("0.00%", CalculateUtils.reportPercentage(0, 0)); } + @Test + public void urlFetchTest() { + List fetchList = new ArrayList<>(); + fetchList.add("/etag/{etag}"); + fetchList.add("/html"); + Assertions.assertFalse(ApiDefinitionUtils.isUrlInList("/brave", fetchList)); + fetchList.add("https://www.abcde.com/etag/{etag}"); + Assertions.assertTrue(ApiDefinitionUtils.isUrlInList("/brave", fetchList)); + fetchList.remove("https://www.abcde.com/etag/{etag}"); + fetchList.add("http://www.abcde.com/etag/{etag}"); + Assertions.assertTrue(ApiDefinitionUtils.isUrlInList("/brave", fetchList)); + } }