|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.geo.search.aggregations.bucket; |
| 10 | + |
| 11 | +import org.opensearch.Version; |
| 12 | +import org.opensearch.action.index.IndexRequestBuilder; |
| 13 | +import org.opensearch.common.xcontent.XContentBuilder; |
| 14 | +import org.opensearch.geo.GeoModulePluginIntegTestCase; |
| 15 | +import org.opensearch.geometry.Geometry; |
| 16 | +import org.opensearch.geometry.Rectangle; |
| 17 | +import org.opensearch.test.VersionUtils; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; |
| 22 | + |
| 23 | +/** |
| 24 | + * This is the base class for all the Bucket Aggregation related integration tests. Use this class to add common |
| 25 | + * methods which can be used across different bucket aggregations. If there is any common code that can be used |
| 26 | + * across other integration test too then this is not the class. Use {@link GeoModulePluginIntegTestCase} |
| 27 | + */ |
| 28 | +public abstract class AbstractBucketAggregationIntegTest extends GeoModulePluginIntegTestCase { |
| 29 | + |
| 30 | + protected static final int MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING = 4; |
| 31 | + |
| 32 | + protected static final int NUM_DOCS = 100; |
| 33 | + |
| 34 | + protected static final String GEO_SHAPE_INDEX_NAME = "geoshape_index"; |
| 35 | + |
| 36 | + // We don't want to generate this BB at random as it may lead to generation of very large or very small BB. |
| 37 | + // Hence, we are making the parameters of this BB static for simplicity. |
| 38 | + protected static final Rectangle BOUNDING_RECTANGLE_FOR_GEO_SHAPES_AGG = new Rectangle(-4.1, 20.9, 21.9, -3.1); |
| 39 | + |
| 40 | + protected static final String AGG_NAME = "geohashgrid"; |
| 41 | + |
| 42 | + protected static final String GEO_SHAPE_FIELD_NAME = "location_geo_shape"; |
| 43 | + |
| 44 | + protected static final String GEO_POINT_FIELD_NAME = "location"; |
| 45 | + |
| 46 | + protected static final String KEYWORD_FIELD_NAME = "city"; |
| 47 | + |
| 48 | + protected final Version version = VersionUtils.randomIndexCompatibleVersion(random()); |
| 49 | + |
| 50 | + @Override |
| 51 | + protected boolean forbidPrivateIndexSettings() { |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + protected IndexRequestBuilder indexGeoShape(final String index, final Geometry geometry) throws Exception { |
| 56 | + XContentBuilder source = jsonBuilder().startObject(); |
| 57 | + source = source.field(GEO_SHAPE_FIELD_NAME, WKT.toWKT(geometry)); |
| 58 | + source = source.endObject(); |
| 59 | + return client().prepareIndex(index).setSource(source); |
| 60 | + } |
| 61 | + |
| 62 | + protected IndexRequestBuilder indexCity(final String index, final String name, final List<String> latLon) throws Exception { |
| 63 | + XContentBuilder source = jsonBuilder().startObject().field(KEYWORD_FIELD_NAME, name); |
| 64 | + if (latLon != null) { |
| 65 | + source = source.field(GEO_POINT_FIELD_NAME, latLon); |
| 66 | + } |
| 67 | + source = source.endObject(); |
| 68 | + return client().prepareIndex(index).setSource(source); |
| 69 | + } |
| 70 | + |
| 71 | + protected IndexRequestBuilder indexCity(final String index, final String name, final String latLon) throws Exception { |
| 72 | + return indexCity(index, name, List.of(latLon)); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments