diff options
author | Arne H Juul <arnej@yahooinc.com> | 2021-12-15 13:49:54 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-01-24 11:40:03 +0000 |
commit | da028dd3cc1653e9af793239d9df441bb76d1fa4 (patch) | |
tree | dad5d892bab16055054aec2ee8387fdd56b4725c /document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java | |
parent | e022e18ae1c424d9afb87ba7d5acde5d7f27cf45 (diff) |
configurable rendering of "position" structs
Diffstat (limited to 'document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java')
-rw-r--r-- | document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index 66ff7a7d4cd..ab4af5e722e 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -31,6 +31,7 @@ import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.document.datatypes.TensorFieldValue; import com.yahoo.document.datatypes.WeightedSet; +import com.yahoo.document.internal.GeoPosType; import com.yahoo.document.json.readers.DocumentParseInfo; import com.yahoo.document.json.readers.VespaJsonDocumentReader; import com.yahoo.document.serialization.DocumentSerializer; @@ -149,6 +150,7 @@ public class JsonReaderTestCase { DocumentType x = new DocumentType("testsinglepos"); DataType d = PositionDataType.INSTANCE; x.addField(new Field("singlepos", d)); + x.addField(new Field("geopos", new GeoPosType(8))); types.registerDocumentType(x); } { @@ -612,6 +614,43 @@ public class JsonReaderTestCase { } @Test + public void testPositionGeoPos() throws IOException { + Document doc = docFromJson(inputJson("{ 'put': 'id:unittest:testsinglepos::bamf',", + " 'fields': {", + " 'geopos': 'N63.429722;E10.393333' }}")); + FieldValue f = doc.getFieldValue(doc.getField("geopos")); + assertSame(Struct.class, f.getClass()); + assertEquals(10393333, PositionDataType.getXValue(f).getInteger()); + assertEquals(63429722, PositionDataType.getYValue(f).getInteger()); + assertEquals(f.getDataType(), PositionDataType.INSTANCE); + } + + @Test + public void testPositionOldGeoPos() throws IOException { + Document doc = docFromJson(inputJson("{ 'put': 'id:unittest:testsinglepos::bamf',", + " 'fields': {", + " 'geopos': {'x':10393333,'y':63429722} }}")); + FieldValue f = doc.getFieldValue(doc.getField("geopos")); + assertSame(Struct.class, f.getClass()); + assertEquals(10393333, PositionDataType.getXValue(f).getInteger()); + assertEquals(63429722, PositionDataType.getYValue(f).getInteger()); + assertEquals(f.getDataType(), PositionDataType.INSTANCE); + } + + @Test + public void testGeoPositionGeoPos() throws IOException { + Document doc = docFromJson(inputJson("{ 'put': 'id:unittest:testsinglepos::bamf',", + " 'fields': {", + " 'geopos': {'lat':63.429722,'lng':10.393333} }}")); + FieldValue f = doc.getFieldValue(doc.getField("geopos")); + assertSame(Struct.class, f.getClass()); + assertEquals(10393333, PositionDataType.getXValue(f).getInteger()); + assertEquals(63429722, PositionDataType.getYValue(f).getInteger()); + assertEquals(f.getDataType(), PositionDataType.INSTANCE); + assertEquals(PositionDataType.INSTANCE, f.getDataType()); + } + + @Test public void testPositionNegative() throws IOException { Document doc = docFromJson(inputJson("{ 'put': 'id:unittest:testsinglepos::bamf',", " 'fields': {", |