blob: a40e2a5a4a38cb72939b8e9b472e61070a0cd71a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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"));
}
}
|