GeoPointMapper extends MultipleColumnMapper { public GeoPointMapper(String field, Boolean validated, String latitude, String longitude, Integer maxLevels) { super(field, validated, Arrays.asList(latitude, longitude), NUMERIC_TYPES, Collections.singletonList(Byte.class)); if (StringUtils.isBlank(latitude)) { throw new IndexException("latitude column name is required"); } if (StringUtils.isBlank(longitude)) { throw new IndexException("longitude column name is required"); } this.latitude = latitude; this.longitude = longitude; this.maxLevels = GeospatialUtils.validateGeohashMaxLevels(maxLevels, DEFAULT_MAX_LEVELS); SpatialPrefixTree grid = new GeohashPrefixTree(CONTEXT, this.maxLevels); RecursivePrefixTreeStrategy indexStrategy = new RecursivePrefixTreeStrategy(grid, field); SerializedDVStrategy geometryStrategy = new SerializedDVStrategy(CONTEXT, field); strategy = new CompositeSpatialStrategy(field, indexStrategy, geometryStrategy); } GeoPointMapper(String field, Boolean validated, String latitude, String longitude, Integer maxLevels); @Override List<IndexableField> indexableFields(Columns columns); @Override SortField sortField(String name, boolean reverse); @Override String toString(); static final int DEFAULT_MAX_LEVELS; final String latitude; final String longitude; final int maxLevels; final CompositeSpatialStrategy strategy; }
@Test public void testConstructorWithDefaultArgs() { GeoPointMapper mapper = geoPointMapper("lat", "lon").build("field"); assertEquals("Field name is not properly set", "field", mapper.field); assertEquals("Validated is not set to default value", Mapper.DEFAULT_VALIDATED, mapper.validated); assertEquals("Latitude is not properly set", "lat", mapper.latitude); assertEquals("Longitude is not properly set", "lon", mapper.longitude); assertEquals("Mapped columns are not properly set", 2, mapper.mappedColumns.size()); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("lat")); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("lon")); assertEquals("Max levels is not properly set", GeoPointMapper.DEFAULT_MAX_LEVELS, mapper.maxLevels); assertNotNull("Spatial strategy is not properly set", mapper.strategy); }
@Test public void testConstructorWithAllArgs() { GeoPointMapper mapper = geoPointMapper("lat", "lon").validated(true).maxLevels(5).build("field"); assertEquals("Field name is not properly set", "field", mapper.field); assertTrue("Validated is not properly set", mapper.validated); assertEquals("Latitude is not properly set", "lat", mapper.latitude); assertEquals("Longitude is not properly set", "lon", mapper.longitude); assertEquals("Max levels is not properly set", 5, mapper.maxLevels); assertNotNull("Spatial strategy is not properly set", mapper.strategy); }
@Test public void testConstructorWithNullMaxLevels() { GeoPointMapper mapper = geoPointMapper("lat", "lon").maxLevels(null).build("field"); assertEquals("Max levels is not properly set", GeoPointMapper.DEFAULT_MAX_LEVELS, mapper.maxLevels); }
@Test(expected = IndexException.class) public void testConstructorWithZeroLevels() { geoPointMapper("lat", "lon").maxLevels(0).build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithNegativeLevels() { geoPointMapper("lat", "lon").maxLevels(-1).build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithTooManyLevels() { geoPointMapper("lat", "lon").maxLevels(25).build("field"); }
@Test public void testJsonSerialization() { GeoPointMapperBuilder builder = geoPointMapper("lat", "lon").maxLevels(5); testJson(builder, "{type:\"geo_point\",latitude:\"lat\",longitude:\"lon\",max_levels:5}"); }
@Test public void testJsonSerializationDefaults() { GeoPointMapperBuilder builder = geoPointMapper("lat", "lon"); testJson(builder, "{type:\"geo_point\",latitude:\"lat\",longitude:\"lon\"}"); }
@Test(expected = IndexException.class) public void testConstructorWithNullLatitude() { geoPointMapper(null, "lon").build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyLatitude() { geoPointMapper("", "lon").build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankLatitude() { geoPointMapper(" ", "lon").build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithNullLongitude() { geoPointMapper(null, "lon").build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithEmptyLongitude() { geoPointMapper("", "lon").build("field"); }
@Test(expected = IndexException.class) public void testConstructorWithBlankLongitude() { geoPointMapper(" ", "lon").build("field"); }
@Test public void testExtractAnalyzers() { GeoPointMapper mapper = geoPointMapper("lat", "lon").build("field"); assertNull("Analyzer must be null", mapper.analyzer); }