|
@@ -26,10 +26,13 @@ import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
|
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
|
|
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
|
|
+import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
|
+import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
|
+import org.elasticsearch.common.xcontent.XContentParser;
|
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
-import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
|
|
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
import static org.hamcrest.Matchers.*;
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -251,6 +254,17 @@ public class GeoUtilsTests extends ElasticsearchTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testTryParsingLatLonFromString() throws Exception {
|
|
|
|
+ XContentBuilder builder = jsonBuilder().startObject().field("lat", "52").field("lon", "4").endObject();
|
|
|
|
+ XContentParser parser = XContentHelper.createParser(builder.bytes());
|
|
|
|
+ parser.nextToken();
|
|
|
|
+ GeoPoint geoPoint = GeoUtils.parseGeoPoint(parser);
|
|
|
|
+ assertThat(geoPoint.lat(), is(52.0));
|
|
|
|
+ assertThat(geoPoint.lon(), is(4.0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private static void assertNormalizedPoint(GeoPoint input, GeoPoint expected) {
|
|
private static void assertNormalizedPoint(GeoPoint input, GeoPoint expected) {
|
|
GeoUtils.normalizePoint(input);
|
|
GeoUtils.normalizePoint(input);
|
|
assertThat(input, equalTo(expected));
|
|
assertThat(input, equalTo(expected));
|