@@ -62,7 +62,7 @@ protected void doAssertLuceneQuery(GeoPolygonQueryBuilder queryBuilder, Query qu
62
62
List <GeoPoint > points = queryBuilder .points ();
63
63
double [] lats = new double [points .size ()];
64
64
double [] lons = new double [points .size ()];
65
- for (int i =0 ; i < points .size (); i ++) {
65
+ for (int i = 0 ; i < points .size (); i ++) {
66
66
lats [i ] = points .get (i ).getLat ();
67
67
lons [i ] = points .get (i ).getLon ();
68
68
}
@@ -73,6 +73,34 @@ protected void doAssertLuceneQuery(GeoPolygonQueryBuilder queryBuilder, Query qu
73
73
}
74
74
}
75
75
76
+ @ Override
77
+ public void testUnknownField () throws IOException {
78
+ super .testUnknownField ();
79
+ assertDeprecationWarning ();
80
+ }
81
+
82
+ @ Override
83
+ public void testUnknownObjectException () throws IOException {
84
+ super .testUnknownObjectException ();
85
+ assertDeprecationWarning ();
86
+ }
87
+
88
+ @ Override
89
+ public void testFromXContent () throws IOException {
90
+ super .testFromXContent ();
91
+ assertDeprecationWarning ();
92
+ }
93
+
94
+ @ Override
95
+ public void testValidOutput () throws IOException {
96
+ super .testValidOutput ();
97
+ assertDeprecationWarning ();
98
+ }
99
+
100
+ private void assertDeprecationWarning () {
101
+ assertWarnings ("Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]" );
102
+ }
103
+
76
104
private static List <GeoPoint > randomPolygon () {
77
105
ShapeBuilder <?, ?, ?> shapeBuilder = null ;
78
106
// This is a temporary fix because sometimes the RandomShapeGenerator
@@ -97,7 +125,7 @@ public void testNullFieldName() {
97
125
98
126
public void testEmptyPolygon () {
99
127
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
100
- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , Collections .emptyList ()));
128
+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , Collections .emptyList ()));
101
129
assertEquals ("polygon must not be null or empty" , e .getMessage ());
102
130
103
131
e = expectThrows (IllegalArgumentException .class , () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , null ));
@@ -110,7 +138,7 @@ public void testInvalidClosedPolygon() {
110
138
points .add (new GeoPoint (90 , 90 ));
111
139
points .add (new GeoPoint (0 , 90 ));
112
140
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
113
- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
141
+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
114
142
assertEquals ("too few points defined for geo_polygon query" , e .getMessage ());
115
143
}
116
144
@@ -119,91 +147,96 @@ public void testInvalidOpenPolygon() {
119
147
points .add (new GeoPoint (0 , 90 ));
120
148
points .add (new GeoPoint (90 , 90 ));
121
149
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
122
- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
150
+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
123
151
assertEquals ("too few points defined for geo_polygon query" , e .getMessage ());
124
152
}
125
153
126
154
public void testParsingAndToQueryParsingExceptions () throws IOException {
127
155
String [] brokenFiles = new String []{
128
- "/org/elasticsearch/index/query/geo_polygon_exception_1.json" ,
129
- "/org/elasticsearch/index/query/geo_polygon_exception_2.json" ,
130
- "/org/elasticsearch/index/query/geo_polygon_exception_3.json" ,
131
- "/org/elasticsearch/index/query/geo_polygon_exception_4.json" ,
132
- "/org/elasticsearch/index/query/geo_polygon_exception_5.json"
156
+ "/org/elasticsearch/index/query/geo_polygon_exception_1.json" ,
157
+ "/org/elasticsearch/index/query/geo_polygon_exception_2.json" ,
158
+ "/org/elasticsearch/index/query/geo_polygon_exception_3.json" ,
159
+ "/org/elasticsearch/index/query/geo_polygon_exception_4.json" ,
160
+ "/org/elasticsearch/index/query/geo_polygon_exception_5.json"
133
161
};
134
162
for (String brokenFile : brokenFiles ) {
135
163
String query = copyToStringFromClasspath (brokenFile );
136
164
expectThrows (ParsingException .class , () -> parseQuery (query ));
137
165
}
166
+ assertDeprecationWarning ();
138
167
}
139
168
140
169
public void testParsingAndToQuery1 () throws IOException {
141
170
String query = "{\n " +
142
- " \" geo_polygon\" :{\n " +
143
- " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
144
- " \" points\" :[\n " +
145
- " [-70, 40],\n " +
146
- " [-80, 30],\n " +
147
- " [-90, 20]\n " +
148
- " ]\n " +
149
- " }\n " +
150
- " }\n " +
151
- "}\n " ;
171
+ " \" geo_polygon\" :{\n " +
172
+ " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
173
+ " \" points\" :[\n " +
174
+ " [-70, 40],\n " +
175
+ " [-80, 30],\n " +
176
+ " [-90, 20]\n " +
177
+ " ]\n " +
178
+ " }\n " +
179
+ " }\n " +
180
+ "}\n " ;
152
181
assertGeoPolygonQuery (query );
182
+ assertDeprecationWarning ();
153
183
}
154
184
155
185
public void testParsingAndToQuery2 () throws IOException {
156
186
String query = "{\n " +
157
- " \" geo_polygon\" :{\n " +
158
- " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
159
- " \" points\" :[\n " +
160
- " {\n " +
161
- " \" lat\" :40,\n " +
162
- " \" lon\" :-70\n " +
163
- " },\n " +
164
- " {\n " +
165
- " \" lat\" :30,\n " +
166
- " \" lon\" :-80\n " +
167
- " },\n " +
168
- " {\n " +
169
- " \" lat\" :20,\n " +
170
- " \" lon\" :-90\n " +
171
- " }\n " +
172
- " ]\n " +
173
- " }\n " +
174
- " }\n " +
175
- "}\n " ;
187
+ " \" geo_polygon\" :{\n " +
188
+ " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
189
+ " \" points\" :[\n " +
190
+ " {\n " +
191
+ " \" lat\" :40,\n " +
192
+ " \" lon\" :-70\n " +
193
+ " },\n " +
194
+ " {\n " +
195
+ " \" lat\" :30,\n " +
196
+ " \" lon\" :-80\n " +
197
+ " },\n " +
198
+ " {\n " +
199
+ " \" lat\" :20,\n " +
200
+ " \" lon\" :-90\n " +
201
+ " }\n " +
202
+ " ]\n " +
203
+ " }\n " +
204
+ " }\n " +
205
+ "}\n " ;
176
206
assertGeoPolygonQuery (query );
207
+ assertDeprecationWarning ();
177
208
}
178
209
179
210
public void testParsingAndToQuery3 () throws IOException {
180
211
String query = "{\n " +
181
- " \" geo_polygon\" :{\n " +
182
- " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
183
- " \" points\" :[\n " +
184
- " \" 40, -70\" ,\n " +
185
- " \" 30, -80\" ,\n " +
186
- " \" 20, -90\" \n " +
187
- " ]\n " +
188
- " }\n " +
189
- " }\n " +
190
- "}\n " ;
212
+ " \" geo_polygon\" :{\n " +
213
+ " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
214
+ " \" points\" :[\n " +
215
+ " \" 40, -70\" ,\n " +
216
+ " \" 30, -80\" ,\n " +
217
+ " \" 20, -90\" \n " +
218
+ " ]\n " +
219
+ " }\n " +
220
+ " }\n " +
221
+ "}\n " ;
191
222
assertGeoPolygonQuery (query );
223
+ assertDeprecationWarning ();
192
224
}
193
225
194
226
public void testParsingAndToQuery4 () throws IOException {
195
227
String query = "{\n " +
196
- " \" geo_polygon\" :{\n " +
197
- " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
198
- " \" points\" :[\n " +
199
- " \" drn5x1g8cu2y\" ,\n " +
200
- " \" 30, -80\" ,\n " +
201
- " \" 20, -90\" \n " +
202
- " ]\n " +
203
- " }\n " +
204
- " }\n " +
205
- "}\n " ;
228
+ " \" geo_polygon\" :{\n " +
229
+ " \" " + GEO_POINT_FIELD_NAME + "\" :{\n " +
230
+ " \" points\" :[\n " +
231
+ " \" drn5x1g8cu2y\" ,\n " +
232
+ " \" 30, -80\" ,\n " +
233
+ " \" 20, -90\" \n " +
234
+ " ]\n " +
235
+ " }\n " +
236
+ " }\n " +
237
+ "}\n " ;
206
238
assertGeoPolygonQuery (query );
239
+ assertDeprecationWarning ();
207
240
}
208
241
209
242
private void assertGeoPolygonQuery (String query ) throws IOException {
@@ -214,7 +247,7 @@ private void assertGeoPolygonQuery(String query) throws IOException {
214
247
215
248
public void testFromJson () throws IOException {
216
249
String json =
217
- "{\n " +
250
+ "{\n " +
218
251
" \" geo_polygon\" : {\n " +
219
252
" \" person.location\" : {\n " +
220
253
" \" points\" : [ [ -70.0, 40.0 ], [ -80.0, 30.0 ], [ -90.0, 20.0 ], [ -70.0, 40.0 ] ]\n " +
@@ -227,6 +260,7 @@ public void testFromJson() throws IOException {
227
260
GeoPolygonQueryBuilder parsed = (GeoPolygonQueryBuilder ) parseQuery (json );
228
261
checkGeneratedJson (json , parsed );
229
262
assertEquals (json , 4 , parsed .points ().size ());
263
+ assertDeprecationWarning ();
230
264
}
231
265
232
266
public void testIgnoreUnmapped () throws IOException {
@@ -274,5 +308,6 @@ public void testPointValidation() throws IOException {
274
308
275
309
QueryShardException e2 = expectThrows (QueryShardException .class , () -> parseQuery (queryInvalidLon ).toQuery (context ));
276
310
assertThat (e2 .getMessage (), containsString ("illegal longitude value [-190.0] for [geo_polygon]" ));
311
+ assertDeprecationWarning ();
277
312
}
278
313
}
0 commit comments