summaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
Publish
Diffstat (limited to 'document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java')
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
new file mode 100644
index 00000000000..a40e2a5a4a3
--- /dev/null
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
@@ -0,0 +1,48 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespaxmlparser;
+
+import com.yahoo.document.Document;
+import com.yahoo.document.DocumentType;
+import com.yahoo.document.DocumentTypeManager;
+import com.yahoo.document.PositionDataType;
+import com.yahoo.document.datatypes.Struct;
+import org.junit.Test;
+
+import java.util.Iterator;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class PositionParserTestCase {
+
+ @Test
+ public void requireThatPositionStringsCanBeParsed() throws Exception {
+ DocumentTypeManager mgr = new DocumentTypeManager();
+ mgr.register(PositionDataType.INSTANCE);
+ DocumentType docType = new DocumentType("my_doc");
+ docType.addField("my_pos", PositionDataType.INSTANCE);
+ mgr.registerDocumentType(docType);
+
+ VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_position.xml", mgr);
+ Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
+ assertTrue(it.hasNext());
+ assertDocument(PositionDataType.valueOf(1, 2), it.next());
+ assertTrue(it.hasNext());
+ assertDocument(PositionDataType.fromString("E3;N4"), it.next());
+ assertTrue(it.hasNext());
+ assertDocument(PositionDataType.fromString("5;6"), it.next());
+ assertTrue(it.hasNext());
+ assertDocument(PositionDataType.fromString("7;8"), it.next());
+ assertFalse(it.hasNext());
+ }
+
+ private static void assertDocument(Struct expected, VespaXMLFeedReader.Operation operation) {
+ assertNotNull(operation);
+ assertEquals(VespaXMLFeedReader.OperationType.DOCUMENT, operation.getType());
+ Document doc = operation.getDocument();
+ assertNotNull(doc);
+ assertEquals(expected, doc.getFieldValue("my_pos"));
+ }
+}