use of com.yahoo.document.Document 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.Document in project vespa by vespa-engine.
the class PositionParserTestCase method assertDocument.
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"));
}
use of com.yahoo.document.Document 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.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method assertTensorRoundTripEquality.
private void assertTensorRoundTripEquality(String inputTensorField, String outputTensorField) throws IOException {
String inputFields = "{ \"tensorfield\": " + inputTensorField + " }";
String outputFields = "{ \"tensorfield\": " + outputTensorField + " }";
String docId = "id:unittest:testtensor::0";
Document doc = readDocumentFromJson(docId, inputFields);
assertEqualJson(asDocument(docId, outputFields), JsonWriter.toByteArray(doc));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method non_empty_reference_field_results_in_reference_value_with_doc_id_present.
@Test
public void non_empty_reference_field_results_in_reference_value_with_doc_id_present() throws IOException {
final Document doc = readDocumentFromJson("id:unittest:testrefs::helloworld", "{ \"ref_field\": \"id:unittest:smoke::and_mirrors_too\" }");
ReferenceFieldValue ref = (ReferenceFieldValue) doc.getFieldValue("ref_field");
assertTrue(ref.getDocumentId().isPresent());
assertEquals(new DocumentId("id:unittest:smoke::and_mirrors_too"), ref.getDocumentId().get());
}
Aggregations