15
15
*/
16
16
package org .springframework .data .mongodb .core .geo ;
17
17
18
- import static org .assertj .core .api .Assertions .*;
19
-
20
- import java .io .IOException ;
21
- import java .util .Arrays ;
22
-
18
+ import com .fasterxml .jackson .databind .ObjectMapper ;
23
19
import org .junit .jupiter .api .BeforeEach ;
24
20
import org .junit .jupiter .api .Test ;
25
-
26
21
import org .springframework .data .geo .Point ;
27
22
28
- import com .fasterxml .jackson .core .JsonParseException ;
29
- import com .fasterxml .jackson .databind .JsonMappingException ;
30
- import com .fasterxml .jackson .databind .ObjectMapper ;
23
+ import java .io .IOException ;
24
+ import java .util .Arrays ;
25
+
26
+ import static org .assertj .core .api .Assertions .assertThat ;
31
27
32
28
/**
33
29
* @author Christoph Strobl
30
+ * @author Artyom Muravlev
34
31
*/
35
- public class GeoJsonModuleUnitTests {
32
+ class GeoJsonModuleUnitTests {
36
33
37
34
ObjectMapper mapper ;
38
35
39
36
@ BeforeEach
40
- public void setUp () {
37
+ void setUp () {
41
38
42
39
mapper = new ObjectMapper ();
43
40
mapper .registerModule (new GeoJsonModule ());
44
41
}
45
42
46
43
@ Test // DATAMONGO-1181
47
- public void shouldDeserializeJsonPointCorrectly () throws JsonParseException , JsonMappingException , IOException {
44
+ void shouldDeserializeJsonPointCorrectly () throws IOException {
48
45
49
46
String json = "{ \" type\" : \" Point\" , \" coordinates\" : [10.0, 20.0] }" ;
50
47
51
48
assertThat (mapper .readValue (json , GeoJsonPoint .class )).isEqualTo (new GeoJsonPoint (10D , 20D ));
52
49
}
53
50
54
51
@ Test // DATAMONGO-1181
55
- public void shouldDeserializeGeoJsonLineStringCorrectly ()
56
- throws JsonParseException , JsonMappingException , IOException {
52
+ void shouldDeserializeGeoJsonLineStringCorrectly ()
53
+ throws IOException {
57
54
58
55
String json = "{ \" type\" : \" LineString\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
59
56
@@ -62,8 +59,8 @@ public void shouldDeserializeGeoJsonLineStringCorrectly()
62
59
}
63
60
64
61
@ Test // DATAMONGO-1181
65
- public void shouldDeserializeGeoJsonMultiPointCorrectly ()
66
- throws JsonParseException , JsonMappingException , IOException {
62
+ void shouldDeserializeGeoJsonMultiPointCorrectly ()
63
+ throws IOException {
67
64
68
65
String json = "{ \" type\" : \" MultiPoint\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
69
66
@@ -73,8 +70,8 @@ public void shouldDeserializeGeoJsonMultiPointCorrectly()
73
70
74
71
@ Test // DATAMONGO-1181
75
72
@ SuppressWarnings ("unchecked" )
76
- public void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77
- throws JsonParseException , JsonMappingException , IOException {
73
+ void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
74
+ throws IOException {
78
75
79
76
String json = "{ \" type\" : \" MultiLineString\" , \" coordinates\" : [ [ [10.0, 20.0], [30.0, 40.0] ], [ [50.0, 60.0] , [70.0, 80.0] ] ]}" ;
80
77
@@ -83,7 +80,7 @@ public void shouldDeserializeGeoJsonMultiLineStringCorrectly()
83
80
}
84
81
85
82
@ Test // DATAMONGO-1181
86
- public void shouldDeserializeGeoJsonPolygonCorrectly () throws JsonParseException , JsonMappingException , IOException {
83
+ void shouldDeserializeGeoJsonPolygonCorrectly () throws IOException {
87
84
88
85
String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ]}" ;
89
86
@@ -92,8 +89,8 @@ public void shouldDeserializeGeoJsonPolygonCorrectly() throws JsonParseException
92
89
}
93
90
94
91
@ Test // DATAMONGO-1181
95
- public void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96
- throws JsonParseException , JsonMappingException , IOException {
92
+ void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
93
+ throws IOException {
97
94
98
95
String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : ["
99
96
+ "[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],"
@@ -110,4 +107,74 @@ public void shouldDeserializeGeoJsonMultiPolygonCorrectly()
110
107
new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))));
111
108
112
109
}
110
+
111
+ @ Test // GH-4950
112
+ void shouldSerializeJsonPointCorrectly () throws IOException {
113
+
114
+ String json = "{\" type\" :\" Point\" ,\" coordinates\" :[10.0,20.0]}" ;
115
+
116
+ assertThat (mapper .writeValueAsString (new GeoJsonPoint (10D , 20D ))).isEqualTo (json );
117
+ }
118
+
119
+ @ Test // GH-4950
120
+ void shouldSerializeGeoJsonLineStringCorrectly ()
121
+ throws IOException {
122
+
123
+ String json = "{\" type\" :\" LineString\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
124
+
125
+ assertThat (mapper .writeValueAsString (new GeoJsonLineString (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
126
+ .isEqualTo (json );
127
+ }
128
+
129
+ @ Test // GH-4950
130
+ void shouldSerializeGeoJsonMultiPointCorrectly ()
131
+ throws IOException {
132
+
133
+ String json = "{\" type\" :\" MultiPoint\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
134
+
135
+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPoint (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
136
+ .isEqualTo (json );
137
+ }
138
+
139
+ @ Test // GH-4950
140
+ @ SuppressWarnings ("unchecked" )
141
+ void shouldSerializeGeoJsonMultiLineStringCorrectly ()
142
+ throws IOException {
143
+
144
+ String json = "{\" type\" :\" MultiLineString\" ,\" coordinates\" :[[[10.0,20.0],[30.0,40.0]],[[50.0,60.0],[70.0,80.0]]]}" ;
145
+
146
+ assertThat (mapper .writeValueAsString (new GeoJsonMultiLineString (
147
+ Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 )), Arrays .asList (new Point (50 , 60 ), new Point (70 , 80 )))))
148
+ .isEqualTo (json );
149
+ }
150
+
151
+ @ Test // GH-4950
152
+ void shouldSerializeGeoJsonPolygonCorrectly () throws IOException {
153
+
154
+ String json = "{\" type\" :\" Polygon\" ,\" coordinates\" :[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}" ;
155
+
156
+ assertThat (mapper .writeValueAsString (new GeoJsonPolygon (
157
+ Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ), new Point (100 , 0 )))))
158
+ .isEqualTo (json );
159
+ }
160
+
161
+ @ Test // GH-4950
162
+ void shouldSerializeGeoJsonMultiPolygonCorrectly ()
163
+ throws IOException {
164
+
165
+ String json ="{\" type\" :\" MultiPolygon\" ,\" coordinates\" :["
166
+ +"[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]],"
167
+ +"[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]],"
168
+ +"[[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]" //
169
+ +"]}" ;
170
+
171
+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPolygon (Arrays .asList (
172
+ new GeoJsonPolygon (Arrays .asList (new Point (102 , 2 ), new Point (103 , 2 ), new Point (103 , 3 ), new Point (102 , 3 ),
173
+ new Point (102 , 2 ))),
174
+ new GeoJsonPolygon (Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ),
175
+ new Point (100 , 0 ))),
176
+ new GeoJsonPolygon (Arrays .asList (new Point (100.2 , 0.2 ), new Point (100.8 , 0.2 ), new Point (100.8 , 0.8 ),
177
+ new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))))).isEqualTo (json );
178
+
179
+ }
113
180
}
0 commit comments