@@ -159,7 +159,7 @@ public void deleteData() throws IOException {
159
159
}
160
160
161
161
public void testBasicGet () throws Exception {
162
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
162
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
163
163
mvtRequest .setJsonEntity ("{\" size\" : 100}" );
164
164
final VectorTile .Tile tile = execute (mvtRequest );
165
165
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
@@ -169,7 +169,7 @@ public void testBasicGet() throws Exception {
169
169
}
170
170
171
171
public void testExtent () throws Exception {
172
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
172
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
173
173
mvtRequest .setJsonEntity ("{\" size\" : 100, \" extent\" : 256}" );
174
174
final VectorTile .Tile tile = execute (mvtRequest );
175
175
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
@@ -178,17 +178,67 @@ public void testExtent() throws Exception {
178
178
assertLayer (tile , META_LAYER , 256 , 1 , 14 );
179
179
}
180
180
181
+ public void testExtentURL () throws Exception {
182
+ final Request mvtRequest = new Request (
183
+ getHttpMethod (),
184
+ INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y + "?extent=" + 512
185
+ );
186
+ mvtRequest .setJsonEntity ("{\" size\" : 100, \" extent\" : 256}" );
187
+ final VectorTile .Tile tile = execute (mvtRequest );
188
+ assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
189
+ assertLayer (tile , HITS_LAYER , 512 , 33 , 1 );
190
+ assertLayer (tile , AGGS_LAYER , 512 , 1 , 1 );
191
+ assertLayer (tile , META_LAYER , 512 , 1 , 14 );
192
+ }
193
+
194
+ public void testExactBounds () throws Exception {
195
+ {
196
+ final Request mvtRequest = new Request (getHttpMethod (), INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
197
+ mvtRequest .setJsonEntity ("{\" size\" : 0, \" grid_precision\" : 0}" );
198
+ final VectorTile .Tile tile = execute (mvtRequest );
199
+ assertThat (tile .getLayersCount (), Matchers .equalTo (1 ));
200
+ assertLayer (tile , META_LAYER , 4096 , 1 , 8 );
201
+ final VectorTile .Tile .Layer layer = getLayer (tile , META_LAYER );
202
+ assertThat (layer .getFeatures (0 ).getType (), Matchers .equalTo (VectorTile .Tile .GeomType .POLYGON ));
203
+
204
+ }
205
+ {
206
+ final Request mvtRequest = new Request (getHttpMethod (), INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
207
+ mvtRequest .setJsonEntity ("{\" size\" : 0, \" grid_precision\" : 0, \" exact_bounds\" : true}" );
208
+ final VectorTile .Tile tile = execute (mvtRequest );
209
+ assertThat (tile .getLayersCount (), Matchers .equalTo (1 ));
210
+ assertLayer (tile , META_LAYER , 4096 , 1 , 8 );
211
+ final VectorTile .Tile .Layer layer = getLayer (tile , META_LAYER );
212
+ // edge case: because all points are the same, the bounding box is a point and cannot be expressed as a polygon.
213
+ // Therefore the feature ends-up without a geometry.
214
+ assertThat (layer .getFeatures (0 ).hasType (), Matchers .equalTo (false ));
215
+ }
216
+ {
217
+ final Request mvtRequest = new Request (
218
+ getHttpMethod (),
219
+ INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y + "?exact_bounds=false"
220
+ );
221
+ mvtRequest .setJsonEntity ("{\" size\" : 0, \" grid_precision\" : 0, \" exact_bounds\" : true}" );
222
+ final VectorTile .Tile tile = execute (mvtRequest );
223
+ assertThat (tile .getLayersCount (), Matchers .equalTo (1 ));
224
+ assertLayer (tile , META_LAYER , 4096 , 1 , 8 );
225
+ final VectorTile .Tile .Layer layer = getLayer (tile , META_LAYER );
226
+ assertThat (layer .getFeatures (0 ).getType (), Matchers .equalTo (VectorTile .Tile .GeomType .POLYGON ));
227
+
228
+ }
229
+ }
230
+
181
231
public void testEmpty () throws Exception {
182
232
final int newY = (1 << z ) - 1 == y ? y - 1 : y + 1 ;
183
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + newY );
233
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + newY );
184
234
final VectorTile .Tile tile = execute (mvtRequest );
185
235
assertThat (tile .getLayersCount (), Matchers .equalTo (1 ));
186
236
assertLayer (tile , META_LAYER , 4096 , 1 , 10 );
187
237
}
188
238
189
239
public void testGridPrecision () throws Exception {
190
240
{
191
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
241
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
192
242
mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_precision\" : 7 }" );
193
243
final VectorTile .Tile tile = execute (mvtRequest );
194
244
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
@@ -197,7 +247,7 @@ public void testGridPrecision() throws Exception {
197
247
assertLayer (tile , META_LAYER , 4096 , 1 , 14 );
198
248
}
199
249
{
200
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
250
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
201
251
mvtRequest .setJsonEntity ("{\" grid_precision\" : 9 }" );
202
252
final ResponseException ex = expectThrows (ResponseException .class , () -> execute (mvtRequest ));
203
253
assertThat (ex .getResponse ().getStatusLine ().getStatusCode (), Matchers .equalTo (HttpStatus .SC_BAD_REQUEST ));
@@ -206,49 +256,86 @@ public void testGridPrecision() throws Exception {
206
256
207
257
public void testGridType () throws Exception {
208
258
{
209
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
259
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
210
260
mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_type\" : \" point\" }" );
211
261
final VectorTile .Tile tile = execute (mvtRequest );
212
262
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
213
263
assertLayer (tile , HITS_LAYER , 4096 , 33 , 1 );
214
264
assertLayer (tile , AGGS_LAYER , 4096 , 1 , 1 );
215
265
assertLayer (tile , META_LAYER , 4096 , 1 , 14 );
266
+ assertFeatureType (tile , AGGS_LAYER , VectorTile .Tile .GeomType .POINT );
216
267
}
217
268
{
218
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
269
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
219
270
mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_type\" : \" grid\" }" );
220
271
final VectorTile .Tile tile = execute (mvtRequest );
221
272
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
222
273
assertLayer (tile , HITS_LAYER , 4096 , 33 , 1 );
223
274
assertLayer (tile , AGGS_LAYER , 4096 , 1 , 1 );
224
275
assertLayer (tile , META_LAYER , 4096 , 1 , 14 );
276
+ assertFeatureType (tile , AGGS_LAYER , VectorTile .Tile .GeomType .POLYGON );
225
277
}
226
278
{
227
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
279
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
228
280
mvtRequest .setJsonEntity ("{\" grid_type\" : \" invalid_type\" }" );
229
281
final ResponseException ex = expectThrows (ResponseException .class , () -> execute (mvtRequest ));
230
282
assertThat (ex .getResponse ().getStatusLine ().getStatusCode (), Matchers .equalTo (HttpStatus .SC_BAD_REQUEST ));
231
283
}
232
284
}
233
285
286
+ public void testGridTypeURL () throws Exception {
287
+ final Request mvtRequest = new Request (
288
+ getHttpMethod (),
289
+ INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y + "?grid_type=grid"
290
+ );
291
+ mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_type\" : \" point\" }" );
292
+ final VectorTile .Tile tile = execute (mvtRequest );
293
+ assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
294
+ assertLayer (tile , HITS_LAYER , 4096 , 33 , 1 );
295
+ assertLayer (tile , AGGS_LAYER , 4096 , 1 , 1 );
296
+ assertLayer (tile , META_LAYER , 4096 , 1 , 14 );
297
+ assertFeatureType (tile , AGGS_LAYER , VectorTile .Tile .GeomType .POLYGON );
298
+ }
299
+
234
300
public void testNoAggLayer () throws Exception {
235
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
301
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
236
302
mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_precision\" : 0 }" );
237
303
final VectorTile .Tile tile = execute (mvtRequest );
238
304
assertThat (tile .getLayersCount (), Matchers .equalTo (2 ));
239
305
assertLayer (tile , HITS_LAYER , 4096 , 33 , 1 );
240
306
assertLayer (tile , META_LAYER , 4096 , 1 , 9 );
241
307
}
242
308
309
+ public void testNoAggLayerURL () throws Exception {
310
+ final Request mvtRequest = new Request (
311
+ getHttpMethod (),
312
+ INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y + "?grid_precision=" + 0
313
+ );
314
+ mvtRequest .setJsonEntity ("{\" size\" : 100, \" grid_precision\" : 4 }" );
315
+ final VectorTile .Tile tile = execute (mvtRequest );
316
+ assertThat (tile .getLayersCount (), Matchers .equalTo (2 ));
317
+ assertLayer (tile , HITS_LAYER , 4096 , 33 , 1 );
318
+ assertLayer (tile , META_LAYER , 4096 , 1 , 9 );
319
+ }
320
+
243
321
public void testNoHitsLayer () throws Exception {
244
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
322
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
245
323
mvtRequest .setJsonEntity ("{\" size\" : 0 }" );
246
324
final VectorTile .Tile tile = execute (mvtRequest );
247
325
assertThat (tile .getLayersCount (), Matchers .equalTo (2 ));
248
326
assertLayer (tile , AGGS_LAYER , 4096 , 1 , 1 );
249
327
assertLayer (tile , META_LAYER , 4096 , 1 , 13 );
250
328
}
251
329
330
+ public void testNoHitsLayerURL () throws Exception {
331
+ final Request mvtRequest = new Request (getHttpMethod (), INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y + "?size=" + 0 );
332
+ mvtRequest .setJsonEntity ("{\" size\" : 100 }" );
333
+ final VectorTile .Tile tile = execute (mvtRequest );
334
+ assertThat (tile .getLayersCount (), Matchers .equalTo (2 ));
335
+ assertLayer (tile , AGGS_LAYER , 4096 , 1 , 1 );
336
+ assertLayer (tile , META_LAYER , 4096 , 1 , 13 );
337
+ }
338
+
252
339
public void testRuntimeFieldWithSort () throws Exception {
253
340
String runtimeMapping = "\" runtime_mappings\" : {\n "
254
341
+ " \" width\" : {\n "
@@ -259,7 +346,7 @@ public void testRuntimeFieldWithSort() throws Exception {
259
346
+ "}\n " ;
260
347
{
261
348
// desc order, polygon should be the first hit
262
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_ALL + "/_mvt/location/" + z + "/" + x + "/" + y );
349
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_ALL + "/_mvt/location/" + z + "/" + x + "/" + y );
263
350
mvtRequest .setJsonEntity (
264
351
"{\n "
265
352
+ " \" size\" : 100,\n "
@@ -285,7 +372,7 @@ public void testRuntimeFieldWithSort() throws Exception {
285
372
}
286
373
{
287
374
// asc order, polygon should be the last hit
288
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_ALL + "/_mvt/location/" + z + "/" + x + "/" + y );
375
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_ALL + "/_mvt/location/" + z + "/" + x + "/" + y );
289
376
mvtRequest .setJsonEntity (
290
377
"{\n "
291
378
+ " \" size\" : 100,\n "
@@ -312,7 +399,7 @@ public void testRuntimeFieldWithSort() throws Exception {
312
399
}
313
400
314
401
public void testBasicQueryGet () throws Exception {
315
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
402
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_POINTS + "/_mvt/location/" + z + "/" + x + "/" + y );
316
403
mvtRequest .setJsonEntity (
317
404
"{\n "
318
405
+ " \" query\" : {\n "
@@ -332,7 +419,7 @@ public void testBasicQueryGet() throws Exception {
332
419
}
333
420
334
421
public void testBasicShape () throws Exception {
335
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
422
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
336
423
final VectorTile .Tile tile = execute (mvtRequest );
337
424
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
338
425
assertLayer (tile , HITS_LAYER , 4096 , 1 , 1 );
@@ -341,7 +428,7 @@ public void testBasicShape() throws Exception {
341
428
}
342
429
343
430
public void testWithFields () throws Exception {
344
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
431
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
345
432
mvtRequest .setJsonEntity ("{\" fields\" : [\" name\" , \" value1\" ] }" );
346
433
final VectorTile .Tile tile = execute (mvtRequest );
347
434
assertThat (tile .getLayersCount (), Matchers .equalTo (3 ));
@@ -351,7 +438,7 @@ public void testWithFields() throws Exception {
351
438
}
352
439
353
440
public void testMinAgg () throws Exception {
354
- final Request mvtRequest = new Request (HttpGet . METHOD_NAME , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
441
+ final Request mvtRequest = new Request (getHttpMethod () , INDEX_SHAPES + "/_mvt/location/" + z + "/" + x + "/" + y );
355
442
mvtRequest .setJsonEntity (
356
443
"{\n "
357
444
+ " \" aggs\" : {\n "
@@ -370,6 +457,18 @@ public void testMinAgg() throws Exception {
370
457
assertLayer (tile , META_LAYER , 4096 , 1 , 19 );
371
458
}
372
459
460
+ private String getHttpMethod () {
461
+ return random ().nextBoolean () ? HttpGet .METHOD_NAME : HttpPost .METHOD_NAME ;
462
+ }
463
+
464
+ private void assertFeatureType (VectorTile .Tile tile , String name , VectorTile .Tile .GeomType type ) {
465
+ final VectorTile .Tile .Layer layer = getLayer (tile , name );
466
+ for (int i = 0 ; i < layer .getFeaturesCount (); i ++) {
467
+ final VectorTile .Tile .Feature feature = layer .getFeatures (i );
468
+ assertThat (feature .getType (), Matchers .equalTo (type ));
469
+ }
470
+ }
471
+
373
472
private void assertLayer (VectorTile .Tile tile , String name , int extent , int numFeatures , int numTags ) {
374
473
final VectorTile .Tile .Layer layer = getLayer (tile , name );
375
474
assertThat (layer .getExtent (), Matchers .equalTo (extent ));
0 commit comments