Skip to content

Commit

Permalink
#8 - use limit parameter bounded by parameter description in OpenApi …
Browse files Browse the repository at this point in the history
…document
  • Loading branch information
lgoltz committed Jul 2, 2018
1 parent 1756e3b commit defc226
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object[]> collectionItemUris( ITestContext testContext ) {
List<Object[]> collectionsData = new ArrayList<>();
for ( Map<String, Object> 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<Object[]> collectionItemUrisWithLimits( ITestContext testContext ) {
List<Object[]> collectionsWithLimits = new ArrayList<>();
for ( Map<String, Object> 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")
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public void testGetFeatureOperations()
getFeaturesOperation.initCommonFixture( testContext );
getFeaturesOperation.retrieveRequiredInformationFromTestContext( testContext );

Object[][] collections = getFeaturesOperation.collectionItemUris( testContext );
for ( Object[] collection : collections ) {
Iterator<Object[]> collections = getFeaturesOperation.collectionItemUris( testContext );
for ( Iterator<Object[]> it = collections; it.hasNext(); ) {
Object[] collection = it.next();
Map<String, Object> parameter = (Map<String, Object>) collection[0];
getFeaturesOperation.validateGetFeaturesOperation( parameter );
getFeaturesOperation.validateGetFeaturesOperationResponse_Links( parameter );
Expand All @@ -76,12 +77,13 @@ public void testGetFeatureOperations()
// fails (parameter is missing): getFeaturesOperation.validateTimeParameter( parameter );
}

Object[][] collectionsWithLimits = getFeaturesOperation.collectionItemUrisWithLimits( testContext );
for ( Object[] collection : collectionsWithLimits ) {
Iterator<Object[]> collectionsWithLimits = getFeaturesOperation.collectionItemUrisWithLimits( testContext );
for ( Iterator<Object[]> it = collectionsWithLimits; it.hasNext(); ) {
Object[] collection = it.next();
Map<String, Object> parameter = (Map<String, Object>) collection[0];
int limit = (int) collection[1];
// skipped (parameter missing):
// getFeaturesOperation.validateLimitParameter_requests( parameter, limit );
getFeaturesOperation.validateLimitParameter_requests( parameter, limit );
}

Iterator<Object[]> collectionsWithBboxes = getFeaturesOperation.collectionItemUrisWithBboxes( testContext );
Expand Down

0 comments on commit defc226

Please sign in to comment.