From 04acb0a5c33e6345f9bc1be74ea1ee3457651d85 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Wed, 20 Nov 2024 18:06:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=A6=86=E7=9B=96=E7=8E=87=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E7=AE=97=E6=B3=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/utils/ApiDefinitionUtils.java | 21 +++++++++++++-- .../api/controller/ApiCalculateTest.java | 27 ++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) 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)); + } }