-
Notifications
You must be signed in to change notification settings - Fork 6
/
FeaturesBBox.java
426 lines (394 loc) · 21.2 KB
/
FeaturesBBox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package org.opengis.cite.ogcapifeatures10.conformance.core.collections;
import static io.restassured.http.Method.GET;
import static org.opengis.cite.ogcapifeatures10.EtsAssert.assertFalse;
import static org.opengis.cite.ogcapifeatures10.OgcApiFeatures10.GEOJSON_MIME_TYPE;
import static org.opengis.cite.ogcapifeatures10.openapi3.OpenApiUtils.retrieveParameterByName;
import static org.opengis.cite.ogcapifeatures10.util.JsonUtils.findFeaturesUrlForGeoJson;
import static org.opengis.cite.ogcapifeatures10.util.JsonUtils.parseSpatialExtent;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URISyntaxException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.locationtech.jts.io.ParseException;
import org.opengis.cite.ogcapifeatures10.openapi3.TestPoint;
import org.opengis.cite.ogcapifeatures10.util.BBox;
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.reprezen.kaizen.oasparser.model3.Parameter;
import com.reprezen.kaizen.oasparser.model3.Schema;
import io.restassured.response.Response;
/**
* A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public class FeaturesBBox extends AbstractFeatures {
@DataProvider(name = "collectionItemUrisWithBboxes")
public Iterator<Object[]> collectionItemUrisWithBboxes( ITestContext testContext ) {
List<Object[]> collectionsWithBboxes = new ArrayList<>();
for ( Map<String, Object> collection : collections ) {
BBox extent = parseSpatialExtent( collection );
if ( extent != null ) {
collectionsWithBboxes.add( new Object[] { collection, extent } );
// These should include test cases which cross the
// meridian,
collectionsWithBboxes.add( new Object[] { collection, new BBox( -1.5, 50.0, 1.5, 53.0 ) } );
// equator,
collectionsWithBboxes.add( new Object[] { collection, new BBox( -80.0, -5.0, -70.0, 5.0 ) } );
// 180 longitude,
collectionsWithBboxes.add( new Object[] { collection, new BBox( 177.0, 65.0, -177.0, 70.0 ) } );
// and polar regions.
collectionsWithBboxes.add( new Object[] { collection, new BBox( -180.0, 85.0, 180.0, 90.0 ) } );
collectionsWithBboxes.add( new Object[] { collection, new BBox( -180.0, -90.0, 180.0, -85.0 ) } );
}
}
return collectionsWithBboxes.iterator();
}
/**
* <pre>
* Abstract Test 14: /ats/core/fc-bbox-definition
* Test Purpose: Validate that the bounding box query parameters are constructed correctly.
* Requirement: /req/core/fc-bbox-definition
*
* Test Method: Verify that the bbox query parameter complies with the following definition (using an OpenAPI Specification 3.0 fragment):
*
* name: bbox
* in: query
* required: false
* schema:
* type: array
* minItems: 4
* maxItems: 6
* items:
* type: number
* style: form
* explode: false
*
* Use a bounding box with four numbers in all requests:
* * Lower left corner, WGS 84 longitude
* * Lower left corner, WGS 84 latitude
* * Upper right corner, WGS 84 longitude
* * Upper right corner, WGS 84 latitude
* </pre>
*
* @param testPoint
* the testPoint under test, never <code>null</code>
*/
@Test(description = "A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 14: (Requirement /req/core/fc-bbox-definition)", dataProvider = "collectionPaths", dependsOnGroups = "featuresBase", alwaysRun = true)
public void boundingBoxParameterDefinition( TestPoint testPoint ) {
Parameter bbox = retrieveParameterByName( testPoint.getPath(), getApiModel(), "bbox" );
assertNotNull( bbox, "Required bbox parameter for collections path '" + testPoint.getPath()
+ "' in OpenAPI document is missing" );
String msg = "Expected property '%s' with value '%s' for collections path '" + testPoint.getPath()
+ "' but was '%s'.";
assertEquals( bbox.getName(), "bbox", String.format( msg, "name", "bbox", bbox.getName() ) );
assertEquals( bbox.getIn(), "query", String.format( msg, "in", "query", bbox.getIn() ) );
assertFalse( isRequired( bbox ), String.format( msg, "required", "false", bbox.getRequired() ) );
assertEquals( bbox.getStyle(), "form", String.format( msg, "style", "form", bbox.getStyle() ) );
assertFalse( isExplode( bbox ), String.format( msg, "explode", "false", bbox.getExplode() ) );
Schema schema = bbox.getSchema();
assertNotNull( schema, "Expected schema for bbox parameter for collections path '" + testPoint.getPath() );
assertEquals( schema.getType(), "array", String.format( msg, "schema -> type", "array", schema.getType() ) );
assertNotNull( schema.getMinItems(), String.format( msg, "schema -> minItems", "null", schema.getMinItems() ) );
assertEquals( schema.getMinItems().intValue(), 4,
String.format( msg, "schema -> minItems", "4", schema.getMinItems() ) );
assertNotNull( schema.getMaxItems(), String.format( msg, "schema -> maxItems", "null", schema.getMaxItems() ) );
assertEquals( schema.getMaxItems().intValue(), 6,
String.format( msg, "schema -> maxItems", "6", schema.getMaxItems() ) );
String itemsType = schema.getItemsSchema().getType();
assertEquals( itemsType, "number", String.format( msg, "schema -> items -> type", "number", itemsType ) );
}
/**
* <pre>
* Abstract Test 13: /ats/core/fc-op
* Test Purpose: Validate that features can be identified and extracted from a Collection using query parameters.
* Requirement: /req/core/fc-op
*
* Test Method
* 1. For every feature collection identified in Collections, issue an HTTP GET request to the URL /collections/{collectionId}/items where {collectionId} is the id property for a Collection described in the Collections content.
* 2. Validate that a document was returned with a status code 200.
* 3. Validate the contents of the returned document using test /ats/core/fc-response.
*
* Repeat these tests using the following parameter tests:
* Bounding Box:
* * Parameter /ats/core/fc-bbox-definition
* * Response /ats/core/fc-bbox-response
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 13: (Requirement /req/core/fc-op)", dataProvider = "collectionItemUrisWithBboxes", dependsOnGroups = "featuresBase", alwaysRun = true)
public void validateFeaturesWithBoundingBoxOperation( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
String getFeaturesUrl = findFeaturesUrlForGeoJson( rootUri, collection );
if ( getFeaturesUrl.isEmpty() )
throw new SkipException( "Could not find url for collection with id " + collectionId
+ " supporting GeoJson (type " + GEOJSON_MIME_TYPE + ")" );
ZonedDateTime timeStampBeforeResponse = ZonedDateTime.now();
Response response = init().baseUri( getFeaturesUrl ).accept( GEOJSON_MIME_TYPE ).param( "bbox",
bbox.asQueryParameter() ).when().request( GET );
response.then().statusCode( 200 );
ZonedDateTime timeStampAfterResponse = ZonedDateTime.now();
ResponseData responseData = new ResponseData( response, timeStampBeforeResponse, timeStampAfterResponse );
collectionIdAndResponse.put( asKey( collectionId, bbox ), responseData );
}
/**
* <pre>
* Abstract Test 15: /ats/core/fc-bbox-response
* Test Purpose: Validate that the bounding box query parameters are processed corrrectly.
* Requirement: /req/core/fc-bbox-response
*
* Test Method
* 1. Verify that only features that have a spatial geometry that intersects the bounding box are returned as part of the result set.
* 2. Verify that the bbox parameter matched all features in the collection that were not associated with a spatial geometry (this is only applicable for datasets that include features without a spatial geometry).
* 3. Verify that the coordinate reference system of the geometries is WGS 84 longitude/latitude ("http://www.opengis.net/def/crs/OGC/1.3/CRS84" or "http://www.opengis.net/def/crs/OGC/0/CRS84h") since no parameter bbox-crs was specified in the request.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 15: (Requirement /req/core/fc-bbox-response)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
ResponseData response = collectionIdAndResponse.get( asKey( collectionId, bbox ) );
if ( response == null )
throw new SkipException( "Could not find a response for collection with id " + collectionId );
// TODO: assert returned features
}
/**
* Abstract Test 2, Test Method 1
*
* <pre>
* Abstract Test 2: /ats/core/crs84
* Test Purpose: Validate that all spatial geometries provided through the API are in the CRS84 spatial reference system unless otherwise requested by the client.
* Requirement: /req/core/crs84
*
* Test Method
* 1. Do not specify a coordinate reference system in any request. All spatial data should be in the CRS84 reference system.
* 2. Validate retrieved spatial data using the CRS84 reference system.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
* @throws ParseException
* if the geometry could not be parsed
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 2, Test Method 2 (Requirement /req/core/crs84)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesResponse_GeometryInCRS84( Map<String, Object> collection, BBox bbox )
throws ParseException {
String collectionId = (String) collection.get( "id" );
validateGeometriesInCrs84( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 1
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 1. Validate that the type property is present and has a value of FeatureCollection
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 1 (Requirement /req/core/fc-response)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse_TypeProperty( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
validateTypeProperty( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 2
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 2. Validate the features property is present and that it is populated with an array of feature items.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 2 (Requirement /req/core/fc-response)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse_FeaturesProperty( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
validateFeaturesProperty( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 4 (Abstract Test 23)
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 4. If the links property is present, validate that all entries comply with /ats/core/fc-links
* </pre>
*
* <pre>
* Abstract Test 23: /ats/core/fc-links
* Test Purpose: Validate that the required links are included in the Collections document.
* Requirement: /req/core/fc-links, /req/core/fc-rel-type
*
* Test Method:
* Verify that the response document includes:
* 1. a link to this response document (relation: self),
* 2. a link to the response document in every other media type supported by the server (relation: alternate).
*
* Verify that all links include the rel and type link parameters.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 4 (Requirement /req/core/fc-response) - Abstract Test 23 (Requirement /req/core/fc-links, /req/core/fc-rel-type)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse_Links( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
validateLinks( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 5 (Abstract Test 24)
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 5. If the timeStamp property is present, validate that it complies with /ats/core/fc-timeStamp
* </pre>
*
* <pre>
* Abstract Test 24: /ats/core/fc-timeStamp
* Test Purpose: Validate the timeStamp parameter returned with a Features response
* Requirement: /req/core/fc-timeStamp
*
* Test Method: Validate that the timeStamp value is set to the time when the response was generated.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 5 (Requirement /req/core/fc-response) - Abstract Test 24 (Requirement /req/core/fc-timeStamp)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse_TimeStamp( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
validateTimeStamp( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 6 (Abstract Test 25)
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 6. If the numberMatched property is present, validate that it complies with /ats/core/fc-numberMatched
* </pre>
*
* <pre>
* Abstract Test 25: /ats/core/fc-numberMatched
* Test Purpose: Validate the numberMatched parameter returned with a Features response
* Requirement: /req/core/fc-numberMatched
*
* Test Method: Validate that the value of the numberMatched parameter is identical to the number of features in the feature collections that match the selection parameters like bbox, datetime or additional filter parameters.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*
* @throws URISyntaxException
* if the creation of a uri fails
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 6 (Requirement /req/core/fc-response) - Abstract Test 25 (Requirement /req/core/fc-numberMatched)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesWithBoundingBoxResponse_NumberMatched( Map<String, Object> collection, BBox bbox )
throws URISyntaxException {
String collectionId = (String) collection.get( "id" );
validateNumberMatched( asKey( collectionId, bbox ) );
}
/**
* Abstract Test 22, Test Method 7 (Abstract Test 26)
*
* <pre>
* Abstract Test 22: /ats/core/fc-response
* Test Purpose: Validate that the Feature Collections complies with the require structure and contents.
* Requirement: /req/core/fc-response
*
* Test Method
* 7. If the numberReturned property is present, validate that it complies with /ats/core/fc-numberReturned
* </pre>
*
* <pre>
* Abstract Test 26: /ats/core/fc-numberReturned
* Test Purpose: Validate the numberReturned parameter returned with a Features response
* Requirement: /req/core/fc-numberReturned
*
* Test Method: Validate that the numberReturned value is identical to the number of features in the response.
* </pre>
*
* @param collection
* the collection under test, never <code>null</code>
* @param bbox
* bbox parameter to request, never <code>null</code>
*/
@Test(description = "Implements A.2.7. Features {root}/collections/{collectionId}/items - BoundingBox, Abstract Test 22, Test Method 7 (Requirement /req/core/fc-response) - Abstract Test 26 (Requirement /req/core/fc-numberReturned)", dataProvider = "collectionItemUrisWithBboxes", dependsOnMethods = "validateFeaturesWithBoundingBoxOperation", alwaysRun = true)
public void validateFeaturesResponse_NumberReturned( Map<String, Object> collection, BBox bbox ) {
String collectionId = (String) collection.get( "id" );
validateNumberReturned( asKey( collectionId, bbox ) );
}
private CollectionIdWithBboxKey asKey( String collectionId, BBox bBox ) {
return new CollectionIdWithBboxKey( collectionId, bBox );
}
private class CollectionIdWithBboxKey extends CollectionResponseKey {
BBox bbox;
public CollectionIdWithBboxKey( String collectionId, BBox bbox ) {
super( collectionId );
this.bbox = bbox;
}
@Override
public boolean equals( Object o ) {
if ( this == o )
return true;
if ( o == null || getClass() != o.getClass() )
return false;
if ( !super.equals( o ) )
return false;
CollectionIdWithBboxKey that = (CollectionIdWithBboxKey) o;
return Objects.equals( bbox, that.bbox );
}
@Override
public int hashCode() {
return Objects.hash( super.hashCode(), bbox );
}
}
}