|
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.
|
@@ -71,11 +71,18 @@ public class GeoJsonConverterUnitTests {
|
71 | 71 | static final Point POINT_2 = new Point(100, 100);
|
72 | 72 | static final Point POINT_3 = new Point(0, 100);
|
73 | 73 |
|
| 74 | + static final Point INNER_POINT_0 = new Point(10, 10); |
| 75 | + static final Point INNER_POINT_1 = new Point(90, 10); |
| 76 | + static final Point INNER_POINT_2 = new Point(90, 90); |
| 77 | + static final Point INNER_POINT_3 = new Point(10, 90); |
| 78 | + |
74 | 79 | static final GeoJsonMultiPoint MULTI_POINT = new GeoJsonMultiPoint(POINT_0, POINT_2, POINT_3);
|
75 | 80 | static final GeoJsonLineString LINE_STRING = new GeoJsonLineString(POINT_0, POINT_1, POINT_2);
|
76 | 81 | @SuppressWarnings("unchecked") static final GeoJsonMultiLineString MULTI_LINE_STRING = new GeoJsonMultiLineString(
|
77 | 82 | Arrays.asList(POINT_0, POINT_1, POINT_2), Arrays.asList(POINT_3, POINT_0));
|
78 | 83 | static final GeoJsonPolygon POLYGON = new GeoJsonPolygon(POINT_0, POINT_1, POINT_2, POINT_3, POINT_0);
|
| 84 | + static final GeoJsonPolygon POLYGON_WITH_2_RINGS = POLYGON.withInnerRing(INNER_POINT_0, INNER_POINT_1, INNER_POINT_2, |
| 85 | + INNER_POINT_3, INNER_POINT_0); |
79 | 86 | static final GeoJsonMultiPolygon MULTI_POLYGON = new GeoJsonMultiPolygon(Arrays.asList(POLYGON));
|
80 | 87 | static final GeoJsonGeometryCollection GEOMETRY_COLLECTION = new GeoJsonGeometryCollection(
|
81 | 88 | Arrays.<GeoJson<?>> asList(SINGLE_POINT, POLYGON));
|
@@ -110,11 +117,26 @@ public class GeoJsonConverterUnitTests {
|
110 | 117 | .add(new BasicDbListBuilder().add(POINT_3.getX()).add(POINT_3.getY()).get()) //
|
111 | 118 | .add(new BasicDbListBuilder().add(POINT_0.getX()).add(POINT_0.getY()).get()) //
|
112 | 119 | .get();
|
| 120 | + |
| 121 | + static final BasicDBList POLYGON_INNER_CORDS = new BasicDbListBuilder() // |
| 122 | + .add(new BasicDbListBuilder().add(INNER_POINT_0.getX()).add(INNER_POINT_0.getY()).get()) // |
| 123 | + .add(new BasicDbListBuilder().add(INNER_POINT_1.getX()).add(INNER_POINT_1.getY()).get()) // |
| 124 | + .add(new BasicDbListBuilder().add(INNER_POINT_2.getX()).add(INNER_POINT_2.getY()).get()) // |
| 125 | + .add(new BasicDbListBuilder().add(INNER_POINT_3.getX()).add(INNER_POINT_3.getY()).get()) // |
| 126 | + .add(new BasicDbListBuilder().add(INNER_POINT_0.getX()).add(INNER_POINT_0.getY()).get()) // |
| 127 | + .get(); |
| 128 | + |
113 | 129 | static final BasicDBList POLYGON_CORDS = new BasicDbListBuilder().add(POLYGON_OUTER_CORDS).get();
|
114 | 130 | static final Document POLYGON_DBO = new Document() //
|
115 | 131 | .append("type", "Polygon") //
|
116 | 132 | .append("coordinates", POLYGON_CORDS); //
|
117 | 133 |
|
| 134 | + static final BasicDBList POLYGON_WITH_2_RINGS_CORDS = new BasicDbListBuilder().add(POLYGON_OUTER_CORDS) |
| 135 | + .add(POLYGON_INNER_CORDS).get(); |
| 136 | + static final Document POLYGON_WITH_2_RINGS_DBO = new Document() // |
| 137 | + .append("type", "Polygon") // |
| 138 | + .append("coordinates", POLYGON_WITH_2_RINGS_CORDS); |
| 139 | + |
118 | 140 | // LineString
|
119 | 141 | static final BasicDBList LINE_STRING_CORDS_0 = new BasicDbListBuilder() //
|
120 | 142 | .add(new BasicDbListBuilder().add(POINT_0.getX()).add(POINT_0.getY()).get()) //
|
@@ -185,6 +207,14 @@ public void shouldThrowExceptionWhenTypeDoesNotMatchPolygon() {
|
185 | 207 | converter.convert(new Document("type", "YouDontKonwMe"));
|
186 | 208 | }
|
187 | 209 |
|
| 210 | + /** |
| 211 | + * @see DATAMONGO-1399 |
| 212 | + */ |
| 213 | + @Test |
| 214 | + public void shouldConvertDboWithMultipleRingsCorrectly() { |
| 215 | + assertThat(converter.convert(POLYGON_WITH_2_RINGS_DBO), equalTo(POLYGON_WITH_2_RINGS)); |
| 216 | + } |
| 217 | + |
188 | 218 | }
|
189 | 219 |
|
190 | 220 | /**
|
@@ -441,5 +471,13 @@ public void shouldConvertGeoJsonMultiPolygonCorrectly() {
|
441 | 471 | public void shouldConvertGeometryCollectionCorrectly() {
|
442 | 472 | assertThat(converter.convert(GEOMETRY_COLLECTION), equalTo(GEOMETRY_COLLECTION_DBO));
|
443 | 473 | }
|
| 474 | + |
| 475 | + /** |
| 476 | + * @see DATAMONGO-1399 |
| 477 | + */ |
| 478 | + @Test |
| 479 | + public void shouldConvertGeoJsonPolygonWithMultipleRingsCorrectly() { |
| 480 | + assertThat(converter.convert(POLYGON_WITH_2_RINGS), equalTo(POLYGON_WITH_2_RINGS_DBO)); |
| 481 | + } |
444 | 482 | }
|
445 | 483 | }
|
0 commit comments