@Override
  protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() {
    GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(GEO_POINT_FIELD_NAME);
    Rectangle box =
        RandomShapeGenerator.xRandomRectangle(
            random(), RandomShapeGenerator.xRandomPoint(random()));

    if (randomBoolean()) {
      // check the top-left/bottom-right combination of setters
      int path = randomIntBetween(0, 2);
      switch (path) {
        case 0:
          builder.setCorners(
              new GeoPoint(box.getMaxY(), box.getMinX()),
              new GeoPoint(box.getMinY(), box.getMaxX()));
          break;
        case 1:
          builder.setCorners(
              GeohashUtils.encodeLatLon(box.getMaxY(), box.getMinX()),
              GeohashUtils.encodeLatLon(box.getMinY(), box.getMaxX()));
          break;
        default:
          builder.setCorners(box.getMaxY(), box.getMinX(), box.getMinY(), box.getMaxX());
      }
    } else {
      // check the bottom-left/ top-right combination of setters
      if (randomBoolean()) {
        builder.setCornersOGC(
            new GeoPoint(box.getMinY(), box.getMinX()), new GeoPoint(box.getMaxY(), box.getMaxX()));
      } else {
        builder.setCornersOGC(
            GeohashUtils.encodeLatLon(box.getMinY(), box.getMinX()),
            GeohashUtils.encodeLatLon(box.getMaxY(), box.getMaxX()));
      }
    }

    if (randomBoolean()) {
      builder.setValidationMethod(randomFrom(GeoValidationMethod.values()));
    }

    if (randomBoolean()) {
      builder.ignoreUnmapped(randomBoolean());
    }

    builder.type(randomFrom(GeoExecType.values()));
    return builder;
  }
 @Override
 protected void doAssertLuceneQuery(
     GeoBoundingBoxQueryBuilder queryBuilder, Query query, SearchContext searchContext)
     throws IOException {
   QueryShardContext context = searchContext.getQueryShardContext();
   MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
   if (fieldType == null) {
     assertTrue("Found no indexed geo query.", query instanceof MatchNoDocsQuery);
   } else {
     if (context.indexVersionCreated().before(Version.V_2_2_0)) {
       if (queryBuilder.type() == GeoExecType.INDEXED) {
         assertTrue("Found no indexed geo query.", query instanceof ConstantScoreQuery);
       } else {
         assertTrue(
             "Found no indexed geo query.", query instanceof LegacyInMemoryGeoBoundingBoxQuery);
       }
     } else if (context.indexVersionCreated().before(Version.V_5_0_0_beta1)) {
       assertTrue("Found no indexed geo query.", query instanceof GeoPointInBBoxQuery);
     } else {
       assertTrue("Found no indexed geo query.", query instanceof Query);
     }
   }
 }
 public void testFromJson() throws IOException {
   String json =
       "{\n"
           + "  \"geo_bounding_box\" : {\n"
           + "    \"pin.location\" : {\n"
           + "      \"top_left\" : [ -74.1, 40.73 ],\n"
           + "      \"bottom_right\" : [ -71.12, 40.01 ]\n"
           + "    },\n"
           + "    \"validation_method\" : \"STRICT\",\n"
           + "    \"type\" : \"MEMORY\",\n"
           + "    \"ignore_unmapped\" : false,\n"
           + "    \"boost\" : 1.0\n"
           + "  }\n"
           + "}";
   GeoBoundingBoxQueryBuilder parsed = (GeoBoundingBoxQueryBuilder) parseQuery(json);
   checkGeneratedJson(json, parsed);
   assertEquals(json, "pin.location", parsed.fieldName());
   assertEquals(json, -74.1, parsed.topLeft().getLon(), 0.0001);
   assertEquals(json, 40.73, parsed.topLeft().getLat(), 0.0001);
   assertEquals(json, -71.12, parsed.bottomRight().getLon(), 0.0001);
   assertEquals(json, 40.01, parsed.bottomRight().getLat(), 0.0001);
   assertEquals(json, 1.0, parsed.boost(), 0.0001);
   assertEquals(json, GeoExecType.MEMORY, parsed.type());
 }
 public void testValidationNullTypeString() {
   GeoBoundingBoxQueryBuilder qb = new GeoBoundingBoxQueryBuilder("teststring");
   IllegalArgumentException e =
       expectThrows(IllegalArgumentException.class, () -> qb.type((String) null));
   assertEquals("cannot parse type from null string", e.getMessage());
 }
 public void testValidationNullType() {
   GeoBoundingBoxQueryBuilder qb = new GeoBoundingBoxQueryBuilder("teststring");
   IllegalArgumentException e =
       expectThrows(IllegalArgumentException.class, () -> qb.type((GeoExecType) null));
   assertEquals("Type is not allowed to be null.", e.getMessage());
 }