Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to support more optional conformance classes #26

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,12 +79,56 @@ 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 <code>null</code>
* @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<String, Path> map = apiModel.getPaths();

boolean hasGetTileOperationId = false;

for (Map.Entry<String, Path> entry : map.entrySet()) {
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");

}

private String parseApiUrl(JsonPath jsonPath) {
for (Object link : parseAsListOfMaps("links", jsonPath)) {
Map<String, Object> linkMap = (Map<String, Object>) link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void validateTilesAreAvailable() throws Exception {
* </pre>
*/
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public class MandatoryCore extends CommonFixture {

/**
* <pre>
* Implements Abstract test A.6
* Addresses Requirement 5: /req/core/tc-success
* Implements Abstract test A.2
* Addresses Requirement 1: /req/core/tc-op
* </pre>
*/
@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<String, String> params = testContext.getSuite().getXmlSuite().getParameters();
Expand Down Expand Up @@ -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");

}

/**
* <pre>
* Implements Abstract test A.6
* Addresses Requirement 5: /req/core/tc-success
* </pre>
*/
@Test(description = "Implements Abstract test A.6, Requirement 5: /req/core/tc-success")
public void validateSuccessfulTilesExecution(ITestContext testContext) throws Exception {

Map<String, String> 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<List<String>> 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 {
Expand Down