From 33724aa80efe399352d50babbd0630d0bbcc29b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Thu, 15 Aug 2024 07:52:32 +0200 Subject: [PATCH] Improve check for implemented conformance classes --- .../cite/ogcapitiles10/CommonFixture.java | 12 ++++++++++ .../conformance/Conformance.java | 6 +++-- .../conformance/RequirementClass.java | 9 +++++++- .../datasettilesets/LandingPage.java | 14 ++++++++++-- .../GeospatialDataResource.java | 22 +++++++++++++++++-- .../tilesetslist/TilesetLlinks.java | 20 ++++++++++++++--- 6 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/CommonFixture.java b/src/main/java/org/opengis/cite/ogcapitiles10/CommonFixture.java index 836da81..4ce04a5 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/CommonFixture.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/CommonFixture.java @@ -6,6 +6,7 @@ import java.io.PrintStream; import java.net.URI; +import org.opengis.cite.ogcapitiles10.conformance.RequirementClass; import org.opengis.cite.ogcapitiles10.util.ClientUtils; import org.testng.ITestContext; import org.testng.annotations.BeforeClass; @@ -25,6 +26,8 @@ public class CommonFixture { private ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream(); + private final String conformance_class_not_implemented = "Skipped because Conformance Class %s is not implemented."; + protected RequestLoggingFilter requestLoggingFilter; protected ResponseLoggingFilter responseLoggingFilter; @@ -35,6 +38,15 @@ public class CommonFixture { protected final String missing_api_definition_error_message = "Skipped because the API definition could not be retrieved"; + protected final String dataset_tilesets_conformance_class_not_implemented = String + .format(conformance_class_not_implemented, RequirementClass.DATASET_TILES.getConformanceClass()); + + protected final String geodata_tilesets_conformance_class_not_implemented = String + .format(conformance_class_not_implemented, RequirementClass.GEODATA_TILESETS.getConformanceClass()); + + protected final String tilesets_lists_conformance_class_not_implemented = String + .format(conformance_class_not_implemented, RequirementClass.TILESETS_LIST.getConformanceClass()); + /** * Initializes the common test fixture with a client component for interacting with * HTTP endpoints. diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Conformance.java b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Conformance.java index 7c4b7d1..e5f3b29 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Conformance.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Conformance.java @@ -52,8 +52,10 @@ public Object[][] conformanceUris(ITestContext testContext) { OpenApi3 apiModel = (OpenApi3) testContext.getSuite().getAttribute(API_MODEL.getName()); URI iut = (URI) testContext.getSuite().getAttribute(IUT.getName()); - - TestPoint tp = new TestPoint(rootUri.toString(), "/conformance", null); + String rootUriString = rootUri.toString(); + rootUriString = rootUriString.endsWith("/") ? rootUriString.substring(0, rootUriString.length() - 1) + : rootUriString; + TestPoint tp = new TestPoint(rootUriString, "/conformance", null); List testPoints = new ArrayList(); testPoints.add(tp); diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/RequirementClass.java b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/RequirementClass.java index 311e131..8ad77de 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/RequirementClass.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/RequirementClass.java @@ -9,7 +9,10 @@ */ public enum RequirementClass { - CORE("http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/core"); + CORE("http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/core"), DATASET_TILES( + "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/dataset-tilesets"), GEODATA_TILESETS( + "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/geodata-tilesets"), TILESETS_LIST( + "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/tilesets-list"); private final String conformanceClass; @@ -70,4 +73,8 @@ public static RequirementClass byConformanceClass(String conformanceClass) { return null; } + public String getConformanceClass() { + return this.conformanceClass; + } + } diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/datasettilesets/LandingPage.java b/src/main/java/org/opengis/cite/ogcapitiles10/datasettilesets/LandingPage.java index 24771a2..e10e07d 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/datasettilesets/LandingPage.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/datasettilesets/LandingPage.java @@ -3,6 +3,7 @@ import static io.restassured.http.ContentType.JSON; import static io.restassured.http.Method.GET; import static org.opengis.cite.ogcapitiles10.EtsAssert.assertTrue; +import static org.opengis.cite.ogcapitiles10.SuiteAttribute.REQUIREMENTCLASSES; import java.util.HashSet; import java.util.List; @@ -10,6 +11,8 @@ import java.util.Set; import org.opengis.cite.ogcapitiles10.CommonFixture; +import org.opengis.cite.ogcapitiles10.conformance.RequirementClass; +import org.testng.ITestContext; import org.testng.SkipException; import org.testng.annotations.Test; @@ -34,8 +37,15 @@ public class LandingPage extends CommonFixture { * */ @Test(description = "Implements Abstract test A.10, addresses Requirement 11", groups = "landingpage") - public void landingPageRetrieval() { - + public void landingPageRetrieval(ITestContext testContext) { + + Object requirementsClassesObject = testContext.getSuite().getAttribute(REQUIREMENTCLASSES.getName()); + if (requirementsClassesObject instanceof List) { + List requirementsClassesList = (List) requirementsClassesObject; + if (!requirementsClassesList.contains(RequirementClass.DATASET_TILES)) { + throw new SkipException(dataset_tilesets_conformance_class_not_implemented); + } + } if (rootUri == null) { throw new SkipException(missing_landing_page_error_message); } diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/geodatatilesets/GeospatialDataResource.java b/src/main/java/org/opengis/cite/ogcapitiles10/geodatatilesets/GeospatialDataResource.java index de03cf8..aef4a85 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/geodatatilesets/GeospatialDataResource.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/geodatatilesets/GeospatialDataResource.java @@ -3,6 +3,7 @@ import static io.restassured.http.ContentType.JSON; import static io.restassured.http.Method.GET; import static org.opengis.cite.ogcapitiles10.EtsAssert.assertTrue; +import static org.opengis.cite.ogcapitiles10.SuiteAttribute.REQUIREMENTCLASSES; import java.util.ArrayList; import java.util.HashMap; @@ -12,7 +13,9 @@ import java.util.Set; import org.opengis.cite.ogcapitiles10.CommonFixture; +import org.opengis.cite.ogcapitiles10.conformance.RequirementClass; import org.testng.Assert; +import org.testng.ITestContext; import org.testng.SkipException; import org.testng.annotations.Test; @@ -37,12 +40,20 @@ public class GeospatialDataResource extends CommonFixture { * */ @Test(description = "Implements Abstract test A.12, addresses Requirement 13", groups = "geodata") - public void geospatialResourceTilesetsLinksCheck() { + public void geospatialResourceTilesetsLinksCheck(ITestContext testContext) { if (rootUri == null) { throw new SkipException(missing_landing_page_error_message); } + Object requirementsClassesObject = testContext.getSuite().getAttribute(REQUIREMENTCLASSES.getName()); + if (requirementsClassesObject instanceof List) { + List requirementsClassesList = (List) requirementsClassesObject; + if (!requirementsClassesList.contains(RequirementClass.GEODATA_TILESETS)) { + throw new SkipException(geodata_tilesets_conformance_class_not_implemented); + } + } + Response request = init().baseUri(rootUri.toString()).accept(JSON).when().request(GET, "/collections"); request.then().statusCode(200); response = request.jsonPath(); @@ -64,8 +75,15 @@ public void geospatialResourceTilesetsLinksCheck() { * */ @Test(description = "Implements Abstract test A.13, addresses Requirement 14", groups = "geodata") - public void geospatialResourceTilesetsRetrieval() { + public void geospatialResourceTilesetsRetrieval(ITestContext testContext) { + Object requirementsClassesObject = testContext.getSuite().getAttribute(REQUIREMENTCLASSES.getName()); + if (requirementsClassesObject instanceof List) { + List requirementsClassesList = (List) requirementsClassesObject; + if (!requirementsClassesList.contains(RequirementClass.GEODATA_TILESETS)) { + throw new SkipException(geodata_tilesets_conformance_class_not_implemented); + } + } if (rootUri == null) { throw new SkipException(missing_landing_page_error_message); } diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/tilesetslist/TilesetLlinks.java b/src/main/java/org/opengis/cite/ogcapitiles10/tilesetslist/TilesetLlinks.java index ef8c809..b2d0b33 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/tilesetslist/TilesetLlinks.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/tilesetslist/TilesetLlinks.java @@ -4,6 +4,7 @@ import static io.restassured.http.Method.GET; import static org.opengis.cite.ogcapitiles10.SuiteAttribute.API_MODEL; import static org.opengis.cite.ogcapitiles10.SuiteAttribute.IUT; +import static org.opengis.cite.ogcapitiles10.SuiteAttribute.REQUIREMENTCLASSES; import static org.testng.Assert.assertTrue; import java.net.URI; @@ -13,6 +14,7 @@ import java.util.Map; import org.opengis.cite.ogcapitiles10.CommonFixture; +import org.opengis.cite.ogcapitiles10.conformance.RequirementClass; import org.opengis.cite.ogcapitiles10.openapi3.TestPoint; import org.testng.ITestContext; import org.testng.SkipException; @@ -51,18 +53,30 @@ public Object[][] tilesetUris(ITestContext testContext) { */ @Test(description = "Implements Abstract test A.9, addresses Requirement 10 (/req/tilesets-list/tileset-links)", groups = "tilesetsLists", dataProvider = "tilesetListsURIs") - public void validateTilesetsListResponse(TestPoint testPoint) { + public void validateTilesetsListResponse(ITestContext testContext, TestPoint testPoint) { if (rootUri == null) { throw new SkipException(missing_landing_page_error_message); } - + Object requirementsClassesObject = testContext.getSuite().getAttribute(REQUIREMENTCLASSES.getName()); + boolean implementsGeoDataTilesets = false; + if (requirementsClassesObject instanceof List) { + List requirementsClassesList = (List) requirementsClassesObject; + if (!requirementsClassesList.contains(RequirementClass.TILESETS_LIST)) { + throw new SkipException(tilesets_lists_conformance_class_not_implemented); + } + if (requirementsClassesList.contains(RequirementClass.GEODATA_TILESETS)) { + implementsGeoDataTilesets = true; + } + } StringBuffer errorMessagesRoot = new StringBuffer(); StringBuffer errorMessagesCollection = new StringBuffer(); errorMessagesRoot.append(tilesetsListResponseFromRoot()); - errorMessagesCollection.append(tilesetsListResponseFromCollections()); + if (implementsGeoDataTilesets) { + errorMessagesCollection.append(tilesetsListResponseFromCollections()); + } assertTrue(errorMessagesRoot.toString().length() == 0 && errorMessagesCollection.toString().length() == 0, errorMessagesRoot.toString() + " \n" + errorMessagesCollection.toString());