use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method predicate_field_values_are_serialized.
@Test
public void predicate_field_values_are_serialized() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_predicate", DataType.PREDICATE);
docType.addField(field);
Document doc = new Document(docType, "doc:scheme:");
PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
doc.setFieldValue("my_predicate", predicate);
DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method get_serialized_size_uses_latest_serializer.
@Test
public void get_serialized_size_uses_latest_serializer() {
DocumentType docType = new DocumentType("my_type");
docType.addField("my_str", DataType.STRING);
docType.addField("my_int", DataType.INT);
Document doc = new Document(docType, "doc:scheme:");
doc.setFieldValue("my_str", new StringFieldValue("foo"));
doc.setFieldValue("my_int", new IntegerFieldValue(69));
GrowableByteBuffer buf = new GrowableByteBuffer();
doc.serialize(buf);
assertEquals(buf.position(), VespaDocumentSerializer42.getSerializedSize(doc));
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class PositionParserTestCase method requireThatPositionStringsCanBeParsed.
@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());
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class JsonWriterTestCase method testWritingOfTensorFieldValueWithoutTensor.
@Test
public void testWritingOfTensorFieldValueWithoutTensor() throws IOException {
DocumentType documentTypeWithTensor = types.getDocumentType("testtensor");
String docId = "id:unittest:testtensor::0";
Document doc = new Document(documentTypeWithTensor, docId);
Field tensorField = documentTypeWithTensor.getField("tensorfield");
doc.setFieldValue(tensorField, new TensorFieldValue(((TensorDataType) tensorField.getDataType()).getTensorType()));
assertEqualJson(asDocument(docId, "{ \"tensorfield\": {} }"), JsonWriter.toByteArray(doc));
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class JsonWriterTestCase method registerSetDocumentType.
private void registerSetDocumentType() {
DocumentType x = new DocumentType("testset");
DataType d = new WeightedSetDataType(DataType.STRING, true, true);
x.addField(new Field("actualset", d));
types.registerDocumentType(x);
}
Aggregations