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

Implemented support of compact API flavor #35

Merged
merged 3 commits into from
Aug 17, 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
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 @@ -21,8 +22,8 @@

import org.opengis.cite.wfs30.CommonFixture;
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;
Expand All @@ -45,8 +46,6 @@ public class FeatureCollectionsMetadataOperation extends CommonFixture {

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 +74,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 +108,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 @@ -201,10 +187,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,8 +218,8 @@ 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 );
List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForCollectionMetadata( apiModel,
collectionName );
if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );
Expand Down Expand Up @@ -291,13 +275,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 +307,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,26 +344,6 @@ 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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
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.WFS3.PATH.COLLECTIONS;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPoints;
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 Down Expand Up @@ -45,15 +44,6 @@ public class GetFeatureOperation extends CommonFixture {

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

@DataProvider(name = "collectionItemUris")
public Iterator<Object[]> collectionItemUris( ITestContext testContext ) {
List<Object[]> collectionsData = new ArrayList<>();
for ( Map<String, Object> collection : collections ) {
collectionsData.add( new Object[] { collection } );
}
return collectionsData.iterator();
}

@DataProvider(name = "collectionFeatureId")
public Iterator<Object[]> collectionFeatureId( ITestContext testContext ) {
Map<String, String> collectionNameToFeatureId = (Map<String, String>) testContext.getSuite().getAttribute( SuiteAttribute.FEATUREIDS.getName() );
Expand Down Expand Up @@ -154,15 +144,16 @@ public void getFeatureOperation( Map<String, Object> collection, String featureI
* @param collection
* the collection under test, never <code>null</code>
*/
@Test(description = "Implements A.4.4.15. Validate the Get Feature Operation Response (Requirement 32)", dataProvider = "collectionItemUris", dependsOnMethods = "getFeatureOperation")
public void validateTheGetFeatureOperationResponse( Map<String, Object> collection ) {
@Test(description = "Implements A.4.4.15. Validate the Get Feature Operation Response (Requirement 32)", dataProvider = "collectionFeatureId", dependsOnMethods = "getFeatureOperation")
public void validateTheGetFeatureOperationResponse( Map<String, Object> collection, String featureId ) {
String collectionName = (String) collection.get( "name" );
Response response = collectionNameAndResponse.get( collectionName );
if ( response == null )
throw new SkipException( "Could not find a response for collection with name " + collectionName );

List<TestPoint> testPointsForNamedCollection = retrieveTestPoints( apiModel, COLLECTIONS,
collectionName + "\\/items\\/\\{.*\\}" );
List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForFeature( apiModel, collectionName,
featureId );

if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -35,7 +36,6 @@

import org.opengis.cite.wfs30.CommonFixture;
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.util.BBox;
import org.opengis.cite.wfs30.util.TemporalExtent;
Expand Down Expand Up @@ -217,8 +217,7 @@ 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 = OpenApiUtils.retrieveTestPoints( apiModel, COLLECTIONS,
collectionName + "/items" );
List<TestPoint> testPointsForNamedCollection = retrieveTestPointsForCollection( apiModel, collectionName );
if ( testPointsForNamedCollection.isEmpty() )
throw new SkipException( "Could not find collection with name " + collectionName
+ " in the OpenAPI document" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.opengis.cite.wfs30.CommonFixture;
import org.opengis.cite.wfs30.openapi3.TestPoint;
import org.opengis.cite.wfs30.openapi3.UriBuilder;
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void validateConformanceOperationAndResponse( TestPoint testPoint ) {
* d) References: Requirement 5
*/
private Response validateConformanceOperation( TestPoint testPoint ) {
String testPointUri = testPoint.createUri();
String testPointUri = new UriBuilder( testPoint ).buildUrl();
return init().baseUri( testPointUri ).accept( JSON ).when().request( GET );
}

Expand Down
Loading