Skip to content

Commit

Permalink
Tests: Add checks to GeoDistanceQueryBuilderTests (#34273)
Browse files Browse the repository at this point in the history
Adds checks for parsed geo distance query. It is a bit hack-ish since it
compares with query's toString() output, but it is better than no
checks. The parsed query itself has default visibility, so we cannot
access it here unless we move the test to org.apache.lucene.document
package.

Fixes #34043
  • Loading branch information
imotov committed Oct 23, 2018
1 parent 8e155b8 commit 123f784
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testParsingAndToQuery1() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery2() throws IOException {
Expand All @@ -166,7 +166,7 @@ public void testParsingAndToQuery2() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":[-70, 40]\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery3() throws IOException {
Expand All @@ -176,7 +176,7 @@ public void testParsingAndToQuery3() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":\"40, -70\"\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery4() throws IOException {
Expand All @@ -186,7 +186,8 @@ public void testParsingAndToQuery4() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":\"drn5x1g8cu2y\"\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
GeoPoint geoPoint = GeoPoint.fromGeohash("drn5x1g8cu2y");
assertGeoDistanceRangeQuery(query, geoPoint.getLat(), geoPoint.getLon(), 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery5() throws IOException {
Expand All @@ -200,7 +201,7 @@ public void testParsingAndToQuery5() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery6() throws IOException {
Expand All @@ -214,7 +215,7 @@ public void testParsingAndToQuery6() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery7() throws IOException {
Expand All @@ -227,7 +228,7 @@ public void testParsingAndToQuery7() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 0.012, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.DEFAULT);
}

public void testParsingAndToQuery8() throws IOException {
Expand All @@ -240,7 +241,7 @@ public void testParsingAndToQuery8() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.KILOMETERS);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.DEFAULT);
}

public void testParsingAndToQuery9() throws IOException {
Expand All @@ -254,7 +255,7 @@ public void testParsingAndToQuery9() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery10() throws IOException {
Expand All @@ -268,7 +269,7 @@ public void testParsingAndToQuery10() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery11() throws IOException {
Expand All @@ -281,7 +282,7 @@ public void testParsingAndToQuery11() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery12() throws IOException {
Expand All @@ -295,13 +296,16 @@ public void testParsingAndToQuery12() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

private void assertGeoDistanceRangeQuery(String query, double lat, double lon, double distance, DistanceUnit distanceUnit)
throws IOException {
parseQuery(query).toQuery(createShardContext());
// TODO: what can we check? See https://github.com/elastic/elasticsearch/issues/34043
Query parsedQuery = parseQuery(query).toQuery(createShardContext());
// The parsedQuery contains IndexOrDocValuesQuery, which wraps LatLonPointDistanceQuery which in turn has default visibility,
// so we cannot access its fields directly to check and have to use toString() here instead.
assertEquals(parsedQuery.toString(),
"mapped_geo_point:" + lat + "," + lon + " +/- " + distanceUnit.toMeters(distance) + " meters");
}

public void testFromJson() throws IOException {
Expand Down

0 comments on commit 123f784

Please sign in to comment.