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

Fixed tests for links with media types of supported conformance classes #37

Merged
merged 4 commits into from
Aug 20, 2018
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
55 changes: 55 additions & 0 deletions src/main/java/org/opengis/cite/wfs30/CommonDataFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.opengis.cite.wfs30;

import static org.opengis.cite.wfs30.SuiteAttribute.REQUIREMENTCLASSES;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.opengis.cite.wfs30.conformance.RequirementClass;
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;

/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class CommonDataFixture extends CommonFixture {

private List<RequirementClass> requirementClasses;

@BeforeClass
public void requirementClasses( ITestContext testContext ) {
this.requirementClasses = (List<RequirementClass>) testContext.getSuite().getAttribute( REQUIREMENTCLASSES.getName() );
}

protected List<String> createListOfMediaTypesToSupportForOtherResources( Map<String, Object> linkToSelf ) {
if ( this.requirementClasses == null )
throw new SkipException( "No requirement classes described in resource /conformance available" );
List<String> mediaTypesToSupport = new ArrayList<>();
for ( RequirementClass requirementClass : this.requirementClasses )
if ( requirementClass.hasMediaTypeForOtherResources() )
mediaTypesToSupport.add( requirementClass.getMediaTypeOtherResources() );
if ( linkToSelf != null )
mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures() {
if ( this.requirementClasses == null )
throw new SkipException( "No requirement classes described in resource /conformance available" );
List<String> mediaTypesToSupport = new ArrayList<>();
for ( RequirementClass requirementClass : this.requirementClasses )
if ( requirementClass.hasMediaTypeForFeaturesAndCollections() )
mediaTypesToSupport.add( requirementClass.getMediaTypeFeaturesAndCollections() );
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures( Map<String, Object> linkToSelf ) {
List<String> mediaTypesToSupport = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures();
if ( linkToSelf != null )
mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
return mediaTypesToSupport;
}

}
5 changes: 5 additions & 0 deletions src/main/java/org/opengis/cite/wfs30/SuiteAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public enum SuiteAttribute {
*/
API_MODEL( "apiModel", OpenApi3.class ),

/**
* Requirement classes parsed from /conformance; Added during execution.
*/
REQUIREMENTCLASSES( "requirementclasses", List.class ),

/**
* Parsed collections from resource /collections; Added during execution.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.PATH.COLLECTIONS;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPoints;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPointsForCollectionMetadata;
import static org.opengis.cite.wfs30.util.JsonUtils.findLinkByRel;
import static org.opengis.cite.wfs30.util.JsonUtils.findLinksWithSupportedMediaTypeByRel;
import static org.opengis.cite.wfs30.util.JsonUtils.findLinksWithoutRelOrType;
Expand All @@ -19,18 +20,17 @@
import java.util.List;
import java.util.Map;

import org.opengis.cite.wfs30.CommonFixture;
import org.opengis.cite.wfs30.CommonDataFixture;
import org.opengis.cite.wfs30.SuiteAttribute;
import org.opengis.cite.wfs30.openapi3.OpenApiUtils;
import org.opengis.cite.wfs30.openapi3.TestPoint;
import org.opengis.cite.wfs30.openapi3.UriBuilder;
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.reprezen.kaizen.oasparser.model3.MediaType;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;

import io.restassured.path.json.JsonPath;
Expand All @@ -39,14 +39,12 @@
/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class FeatureCollectionsMetadataOperation extends CommonFixture {
public class FeatureCollectionsMetadataOperation extends CommonDataFixture {

private final Map<TestPoint, Response> testPointAndResponses = new HashMap<>();

private final Map<TestPoint, List<Map<String, Object>>> testPointAndCollections = new HashMap<>();

private final List<String> collectionNamesFromLandingPage = new ArrayList<>();

private OpenApi3 apiModel;

private Object[][] testPointsData;
Expand Down Expand Up @@ -75,19 +73,6 @@ public Object[][] collections( ITestContext testContext ) {
return objects;
}

@BeforeClass
public void parseRequiredMetadata( ITestContext testContext ) {
Response request = init().baseUri( rootUri.toString() ).accept( JSON ).when().request( GET, "/" );
JsonPath jsonPath = request.jsonPath();

List<Object> collections = jsonPath.getList( "collections" );
for ( Object collectionObject : collections ) {
Map<String, Object> collection = (Map<String, Object>) collectionObject;
String collectionName = (String) collection.get( "name" );
this.collectionNamesFromLandingPage.add( collectionName );
}
}

@BeforeClass
public void openApiDocument( ITestContext testContext ) {
this.apiModel = (OpenApi3) testContext.getSuite().getAttribute( API_MODEL.getName() );
Expand Down Expand Up @@ -122,7 +107,7 @@ public void storeCollectionsInTestContext( ITestContext testContext ) {
*/
@Test(description = "Implements A.4.4.4. Validate the Feature Collections Metadata Operation (Requirement 9, 10)", groups = "collections", dataProvider = "collectionsUris", dependsOnGroups = "apidefinition")
public void validateFeatureCollectionsMetadataOperation( TestPoint testPoint ) {
String testPointUri = testPoint.createUri();
String testPointUri = new UriBuilder( testPoint ).buildUrl();
Response response = init().baseUri( testPointUri ).accept( JSON ).when().request( GET );
response.then().statusCode( 200 );
this.testPointAndResponses.put( testPoint, response );
Expand Down Expand Up @@ -163,7 +148,7 @@ public void validateFeatureCollectionsMetadataOperationResponse_Links( TestPoint

// Validate that the retrieved document includes links for: Itself, Alternate encodings of this document in
// every other media type as identified by the compliance classes for this server.
List<String> mediaTypesToSupport = createListOfMediaTypesToSupport( testPoint, linkToSelf );
List<String> mediaTypesToSupport = createListOfMediaTypesToSupportForOtherResources( linkToSelf );
List<Map<String, Object>> alternateLinks = findLinksWithSupportedMediaTypeByRel( links, mediaTypesToSupport,
"alternate" );
List<String> typesWithoutLink = findUnsupportedTypes( alternateLinks, mediaTypesToSupport );
Expand Down Expand Up @@ -201,10 +186,8 @@ public void validateFeatureCollectionsMetadataOperationResponse_Collections( Tes
JsonPath jsonPath = response.jsonPath();
List<Object> collections = jsonPath.getList( "collections" );

List<String> missingCollectionNames = findMissingCollectionNames( collections );
assertTrue( missingCollectionNames.isEmpty(),
"Feature Collection Metadata document must include a collections property for each collection in the dataset. Missing collection properties "
+ missingCollectionNames );
// Test method cannot be verified as the provided collections are not known.

this.testPointAndCollections.put( testPoint, createCollectionsMap( collections ) );
}

Expand Down Expand Up @@ -234,25 +217,21 @@ public void validateFeatureCollectionsMetadataOperationResponse_Collections( Tes
@Test(description = "Implements A.4.4.6. Validate a Collections Metadata document (Requirement 13)", groups = "collections", dataProvider = "collections", dependsOnMethods = "validateFeatureCollectionsMetadataOperationResponse_Collections")
public void validateCollectionsMetadataDocument_Links( TestPoint testPoint, Map<String, Object> collection ) {
String collectionName = (String) collection.get( "name" );
List<TestPoint> testPointsForNamedCollection = OpenApiUtils.retrieveTestPoints( apiModel, COLLECTIONS,
collectionName );
if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );

List<String> mediaTypesToSupport = createListOfMediaTypesToSupport( testPointsForNamedCollection.get( 0 ), null );
List<String> mediaTypesToSupport = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures();
List<Map<String, Object>> links = (List<Map<String, Object>>) collection.get( "links" );

List<Map<String, Object>> alternateLinks = findLinksWithSupportedMediaTypeByRel( links, mediaTypesToSupport,
"item" );
List<String> typesWithoutLink = findUnsupportedTypes( alternateLinks, mediaTypesToSupport );
List<Map<String, Object>> items = findLinksWithSupportedMediaTypeByRel( links, mediaTypesToSupport, "item" );
List<String> typesWithoutLink = findUnsupportedTypes( items, mediaTypesToSupport );
assertTrue( typesWithoutLink.isEmpty(),
"Collections Metadata document must include links with relation 'item' for each supported encodings. Missing links for types "
+ typesWithoutLink );
List<String> linksWithoutRelOrType = findLinksWithoutRelOrType( alternateLinks );
"Collections Metadata document for collection with name "
+ collectionName
+ " must include links with relation 'item' for each supported encodings. Missing links for types "
+ String.join( ", ", typesWithoutLink ) );
List<String> linksWithoutRelOrType = findLinksWithoutRelOrType( items );
assertTrue( linksWithoutRelOrType.isEmpty(),
"Links with relation 'item' for encodings must include a rel and type parameter. Missing for links "
+ linksWithoutRelOrType );
+ String.join( ", ", linksWithoutRelOrType ) );
}

/**
Expand Down Expand Up @@ -291,13 +270,15 @@ public void validateCollectionsMetadataDocument_Extent( TestPoint testPoint, Map
public void validateTheFeatureCollectionMetadataOperationAndResponse( TestPoint testPoint,
Map<String, Object> collection ) {
String collectionName = (String) collection.get( "name" );
List<TestPoint> testPointsForNamedCollection = OpenApiUtils.retrieveTestPoints( apiModel, COLLECTIONS,
collectionName );
List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForCollectionMetadata( apiModel,
collectionName );
if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );

Response response = validateTheFeatureCollectionMetadataOperationAndResponse( testPointsForNamedCollection.get( 0 ) );
TestPoint testPointCollectionMetadata = testPointsForNamedCollection.get( 0 );
Response response = validateTheFeatureCollectionMetadataOperationAndResponse( testPointCollectionMetadata,
collectionName );
validateFeatureCollectionMetadataOperationResponse( response, collection );
}

Expand All @@ -321,12 +302,14 @@ public void validateTheFeatureCollectionMetadataOperationAndResponse( TestPoint
* Go to test A.4.4.8
*
* d) References: Requirement 15
*
*
* @param testPoint
* to test, never <code>null</code>
* @param collectionName
*/
private Response validateTheFeatureCollectionMetadataOperationAndResponse( TestPoint testPoint ) {
String testPointUri = testPoint.createUri();
private Response validateTheFeatureCollectionMetadataOperationAndResponse( TestPoint testPoint,
String collectionName ) {
String testPointUri = new UriBuilder( testPoint ).collectionName( collectionName ).buildUrl();
Response response = init().baseUri( testPointUri ).accept( JSON ).when().request( GET );
response.then().statusCode( 200 );
return response;
Expand Down Expand Up @@ -356,40 +339,11 @@ private void validateFeatureCollectionMetadataOperationResponse( Response respon
assertEquals( collection, jsonPath.get() );
}

private List<String> findMissingCollectionNames( List<Object> collections ) {
List<String> missingCollectionNames = new ArrayList<>();
for ( String collectionNameFromLandingPage : this.collectionNamesFromLandingPage ) {
Map<String, Object> collection = findCollectionByName( collectionNameFromLandingPage, collections );
if ( collection == null )
missingCollectionNames.add( collectionNameFromLandingPage );
}
return missingCollectionNames;
}

private Map<String, Object> findCollectionByName( String collectionNameFromLandingPage, List<Object> collections ) {
for ( Object collectionObject : collections ) {
Map<String, Object> collection = (Map<String, Object>) collectionObject;
Object collectionName = collection.get( "name" );
if ( collectionNameFromLandingPage.equals( collectionName ) )
return collection;
}
return null;
}

private List<Map<String, Object>> createCollectionsMap( List<Object> collections ) {
List<Map<String, Object>> collectionsMap = new ArrayList<>();
for ( Object collection : collections )
collectionsMap.add( (Map<String, Object>) collection );
return collectionsMap;
}

private List<String> createListOfMediaTypesToSupport( TestPoint testPoint, Map<String, Object> linkToSelf ) {
Map<String, MediaType> contentMediaTypes = testPoint.getContentMediaTypes();
List<String> mediaTypesToSupport = new ArrayList<>();
mediaTypesToSupport.addAll( contentMediaTypes.keySet() );
if ( linkToSelf != null )
mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
return mediaTypesToSupport;
}

}
Loading