@@ -62,7 +62,7 @@ protected void doAssertLuceneQuery(GeoPolygonQueryBuilder queryBuilder, Query qu
6262 List <GeoPoint > points = queryBuilder .points ();
6363 double [] lats = new double [points .size ()];
6464 double [] lons = new double [points .size ()];
65- for (int i =0 ; i < points .size (); i ++) {
65+ for (int i = 0 ; i < points .size (); i ++) {
6666 lats [i ] = points .get (i ).getLat ();
6767 lons [i ] = points .get (i ).getLon ();
6868 }
@@ -73,6 +73,34 @@ protected void doAssertLuceneQuery(GeoPolygonQueryBuilder queryBuilder, Query qu
7373 }
7474 }
7575
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+
76104 private static List <GeoPoint > randomPolygon () {
77105 ShapeBuilder <?, ?, ?> shapeBuilder = null ;
78106 // This is a temporary fix because sometimes the RandomShapeGenerator
@@ -97,7 +125,7 @@ public void testNullFieldName() {
97125
98126 public void testEmptyPolygon () {
99127 IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
100- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , Collections .emptyList ()));
128+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , Collections .emptyList ()));
101129 assertEquals ("polygon must not be null or empty" , e .getMessage ());
102130
103131 e = expectThrows (IllegalArgumentException .class , () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , null ));
@@ -110,7 +138,7 @@ public void testInvalidClosedPolygon() {
110138 points .add (new GeoPoint (90 , 90 ));
111139 points .add (new GeoPoint (0 , 90 ));
112140 IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
113- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
141+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
114142 assertEquals ("too few points defined for geo_polygon query" , e .getMessage ());
115143 }
116144
@@ -119,91 +147,96 @@ public void testInvalidOpenPolygon() {
119147 points .add (new GeoPoint (0 , 90 ));
120148 points .add (new GeoPoint (90 , 90 ));
121149 IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
122- () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
150+ () -> new GeoPolygonQueryBuilder (GEO_POINT_FIELD_NAME , points ));
123151 assertEquals ("too few points defined for geo_polygon query" , e .getMessage ());
124152 }
125153
126154 public void testParsingAndToQueryParsingExceptions () throws IOException {
127155 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"
133161 };
134162 for (String brokenFile : brokenFiles ) {
135163 String query = copyToStringFromClasspath (brokenFile );
136164 expectThrows (ParsingException .class , () -> parseQuery (query ));
137165 }
166+ assertDeprecationWarning ();
138167 }
139168
140169 public void testParsingAndToQuery1 () throws IOException {
141170 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 " ;
152181 assertGeoPolygonQuery (query );
182+ assertDeprecationWarning ();
153183 }
154184
155185 public void testParsingAndToQuery2 () throws IOException {
156186 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 " ;
176206 assertGeoPolygonQuery (query );
207+ assertDeprecationWarning ();
177208 }
178209
179210 public void testParsingAndToQuery3 () throws IOException {
180211 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 " ;
191222 assertGeoPolygonQuery (query );
223+ assertDeprecationWarning ();
192224 }
193225
194226 public void testParsingAndToQuery4 () throws IOException {
195227 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 " ;
206238 assertGeoPolygonQuery (query );
239+ assertDeprecationWarning ();
207240 }
208241
209242 private void assertGeoPolygonQuery (String query ) throws IOException {
@@ -214,7 +247,7 @@ private void assertGeoPolygonQuery(String query) throws IOException {
214247
215248 public void testFromJson () throws IOException {
216249 String json =
217- "{\n " +
250+ "{\n " +
218251 " \" geo_polygon\" : {\n " +
219252 " \" person.location\" : {\n " +
220253 " \" 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 {
227260 GeoPolygonQueryBuilder parsed = (GeoPolygonQueryBuilder ) parseQuery (json );
228261 checkGeneratedJson (json , parsed );
229262 assertEquals (json , 4 , parsed .points ().size ());
263+ assertDeprecationWarning ();
230264 }
231265
232266 public void testIgnoreUnmapped () throws IOException {
@@ -274,5 +308,6 @@ public void testPointValidation() throws IOException {
274308
275309 QueryShardException e2 = expectThrows (QueryShardException .class , () -> parseQuery (queryInvalidLon ).toQuery (context ));
276310 assertThat (e2 .getMessage (), containsString ("illegal longitude value [-190.0] for [geo_polygon]" ));
311+ assertDeprecationWarning ();
277312 }
278313}
0 commit comments