From 3abce1479a31e9c25c49f9fd3751912ec0bc1eba Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Thu, 28 Jun 2018 18:13:36 +0200 Subject: [PATCH] #8 - implemented A.4.4.11. A.4.4.12, A.4.4.13, test methods 2,3 --- .../collections/GetFeaturesOperation.java | 259 +++++++++++++++--- .../collections/GetFeaturesOperationIT.java | 24 ++ 2 files changed, 252 insertions(+), 31 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 f30d3888..c08a5924 100644 --- a/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java +++ b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java @@ -66,6 +66,47 @@ public Object[][] collectionItemUris( ITestContext testContext ) { return collectionsData; } + @DataProvider(name = "collectionItemUrisWithLimit") + public Object[][] collectionItemUrisWithLimits( ITestContext testContext ) { + // TODO: find values between min and max described in OpenApi document (per collection) + Object[][] collectionsData = new Object[collections.size() * 3][]; + int i = 0; + for ( Map collection : collections ) { + collectionsData[i++] = new Object[] { collection, 5 }; + collectionsData[i++] = new Object[] { collection, 100 }; + collectionsData[i++] = new Object[] { collection, 1000 }; + } + return collectionsData; + } + + @DataProvider(name = "collectionItemUrisWithBboxes") + public Object[][] collectionItemUrisWithBboxes( ITestContext testContext ) { + // TODO: find values + Object[][] collectionsData = new Object[collections.size()][]; + int i = 0; + for ( Map collection : collections ) { + // Example 5. The bounding box of the New Zealand Exclusive Economic Zone + collectionsData[i++] = new Object[] { collection, "160.6,-55.95,-170,-25.89" }; + } + return collectionsData; + } + + @DataProvider(name = "collectionItemUrisWithTimes") + public Object[][] collectionItemUrisWithTimes( ITestContext testContext ) { + // TODO: find values + Object[][] collectionsData = new Object[collections.size() * 3][]; + int i = 0; + for ( Map collection : collections ) { + // Example 6. A date-time + collectionsData[i++] = new Object[] { collection, "2018-02-12T23%3A20%3A50Z" }; + // Example 7. A period using a start and end time + collectionsData[i++] = new Object[] { collection, "2018-02-12T00%3A00%3A00Z%2F2018-03-18T12%3A31%3A12Z" }; + // Example 8. A period using start time and a duration + collectionsData[i++] = new Object[] { collection, "2018-02-12T00%3A00%3A00Z%2FP1M6DT12H31M12S" }; + } + return collectionsData; + } + @BeforeClass public void retrieveRequiredInformationFromTestContext( ITestContext testContext ) { this.apiModel = (OpenApi3) testContext.getSuite().getAttribute( API_MODEL.getName() ); @@ -195,19 +236,7 @@ public void validateGetFeaturesOperationResponse_property_timeStamp( Map + * + * @param collection + * the collection under test, never null + * */ @Test(description = "Implements A.4.4.11. Limit Parameter (Requirement 18)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") public void validateLimitParameter( Map collection ) { @@ -340,6 +357,50 @@ public void validateLimitParameter( Map collection ) { assertIntegerGreaterZero( schema.getDefault(), "schema -> default" ); } + /** + * A.4.4.11. Limit Parameter (Test method 2, 3) + * + * a) Test Purpose: Validate the proper handling of the limit parameter. + * + * b) Pre-conditions: Tests A.4.4.9 and A.4.4.10 have completed successfully. + * + * c) Test Method: + * + * Repeat Test A.4.4.9 using different values for the limit parameter. + * + * For each execution of Test A.4.4.9, repeat Test A.4.4.10 to validate the results. + * + * d) References: Requirement 19 + * + * @param collection + * the collection under test, never null + * @param limit + * limit parameter to request, never null + * @throws URISyntaxException + * if the creation of a uri fails + */ + @Test(description = "Implements A.4.4.11. Limit Parameter (Requirement 19)", dataProvider = "collectionItemUrisWithLimit", dependsOnMethods = "validateGetFeaturesOperation") + public void validateLimitParameter_requests( Map collection, int limit ) + throws URISyntaxException { + String collectionName = (String) collection.get( "name" ); + + String getFeaturesUrl = findGetFeatureUrlForGeoJson( collection ); + if ( getFeaturesUrl.isEmpty() ) + throw new SkipException( "Could not find url for collection with name " + collectionName + + " supporting GeoJson (type " + GEOJSON_MIME_TYPE + ")" ); + Date timeStampBeforeResponse = new Date(); + Response response = init().baseUri( getFeaturesUrl ).accept( GEOJSON_MIME_TYPE ).param( "limit", limit ).when().request( GET ); + response.then().statusCode( 200 ); + Date timeStampAfterResponse = new Date(); + + JsonPath jsonPath = response.jsonPath(); + assertTimeStamp( collectionName, jsonPath, timeStampBeforeResponse, timeStampAfterResponse ); + assertNumberReturned( collectionName, jsonPath ); + assertNumberMatched( collectionName, jsonPath ); + + // TODO: assert returned features + } + /** * A.4.4.12. Bounding Box Parameter (Test method 1) * @@ -368,6 +429,9 @@ public void validateLimitParameter( Map collection ) { * style: form * explode: false * + * + * @param collection + * the collection under test, never null */ @Test(description = "Implements A.4.4.12. Bounding Box (Requirement 20)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") public void validateBboxParameter( Map collection ) { @@ -396,6 +460,50 @@ public void validateBboxParameter( Map collection ) { assertEquals( itemsType, "number", String.format( msg, "schema -> items -> type", "number", itemsType ) ); } + /** + * A.4.4.12. Bounding Box Parameter (Test method 1) + * + * a) Test Purpose:Validate the proper handling of the bbox parameter. + * + * b) Pre-conditions: Tests A.4.4.9 and A.4.4.10 have completed successfully. + * + * c) Test Method: + * + * Repeat Test A.4.4.9 using different values for the limit parameter. + * + * For each execution of Test A.4.4.9, repeat Test A.4.4.10 to validate the results. + * + * d) References: Requirement 21 + * + * @param collection + * the collection under test, never null + * @param bbox + * bbox parameter to request, never null + * @throws URISyntaxException + * if the creation of a uri fails + */ + @Test(description = "Implements A.4.4.12. Bounding Box Parameter (Requirement 21)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateGetFeaturesOperation") + public void validateBboxParameter_requests( Map collection, String bbox ) + throws URISyntaxException { + String collectionName = (String) collection.get( "name" ); + + String getFeaturesUrl = findGetFeatureUrlForGeoJson( collection ); + if ( getFeaturesUrl.isEmpty() ) + throw new SkipException( "Could not find url for collection with name " + collectionName + + " supporting GeoJson (type " + GEOJSON_MIME_TYPE + ")" ); + Date timeStampBeforeResponse = new Date(); + Response response = init().baseUri( getFeaturesUrl ).accept( GEOJSON_MIME_TYPE ).param( "bbox", bbox ).when().request( GET ); + response.then().statusCode( 200 ); + Date timeStampAfterResponse = new Date(); + + JsonPath jsonPath = response.jsonPath(); + assertTimeStamp( collectionName, jsonPath, timeStampBeforeResponse, timeStampAfterResponse ); + assertNumberReturned( collectionName, jsonPath ); + assertNumberMatched( collectionName, jsonPath ); + + // TODO: assert returned features + } + /** * A.4.4.13. Time Parameter (Test method 1) * @@ -420,6 +528,9 @@ public void validateBboxParameter( Map collection ) { * style: form * explode: false * + * + * @param collection + * the collection under test, never null */ @Test(description = "Implements A.4.4.13. Time (Requirement 22)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") public void validateTimeParameter( Map collection ) { @@ -441,6 +552,92 @@ public void validateTimeParameter( Map collection ) { assertEquals( schema.getType(), "string", String.format( msg, "schema -> type", "string", schema.getType() ) ); } + /** + * A.4.4.13. Time Parameter (Test method 2, 3) + * + * a) Test Purpose:Validate the proper handling of the bbox parameter. + * + * b) Pre-conditions: Tests A.4.4.9 and A.4.4.10 have completed successfully. + * + * c) Test Method: + * + * Repeat Test A.4.4.9 using different values for the limit parameter. + * + * For each execution of Test A.4.4.9, repeat Test A.4.4.10 to validate the results. + * + * d) References: Requirement 23 + * + * @param collection + * the collection under test, never null + * @param time + * time parameter to request, never null + * @throws URISyntaxException + * if the creation of a uri fails + * + */ + @Test(description = "Implements A.4.4.12. Bounding Box Parameter (Requirement 23)", dataProvider = "collectionItemUrisWithTimes", dependsOnMethods = "validateGetFeaturesOperation") + public void validateTimeParameter_requests( Map collection, String time ) + throws URISyntaxException { + String collectionName = (String) collection.get( "name" ); + + String getFeaturesUrl = findGetFeatureUrlForGeoJson( collection ); + if ( getFeaturesUrl.isEmpty() ) + throw new SkipException( "Could not find url for collection with name " + collectionName + + " supporting GeoJson (type " + GEOJSON_MIME_TYPE + ")" ); + Date timeStampBeforeResponse = new Date(); + Response response = init().baseUri( getFeaturesUrl ).accept( GEOJSON_MIME_TYPE ).param( "time", time ).when().request( GET ); + response.then().statusCode( 200 ); + Date timeStampAfterResponse = new Date(); + + JsonPath jsonPath = response.jsonPath(); + assertTimeStamp( collectionName, jsonPath, timeStampBeforeResponse, timeStampAfterResponse ); + assertNumberReturned( collectionName, jsonPath ); + assertNumberMatched( collectionName, jsonPath ); + + // TODO: assert returned features + } + + private void assertTimeStamp( String collectionName, JsonPath jsonPath, Date timeStampBeforeResponse, + Date timeStampAfterResponse ) { + String timeStamp = jsonPath.getString( "timeStamp" ); + if ( timeStamp == null ) + throw new SkipException( "Property timeStamp is not set in collection items '" + collectionName + "'" ); + + Date date = parseAsDate( timeStamp ); + assertTrue( date.before( timeStampAfterResponse ), + "timeStamp in response must be before the request was send (" + + DATE_FORMAT.format( timeStampAfterResponse ) + ") but was '" + timeStamp + + "'" ); + assertTrue( date.after( timeStampBeforeResponse ), "timeStamp in response must be after the request was send (" + + DATE_FORMAT.format( timeStampBeforeResponse ) + + ") but was '" + timeStamp + "'" ); + } + + private void assertNumberReturned( String collectionName, JsonPath jsonPath ) { + if ( !hasProperty( "numberReturned", jsonPath ) ) { + throw new SkipException( "Property numberReturned is not set in collection items '" + collectionName + "'" ); + } + int numberReturned = jsonPath.getInt( "numberReturned" ); + + int numberOfFeatures = jsonPath.getList( "features" ).size(); + assertEquals( numberReturned, numberOfFeatures, "Value of numberReturned (" + numberReturned + + ") does not match the number of features in the response (" + + numberOfFeatures + ")" ); + } + + private void assertNumberMatched( String collectionName, JsonPath jsonPath ) + throws URISyntaxException { + if ( !hasProperty( "numberMatched", jsonPath ) ) { + throw new SkipException( "Property numberMatched is not set in collection items '" + collectionName + "'" ); + } + int numberMatched = jsonPath.getInt( "numberMatched" ); + int numberOfAllReturnedFeatures = collectNumberOfAllReturnedFeatures( jsonPath ); + assertEquals( numberMatched, numberOfAllReturnedFeatures, + "Value of numberReturned (" + numberMatched + + ") does not match the number of features in all responses (" + + numberOfAllReturnedFeatures + ")" ); + } + private Parameter findParameterByName( String collectionName, String name ) { String collectionItemPath = "/" + COLLECTIONS.getPathItem() + "/" + collectionName + "/items"; Path path = apiModel.getPath( collectionItemPath ); 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 248f5405..cf79f835 100644 --- a/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java +++ b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java @@ -73,6 +73,30 @@ public void testGetFeatureOperations() // fails (schema->items->type missing): getFeaturesOperation.validateBboxParameter(); // fails (parameter is missing): getFeaturesOperation.validateTimeParameter( parameter ); } + + Object[][] collectionsWithLimits = getFeaturesOperation.collectionItemUrisWithLimits( testContext ); + for ( Object[] collection : collectionsWithLimits ) { + Map parameter = (Map) collection[0]; + int limit = (int) collection[1]; + // skipped (parameter missing): + // getFeaturesOperation.validateLimitParameter_requests( parameter, limit ); + } + + Object[][] collectionsWithBboxes = getFeaturesOperation.collectionItemUrisWithBboxes( testContext ); + for ( Object[] collection : collectionsWithBboxes ) { + Map parameter = (Map) collection[0]; + String bbox = (String) collection[1]; + // fails: response is empty + // getFeaturesOperation.validateBboxParameter_requests( parameter, bbox ); + } + + Object[][] collectionsWithTimes = getFeaturesOperation.collectionItemUrisWithTimes( testContext ); + for ( Object[] collection : collectionsWithTimes ) { + Map parameter = (Map) collection[0]; + String time = (String) collection[1]; + // skipped (parameter missing): + // getFeaturesOperation.validateTimeParameter_requests( parameter, time ); + } } }