|
1 | 1 | /*
|
2 |
| - * Copyright 2015 the original author or authors. |
| 2 | + * Copyright 2015-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -73,11 +73,18 @@ public class GeoJsonConverterUnitTests {
|
73 | 73 | static final Point POINT_2 = new Point(100, 100);
|
74 | 74 | static final Point POINT_3 = new Point(0, 100);
|
75 | 75 |
|
| 76 | + static final Point INNER_POINT_0 = new Point(10, 10); |
| 77 | + static final Point INNER_POINT_1 = new Point(90, 10); |
| 78 | + static final Point INNER_POINT_2 = new Point(90, 90); |
| 79 | + static final Point INNER_POINT_3 = new Point(10, 90); |
| 80 | + |
76 | 81 | static final GeoJsonMultiPoint MULTI_POINT = new GeoJsonMultiPoint(POINT_0, POINT_2, POINT_3);
|
77 | 82 | static final GeoJsonLineString LINE_STRING = new GeoJsonLineString(POINT_0, POINT_1, POINT_2);
|
78 | 83 | @SuppressWarnings("unchecked") static final GeoJsonMultiLineString MULTI_LINE_STRING = new GeoJsonMultiLineString(
|
79 | 84 | Arrays.asList(POINT_0, POINT_1, POINT_2), Arrays.asList(POINT_3, POINT_0));
|
80 | 85 | static final GeoJsonPolygon POLYGON = new GeoJsonPolygon(POINT_0, POINT_1, POINT_2, POINT_3, POINT_0);
|
| 86 | + static final GeoJsonPolygon POLYGON_WITH_2_RINGS = POLYGON.withInnerRing(INNER_POINT_0, INNER_POINT_1, INNER_POINT_2, |
| 87 | + INNER_POINT_3, INNER_POINT_0); |
81 | 88 | static final GeoJsonMultiPolygon MULTI_POLYGON = new GeoJsonMultiPolygon(Arrays.asList(POLYGON));
|
82 | 89 | static final GeoJsonGeometryCollection GEOMETRY_COLLECTION = new GeoJsonGeometryCollection(
|
83 | 90 | Arrays.<GeoJson<?>> asList(SINGLE_POINT, POLYGON));
|
@@ -114,12 +121,28 @@ public class GeoJsonConverterUnitTests {
|
114 | 121 | .add(new BasicDbListBuilder().add(POINT_3.getX()).add(POINT_3.getY()).get()) //
|
115 | 122 | .add(new BasicDbListBuilder().add(POINT_0.getX()).add(POINT_0.getY()).get()) //
|
116 | 123 | .get();
|
| 124 | + |
| 125 | + static final BasicDBList POLYGON_INNER_CORDS = new BasicDbListBuilder() // |
| 126 | + .add(new BasicDbListBuilder().add(INNER_POINT_0.getX()).add(INNER_POINT_0.getY()).get()) // |
| 127 | + .add(new BasicDbListBuilder().add(INNER_POINT_1.getX()).add(INNER_POINT_1.getY()).get()) // |
| 128 | + .add(new BasicDbListBuilder().add(INNER_POINT_2.getX()).add(INNER_POINT_2.getY()).get()) // |
| 129 | + .add(new BasicDbListBuilder().add(INNER_POINT_3.getX()).add(INNER_POINT_3.getY()).get()) // |
| 130 | + .add(new BasicDbListBuilder().add(INNER_POINT_0.getX()).add(INNER_POINT_0.getY()).get()) // |
| 131 | + .get(); |
| 132 | + |
117 | 133 | static final BasicDBList POLYGON_CORDS = new BasicDbListBuilder().add(POLYGON_OUTER_CORDS).get();
|
118 | 134 | static final DBObject POLYGON_DBO = new BasicDBObjectBuilder() //
|
119 | 135 | .add("type", "Polygon") //
|
120 | 136 | .add("coordinates", POLYGON_CORDS) //
|
121 | 137 | .get();
|
122 | 138 |
|
| 139 | + static final BasicDBList POLYGON_WITH_2_RINGS_CORDS = new BasicDbListBuilder().add(POLYGON_OUTER_CORDS) |
| 140 | + .add(POLYGON_INNER_CORDS).get(); |
| 141 | + static final DBObject POLYGON_WITH_2_RINGS_DBO = new BasicDBObjectBuilder() // |
| 142 | + .add("type", "Polygon") // |
| 143 | + .add("coordinates", POLYGON_WITH_2_RINGS_CORDS) // |
| 144 | + .get(); |
| 145 | + |
123 | 146 | // LineString
|
124 | 147 | static final BasicDBList LINE_STRING_CORDS_0 = new BasicDbListBuilder() //
|
125 | 148 | .add(new BasicDbListBuilder().add(POINT_0.getX()).add(POINT_0.getY()).get()) //
|
@@ -190,6 +213,14 @@ public void shouldThrowExceptionWhenTypeDoesNotMatchPolygon() {
|
190 | 213 | converter.convert(new BasicDBObject("type", "YouDontKonwMe"));
|
191 | 214 | }
|
192 | 215 |
|
| 216 | + /** |
| 217 | + * @see DATAMONGO-1399 |
| 218 | + */ |
| 219 | + @Test |
| 220 | + public void shouldConvertDboWithMultipleRingsCorrectly() { |
| 221 | + assertThat(converter.convert(POLYGON_WITH_2_RINGS_DBO), equalTo(POLYGON_WITH_2_RINGS)); |
| 222 | + } |
| 223 | + |
193 | 224 | }
|
194 | 225 |
|
195 | 226 | /**
|
@@ -446,5 +477,13 @@ public void shouldConvertGeoJsonMultiPolygonCorrectly() {
|
446 | 477 | public void shouldConvertGeometryCollectionCorrectly() {
|
447 | 478 | assertThat(converter.convert(GEOMETRY_COLLECTION), equalTo(GEOMETRY_COLLECTION_DBO));
|
448 | 479 | }
|
| 480 | + |
| 481 | + /** |
| 482 | + * @see DATAMONGO-1399 |
| 483 | + */ |
| 484 | + @Test |
| 485 | + public void shouldConvertGeoJsonPolygonWithMultipleRingsCorrectly() { |
| 486 | + assertThat(converter.convert(POLYGON_WITH_2_RINGS), equalTo(POLYGON_WITH_2_RINGS_DBO)); |
| 487 | + } |
449 | 488 | }
|
450 | 489 | }
|
0 commit comments