Skip to content

Commit

Permalink
Merge pull request #37 from opengeospatial/fixValidateCollectionsMeta…
Browse files Browse the repository at this point in the history
…dataDocument_Links-36

Fixed tests for links with media types of supported conformance classes
  • Loading branch information
dstenger authored Aug 20, 2018
2 parents 3c77ac5 + 124d3ad commit 7f3b98c
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 109 deletions.
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 @@ -20,7 +20,7 @@
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.TestPoint;
import org.opengis.cite.wfs30.openapi3.UriBuilder;
Expand All @@ -31,7 +31,6 @@
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 @@ -40,7 +39,7 @@
/**
* @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<>();

Expand Down Expand Up @@ -149,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 @@ -218,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 = retrieveTestPointsForCollectionMetadata( apiModel,
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 @@ -351,13 +346,4 @@ private List<Map<String, Object>> createCollectionsMap( List<Object> collections
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static io.restassured.http.Method.GET;
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.GEOJSON_MIME_TYPE;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPointsForFeature;
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 @@ -18,16 +17,14 @@
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.TestPoint;
import org.testng.ITestContext;
import org.testng.SkipException;
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 @@ -36,7 +33,7 @@
/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class GetFeatureOperation extends CommonFixture {
public class GetFeatureOperation extends CommonDataFixture {

private OpenApi3 apiModel;

Expand Down Expand Up @@ -151,14 +148,6 @@ public void validateTheGetFeatureOperationResponse( Map<String, Object> collecti
if ( response == null )
throw new SkipException( "Could not find a response for collection with name " + collectionName );

List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForFeature( apiModel, collectionName,
featureId );

if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );
TestPoint testPoint = testPointsForNamedCollection.get( 0 );

JsonPath jsonPath = response.jsonPath();

List<Map<String, Object>> links = jsonPath.getList( "links" );
Expand All @@ -179,7 +168,7 @@ public void validateTheGetFeatureOperationResponse( Map<String, Object> collecti
// Validate that the retrieved document includes links for:
// 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 = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures( linkToSelf );
List<Map<String, Object>> alternateLinks = findLinksWithSupportedMediaTypeByRel( links, mediaTypesToSupport,
"alternate" );
List<String> typesWithoutLink = findUnsupportedTypes( alternateLinks, mediaTypesToSupport );
Expand All @@ -194,15 +183,6 @@ public void validateTheGetFeatureOperationResponse( Map<String, Object> collecti
+ linksWithoutRelOrType );
}

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;
}

private String findGetFeatureUrlForGeoJson( Map<String, Object> collection ) {
List<Object> links = (List<Object>) collection.get( "links" );
for ( Object linkObject : links ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.GEOJSON_MIME_TYPE;
import static org.opengis.cite.wfs30.WFS3.PATH.COLLECTIONS;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPointsForCollection;
import static org.opengis.cite.wfs30.util.JsonUtils.collectNumberOfAllReturnedFeatures;
import static org.opengis.cite.wfs30.util.JsonUtils.findLinkByRel;
import static org.opengis.cite.wfs30.util.JsonUtils.findLinksWithSupportedMediaTypeByRel;
Expand Down Expand Up @@ -34,9 +33,8 @@
import java.util.Map;
import java.util.Random;

import org.opengis.cite.wfs30.CommonFixture;
import org.opengis.cite.wfs30.CommonDataFixture;
import org.opengis.cite.wfs30.SuiteAttribute;
import org.opengis.cite.wfs30.openapi3.TestPoint;
import org.opengis.cite.wfs30.util.BBox;
import org.opengis.cite.wfs30.util.TemporalExtent;
import org.testng.ITestContext;
Expand All @@ -45,7 +43,6 @@
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 com.reprezen.kaizen.oasparser.model3.Operation;
import com.reprezen.kaizen.oasparser.model3.Parameter;
Expand All @@ -58,7 +55,7 @@
/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class GetFeaturesOperation extends CommonFixture {
public class GetFeaturesOperation extends CommonDataFixture {

private final Map<String, ResponseData> collectionNameAndResponse = new HashMap<>();

Expand Down Expand Up @@ -217,12 +214,6 @@ public void validateTheGetFeaturesOperationResponse_Links( Map<String, Object> c
if ( response == null )
throw new SkipException( "Could not find a response for collection with name " + collectionName );

List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForCollection( apiModel, collectionName );
if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );
TestPoint testPoint = testPointsForNamedCollection.get( 0 );

JsonPath jsonPath = response.jsonPath();

List<Map<String, Object>> links = jsonPath.getList( "links" );
Expand All @@ -233,7 +224,7 @@ public void validateTheGetFeaturesOperationResponse_Links( Map<String, Object> c

// Validate that the retrieved document includes links for: 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 = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures( linkToSelf );
List<Map<String, Object>> alternateLinks = findLinksWithSupportedMediaTypeByRel( links, mediaTypesToSupport,
"alternate" );
List<String> typesWithoutLink = findUnsupportedTypes( alternateLinks, mediaTypesToSupport );
Expand Down Expand Up @@ -735,15 +726,6 @@ private String findGetFeaturesUrlForGeoJson( Map<String, Object> collection ) {
return null;
}

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;
}

private void assertIntegerGreaterZero( Object value, String propertyName ) {
if ( value instanceof Number )
assertIntegerGreaterZero( ( (Number) value ).intValue(), propertyName );
Expand Down
Loading

0 comments on commit 7f3b98c

Please sign in to comment.