From defc226161c1d2a7e5b0d88899c9113d03c8dd4e Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Mon, 2 Jul 2018 21:42:12 +0200 Subject: [PATCH] #8 - use limit parameter bounded by parameter description in OpenApi document --- .../collections/GetFeaturesOperation.java | 35 ++++++++++++------- .../collections/GetFeaturesOperationIT.java | 12 ++++--- 2 files changed, 30 insertions(+), 17 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 7edc9248..c49e3468 100644 --- a/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java +++ b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java @@ -30,6 +30,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Random; import org.opengis.cite.wfs30.CommonFixture; import org.opengis.cite.wfs30.SuiteAttribute; @@ -65,24 +66,24 @@ public class GetFeaturesOperation extends CommonFixture { private OpenApi3 apiModel; @DataProvider(name = "collectionItemUris") - public Object[][] collectionItemUris( ITestContext testContext ) { - Object[][] collectionsData = new Object[collections.size()][]; - for ( int i = 0; i < collections.size(); i++ ) { - collectionsData[i] = new Object[] { collections.get( i ) }; + public Iterator collectionItemUris( ITestContext testContext ) { + List collectionsData = new ArrayList<>(); + for ( Map collection : collections ) { + collectionsData.add( new Object[] { collection } ); } - return collectionsData; + return collectionsData.iterator(); } @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() * 2][]; - int i = 0; + public Iterator collectionItemUrisWithLimits( ITestContext testContext ) { + List collectionsWithLimits = new ArrayList<>(); for ( Map collection : collections ) { - collectionsData[i++] = new Object[] { collection, 5 }; - collectionsData[i++] = new Object[] { collection, 15 }; + Parameter limit = findParameterByName( (String) collection.get( "name" ), "limit" ); + int[] ints = getTwoRandomLimits( limit ); + collectionsWithLimits.add( new Object[] { collection, ints[0] } ); + collectionsWithLimits.add( new Object[] { collection, ints[0] } ); } - return collectionsData; + return collectionsWithLimits.iterator(); } @DataProvider(name = "collectionItemUrisWithBboxes") @@ -743,6 +744,16 @@ private void assertIntegerGreaterZero( int value, String propertyName ) { assertTrue( value > 0, String.format( msg, propertyName, value ) ); } + private int[] getTwoRandomLimits( Parameter limit ) { + Schema schema = limit.getSchema(); + int min = schema.getMinimum().intValue(); + int max = schema.getMaximum().intValue(); + if ( max > 25 ) + max = 25; + Random random = new Random(); + return random.ints( 2, min, max ).toArray(); + } + private class ResponseData { private final Response response; 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 4a860123..4de28df4 100644 --- a/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java +++ b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java @@ -60,8 +60,9 @@ public void testGetFeatureOperations() getFeaturesOperation.initCommonFixture( testContext ); getFeaturesOperation.retrieveRequiredInformationFromTestContext( testContext ); - Object[][] collections = getFeaturesOperation.collectionItemUris( testContext ); - for ( Object[] collection : collections ) { + Iterator collections = getFeaturesOperation.collectionItemUris( testContext ); + for ( Iterator it = collections; it.hasNext(); ) { + Object[] collection = it.next(); Map parameter = (Map) collection[0]; getFeaturesOperation.validateGetFeaturesOperation( parameter ); getFeaturesOperation.validateGetFeaturesOperationResponse_Links( parameter ); @@ -76,12 +77,13 @@ public void testGetFeatureOperations() // fails (parameter is missing): getFeaturesOperation.validateTimeParameter( parameter ); } - Object[][] collectionsWithLimits = getFeaturesOperation.collectionItemUrisWithLimits( testContext ); - for ( Object[] collection : collectionsWithLimits ) { + Iterator collectionsWithLimits = getFeaturesOperation.collectionItemUrisWithLimits( testContext ); + for ( Iterator it = collectionsWithLimits; it.hasNext(); ) { + Object[] collection = it.next(); Map parameter = (Map) collection[0]; int limit = (int) collection[1]; // skipped (parameter missing): - // getFeaturesOperation.validateLimitParameter_requests( parameter, limit ); + getFeaturesOperation.validateLimitParameter_requests( parameter, limit ); } Iterator collectionsWithBboxes = getFeaturesOperation.collectionItemUrisWithBboxes( testContext );