From be6782d7333098b0263e1547403f1bdfc857308d Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Thu, 28 Jun 2018 17:40:59 +0200 Subject: [PATCH] #8 - changed test for limit, bbox and time parameter to be executed per collections item --- .../collections/GetFeaturesOperation.java | 50 ++++++++++++++----- .../collections/GetFeaturesOperationIT.java | 6 +-- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java index 20546739..f30d3888 100644 --- a/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java +++ b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java @@ -36,7 +36,9 @@ import com.fasterxml.jackson.databind.util.ISO8601DateFormat; 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; +import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.model3.Schema; import io.restassured.path.json.JsonPath; @@ -315,10 +317,13 @@ public void validateGetFeaturesOperationResponse_property_numberMatched( Map */ - @Test(description = "Implements A.4.4.11. Limit Parameter (Requirement 18)", dependsOnMethods = "validateGetFeaturesOperation") - public void validateLimitParameter() { - Parameter limit = apiModel.getParameter( "limit" ); - assertNotNull( limit, "Required limit parameter in OpenAPI document is missing" ); + @Test(description = "Implements A.4.4.11. Limit Parameter (Requirement 18)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") + public void validateLimitParameter( Map collection ) { + String collectionName = (String) collection.get( "name" ); + Parameter limit = findParameterByName( collectionName, "limit" ); + + assertNotNull( limit, "Required limit parameter for collections item with name '" + collectionName + + "' in OpenAPI document is missing" ); String msg = "Expected property '%s' with value '%s' but was '%s'"; @@ -364,10 +369,13 @@ public void validateLimitParameter() { * explode: false * */ - @Test(description = "Implements A.4.4.12. Bounding Box (Requirement 20)", dependsOnMethods = "validateGetFeaturesOperation") - public void validateBboxParameter() { - Parameter bbox = apiModel.getParameter( "bbox" ); - assertNotNull( bbox, "Required bbox parameter in OpenAPI document is missing" ); + @Test(description = "Implements A.4.4.12. Bounding Box (Requirement 20)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") + public void validateBboxParameter( Map collection ) { + String collectionName = (String) collection.get( "name" ); + Parameter bbox = findParameterByName( collectionName, "bbox" ); + + assertNotNull( bbox, "Required bbox parameter for collections item with name '" + collectionName + + "' in OpenAPI document is missing" ); String msg = "Expected property '%s' with value '%s' but was '%s'"; @@ -413,10 +421,13 @@ public void validateBboxParameter() { * explode: false * */ - @Test(description = "Implements A.4.4.13. Time (Requirement 22)", dependsOnMethods = "validateGetFeaturesOperation") - public void validateTimeParameter() { - Parameter time = apiModel.getParameter( "time" ); - assertNotNull( time, "Required time parameter in OpenAPI document is missing" ); + @Test(description = "Implements A.4.4.13. Time (Requirement 22)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") + public void validateTimeParameter( Map collection ) { + String collectionName = (String) collection.get( "name" ); + Parameter time = findParameterByName( collectionName, "time" ); + + assertNotNull( time, "Required time parameter for collections item with name '" + collectionName + + "' in OpenAPI document is missing" ); String msg = "Expected property '%s' with value '%s' but was '%s'"; @@ -430,6 +441,21 @@ public void validateTimeParameter() { assertEquals( schema.getType(), "string", String.format( msg, "schema -> type", "string", schema.getType() ) ); } + private Parameter findParameterByName( String collectionName, String name ) { + String collectionItemPath = "/" + COLLECTIONS.getPathItem() + "/" + collectionName + "/items"; + Path path = apiModel.getPath( collectionItemPath ); + if ( path != null ) { + for ( Parameter parameter : path.getParameters() ) + if ( name.equals( parameter.getName() ) ) + return parameter; + Operation get = path.getOperation( "get" ); + for ( Parameter parameter : get.getParameters() ) + if ( name.equals( parameter.getName() ) ) + return parameter; + } + return null; + } + private String findGetFeatureUrlForGeoJson( Map collection ) { List links = (List) collection.get( "links" ); for ( Object linkObject : links ) { diff --git a/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java index e0ceba1d..248f5405 100644 --- a/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java +++ b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java @@ -69,10 +69,10 @@ public void testGetFeatureOperations() // getFeaturesOperation.validateGetFeaturesOperationResponse_property_numberReturned( parameter ); // skipped (parameter missing): // getFeaturesOperation.validateGetFeaturesOperationResponse_property_numberMatched( parameter ); + getFeaturesOperation.validateLimitParameter( parameter ); + // fails (schema->items->type missing): getFeaturesOperation.validateBboxParameter(); + // fails (parameter is missing): getFeaturesOperation.validateTimeParameter( parameter ); } - getFeaturesOperation.validateLimitParameter(); - // fails (schema->items->type missing): getFeaturesOperation.validateBboxParameter(); - getFeaturesOperation.validateTimeParameter(); } }