From f7a4f503811e4e62d1451f984952ad704f2e1b64 Mon Sep 17 00:00:00 2001 From: Gobe Hobona Date: Tue, 6 Feb 2024 17:54:10 +0000 Subject: [PATCH 1/2] updates --- .../apidefinition/ApiDefinition.java | 38 ++++++++++ .../cite/ogcapitiles10/conformance/Tile.java | 2 +- .../ogcapitiles10/core/MandatoryCore.java | 69 ++++++++++++++++++- 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java b/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java index f20e158..7ead2da 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java @@ -2,6 +2,7 @@ import com.reprezen.kaizen.oasparser.OpenApi3Parser; import com.reprezen.kaizen.oasparser.model3.OpenApi3; +import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.val.ValidationResults; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; @@ -78,12 +79,49 @@ public void apiDefinitionValidation(ITestContext testContext) throws MalformedUR } OpenApi3 apiModel = parser.parse(response, new URL(apiUrl), true); + + assertTrue(apiModel.isValid(), createValidationMsg(apiModel)); testContext.getSuite().setAttribute(API_MODEL.getName(), apiModel); } + /** + * Implements Abstract test A.24: /conf/oas30/operation-id Partly addresses + * Requirement 23: /req/oas30/operation-id + * @param testContext never null + * @throws MalformedURLException if the apiUrl is malformed + */ + @Test(description = "Implements Abstract test A.24, Requirement 23: /req/oas30/operation-id", + groups = "apidefinition") + public void apiDefinitionOperationIdValidation(ITestContext testContext) throws MalformedURLException { + + OpenApi3Parser parser = new OpenApi3Parser(); + + if (apiUrl == null || apiUrl.isEmpty()) { + throw new SkipException(missing_api_definition_error_message); + } + + OpenApi3 apiModel = parser.parse(response, new URL(apiUrl), true); + + Map map = apiModel.getPaths(); + + boolean hasGetTileOperationId = false; + + for (Map.Entry entry : map.entrySet()) { + System.out.println("ACHK " + entry.getKey() + "/" + entry.getValue().getGet().getOperationId()); + if(entry.getValue().getGet().getOperationId().contains(".getTile")) { + hasGetTileOperationId = true; + System.out.println("BCHK " + "*******" + entry.getValue().getGet().getOperationId()); + } + } + + assertTrue(hasGetTileOperationId, "None of the operationIDs matched those specified by Requirement /req/oas30/operation-id and Table 11"); + + + } + private String parseApiUrl(JsonPath jsonPath) { for (Object link : parseAsListOfMaps("links", jsonPath)) { Map linkMap = (Map) link; diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Tile.java b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Tile.java index c15d6b2..3c9d13e 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Tile.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/conformance/Tile.java @@ -114,7 +114,7 @@ public void validateTilesAreAvailable() throws Exception { * */ @Test(description = "Implements Abstract test A.6, Requirement 5: /req/core/tc-success") - public void validateSuccessfulTilesExecution() throws Exception { + public void validateSuccessfulTilesExecutionFollowingLinks() throws Exception { if (rootUri == null) { throw new SkipException(missing_landing_page_error_message); diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/core/MandatoryCore.java b/src/main/java/org/opengis/cite/ogcapitiles10/core/MandatoryCore.java index f9c9a39..98568c2 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/core/MandatoryCore.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/core/MandatoryCore.java @@ -66,11 +66,11 @@ public class MandatoryCore extends CommonFixture { /** *
-	 * Implements Abstract test A.6
-	 * Addresses Requirement 5: /req/core/tc-success
+	 * Implements Abstract test A.2
+	 * Addresses Requirement 1: /req/core/tc-op
 	 * 
*/ - @Test(description = "Implements Abstract test A.6, Requirement 5: /req/core/tc-success") + @Test(description = "Implements Abstract test A.2, Requirement 1: /req/core/tc-op") public void verifyMinimalConformance(ITestContext testContext) throws Exception { Map params = testContext.getSuite().getXmlSuite().getParameters(); @@ -130,6 +130,69 @@ public void verifyMinimalConformance(ITestContext testContext) throws Exception Assert.assertTrue(tileMatrixSetDefinitionInUrlTemplate, "Neither the user-provided tile matrix set definition nor its variable ({tileMatrixSetId}) was found in the url template"); + } + + /** + *
+	 * Implements Abstract test A.6
+	 * Addresses Requirement 5: /req/core/tc-success
+	 * 
+ */ + @Test(description = "Implements Abstract test A.6, Requirement 5: /req/core/tc-success") + public void validateSuccessfulTilesExecution(ITestContext testContext) throws Exception { + + Map params = testContext.getSuite().getXmlSuite().getParameters(); + + checkInputs(params); + + String urlTemplate = testContext.getSuite().getAttribute(URL_TEMPLATE_FOR_TILES.getName()).toString(); + String tileMatrixSetDefinitionURI = testContext.getSuite() + .getAttribute(TILE_MATRIX_SET_DEFINITION_URI.getName()).toString(); + + String tileMatrixString = testContext.getSuite().getAttribute(TILE_MATRIX.getName()).toString(); + String minTileRowString = testContext.getSuite().getAttribute(MINIMUM_TILE_ROW.getName()).toString(); + String maxTileRowString = testContext.getSuite().getAttribute(MAXIMUM_TILE_ROW.getName()).toString(); + String minTileColString = testContext.getSuite().getAttribute(MINIMUM_TILE_COLUMN.getName()).toString(); + String maxTileColString = testContext.getSuite().getAttribute(MAXIMUM_TILE_COLUMN.getName()).toString(); + + int tileMatrix = Integer.parseInt(tileMatrixString); + int minTileRow = Integer.parseInt(minTileRowString); + int maxTileRow = Integer.parseInt(maxTileRowString); + int minTileCol = Integer.parseInt(minTileColString); + int maxTileCol = Integer.parseInt(maxTileColString); + + FileReader fis = null; + boolean foundRegisteredTileMatrixSetDefinition = false; + boolean tileMatrixSetDefinitionInUrlTemplate = false; + try { + + List> records = new ArrayList<>(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(this.getClass() + .getResourceAsStream("/org/opengis/cite/ogcapitiles10/tilematrixsetdefinitions.csv")))) { + String line; + while ((line = br.readLine()) != null) { + String[] values = line.split(","); + records.add(Arrays.asList(values)); + } + } + + for (int i = 0; i < records.size(); i++) { + + if (tileMatrixSetDefinitionURI.toLowerCase().equals(records.get(i).get(1).toLowerCase())) { + foundRegisteredTileMatrixSetDefinition = true; + + tileMatrixSetDefinitionInUrlTemplate = urlTemplate.contains("/tiles/" + records.get(i).get(0)) + || urlTemplate.contains("/tiles/{tileMatrixSetId}"); + + } + } + + } + catch (Exception ex) { + + ex.printStackTrace(); + } + TileResponseMetadata tileResponseMetadata = new TileResponseMetadata(false, -1); try { From c9ea102f0412a940ae0739bdc728fdb62517b4f9 Mon Sep 17 00:00:00 2001 From: Gobe Hobona Date: Tue, 6 Feb 2024 18:53:44 +0000 Subject: [PATCH 2/2] Update ApiDefinition.java --- .../apidefinition/ApiDefinition.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java b/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java index 7ead2da..8a57348 100644 --- a/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java +++ b/src/main/java/org/opengis/cite/ogcapitiles10/apidefinition/ApiDefinition.java @@ -80,7 +80,6 @@ public void apiDefinitionValidation(ITestContext testContext) throws MalformedUR OpenApi3 apiModel = parser.parse(response, new URL(apiUrl), true); - assertTrue(apiModel.isValid(), createValidationMsg(apiModel)); testContext.getSuite().setAttribute(API_MODEL.getName(), apiModel); @@ -110,15 +109,23 @@ public void apiDefinitionOperationIdValidation(ITestContext testContext) throws boolean hasGetTileOperationId = false; for (Map.Entry entry : map.entrySet()) { - System.out.println("ACHK " + entry.getKey() + "/" + entry.getValue().getGet().getOperationId()); - if(entry.getValue().getGet().getOperationId().contains(".getTile")) { - hasGetTileOperationId = true; - System.out.println("BCHK " + "*******" + entry.getValue().getGet().getOperationId()); + if(entry.getValue().hasOperations()) { + if(entry.getValue().getGet()!=null) { + String operationId = ""+entry.getValue().getGet().getOperationId(); + if (!operationId.trim().equals("null")) { + if (operationId.contains(".getTile")) { + hasGetTileOperationId = true; + } + } + } + + } + } - assertTrue(hasGetTileOperationId, "None of the operationIDs matched those specified by Requirement /req/oas30/operation-id and Table 11"); - + assertTrue(hasGetTileOperationId, + "None of the operationIDs matched those specified by Requirement /req/oas30/operation-id and Table 11"); }