|
@@ -31,9 +31,10 @@ import static org.hamcrest.CoreMatchers.containsString;
|
|
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
|
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
|
|
|
|
|
+@SuppressWarnings("checkstyle:MissingJavadocMethod")
|
|
|
public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBoundingBoxQueryBuilder> {
|
|
|
/** Randomly generate either NaN or one of the two infinity values. */
|
|
|
- private static Double[] brokenDoubles = { Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY };
|
|
|
+ private static final Double[] brokenDoubles = { Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY };
|
|
|
|
|
|
@Override
|
|
|
protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() {
|
|
@@ -117,11 +118,9 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
PointTester[] testers = { new TopTester(), new LeftTester(), new BottomTester(), new RightTester() };
|
|
|
|
|
|
for (PointTester tester : testers) {
|
|
|
- QueryValidationException except = null;
|
|
|
-
|
|
|
GeoBoundingBoxQueryBuilder builder = createTestQueryBuilder();
|
|
|
tester.invalidateCoordinate(builder.setValidationMethod(GeoValidationMethod.COERCE), false);
|
|
|
- except = builder.checkLatLon();
|
|
|
+ QueryValidationException except = builder.checkLatLon();
|
|
|
assertNull(
|
|
|
"validation w/ coerce should ignore invalid "
|
|
|
+ tester.getClass().getName()
|
|
@@ -237,15 +236,15 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public abstract class PointTester {
|
|
|
- private double brokenCoordinate = randomFrom(brokenDoubles);
|
|
|
- private double invalidCoordinate;
|
|
|
+ private abstract static class PointTester {
|
|
|
+ private final double brokenCoordinate = randomFrom(brokenDoubles);
|
|
|
+ private final double invalidCoordinate;
|
|
|
|
|
|
- public PointTester(double invalidCoodinate) {
|
|
|
+ private PointTester(double invalidCoodinate) {
|
|
|
this.invalidCoordinate = invalidCoodinate;
|
|
|
}
|
|
|
|
|
|
- public void invalidateCoordinate(GeoBoundingBoxQueryBuilder qb, boolean useBrokenDouble) {
|
|
|
+ private void invalidateCoordinate(GeoBoundingBoxQueryBuilder qb, boolean useBrokenDouble) {
|
|
|
if (useBrokenDouble) {
|
|
|
fillIn(brokenCoordinate, qb);
|
|
|
} else {
|
|
@@ -256,8 +255,8 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
protected abstract void fillIn(double fillIn, GeoBoundingBoxQueryBuilder qb);
|
|
|
}
|
|
|
|
|
|
- public class TopTester extends PointTester {
|
|
|
- public TopTester() {
|
|
|
+ private static class TopTester extends PointTester {
|
|
|
+ private TopTester() {
|
|
|
super(randomDoubleBetween(GeoUtils.MAX_LAT, Double.MAX_VALUE, false));
|
|
|
}
|
|
|
|
|
@@ -267,8 +266,8 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class LeftTester extends PointTester {
|
|
|
- public LeftTester() {
|
|
|
+ private static class LeftTester extends PointTester {
|
|
|
+ private LeftTester() {
|
|
|
super(randomDoubleBetween(-Double.MAX_VALUE, GeoUtils.MIN_LON, true));
|
|
|
}
|
|
|
|
|
@@ -278,8 +277,8 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class BottomTester extends PointTester {
|
|
|
- public BottomTester() {
|
|
|
+ private static class BottomTester extends PointTester {
|
|
|
+ private BottomTester() {
|
|
|
super(randomDoubleBetween(-Double.MAX_VALUE, GeoUtils.MIN_LAT, false));
|
|
|
}
|
|
|
|
|
@@ -289,8 +288,8 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public class RightTester extends PointTester {
|
|
|
- public RightTester() {
|
|
|
+ private static class RightTester extends PointTester {
|
|
|
+ private RightTester() {
|
|
|
super(randomDoubleBetween(GeoUtils.MAX_LON, Double.MAX_VALUE, true));
|
|
|
}
|
|
|
|
|
@@ -300,6 +299,40 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testParsingAndToQueryGeoJSON() throws IOException {
|
|
|
+ String query = """
|
|
|
+ {
|
|
|
+ "geo_bounding_box":{
|
|
|
+ "%s":{
|
|
|
+ "top_left":{
|
|
|
+ "type":"Point",
|
|
|
+ "coordinates":[-70, 40]
|
|
|
+ },
|
|
|
+ "bottom_right":{
|
|
|
+ "type":"Point",
|
|
|
+ "coordinates":[-80, 30]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ """.formatted(GEO_POINT_FIELD_NAME);
|
|
|
+ assertGeoBoundingBoxQuery(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testParsingAndToQueryWKT() throws IOException {
|
|
|
+ String query = """
|
|
|
+ {
|
|
|
+ "geo_bounding_box":{
|
|
|
+ "%s":{
|
|
|
+ "top_left":"POINT(-70 40)",
|
|
|
+ "bottom_right":"POINT(-80 30)"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ """.formatted(GEO_POINT_FIELD_NAME);
|
|
|
+ assertGeoBoundingBoxQuery(query);
|
|
|
+ }
|
|
|
+
|
|
|
public void testParsingAndToQuery1() throws IOException {
|
|
|
String query = """
|
|
|
{
|