Search in sources :

Example 86 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonWriterTestCase method empty_reference_field_results_in_reference_value_without_doc_id_present.

@Test
public void empty_reference_field_results_in_reference_value_without_doc_id_present() throws IOException {
    final Document doc = readDocumentFromJson("id:unittest:testrefs::helloworld", "{ \"ref_field\": \"\" }");
    ReferenceFieldValue ref = (ReferenceFieldValue) doc.getFieldValue("ref_field");
    assertFalse(ref.getDocumentId().isPresent());
}
Also used : ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 87 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonWriterTestCase method oldStringToArrayOfIntMapTest.

@Test
public final void oldStringToArrayOfIntMapTest() throws IOException {
    String docId = "id:unittest:testMapStringToArrayOfInt::whee";
    String fields = "{ \"actualMapStringToArrayOfInt\": [" + "{ \"key\": \"bamse\", \"value\": [1, 2, 3] }" + "]}";
    Document doc = readDocumentFromJson(docId, fields);
    // we have to do everything by hand to check, as maps are unordered, but
    // are serialized as an ordered structure
    ObjectMapper m = new ObjectMapper();
    Map<?, ?> generated = m.readValue(JsonWriter.toByteArray(doc), Map.class);
    assertEquals(docId, generated.get("id"));
    // and from here on down there will be lots of unchecked casting and
    // other fun. This is OK here, because if the casts fail, the should and
    // will fail anyway
    List<?> inputMap = (List<?>) m.readValue(Utf8.toBytes(fields), Map.class).get("actualMapStringToArrayOfInt");
    Map<?, ?> generatedMap = (Map<?, ?>) ((Map<?, ?>) generated.get("fields")).get("actualMapStringToArrayOfInt");
    assertEquals(populateMap(inputMap), generatedMap);
}
Also used : List(java.util.List) Document(com.yahoo.document.Document) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 88 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class PredicateFieldValueSerializationTestCase method requireThatPredicateFieldValuesAreDeserialized.

@Test
public void requireThatPredicateFieldValuesAreDeserialized() {
    Document prevDocument = docFactory.createDocument();
    PredicateFieldValue prevPredicate = new PredicateFieldValue(new Conjunction(new FeatureSet("foo", "bar"), new FeatureRange("baz", 6L, 9L)));
    prevDocument.setFieldValue(PREDICATE_FIELD, prevPredicate);
    byte[] buf = serializeDocument(prevDocument);
    Document nextDocument = deserializeDocument(buf, docFactory);
    assertEquals(prevDocument, nextDocument);
    assertEquals(prevPredicate, nextDocument.getFieldValue(PREDICATE_FIELD));
}
Also used : Conjunction(com.yahoo.document.predicate.Conjunction) FeatureRange(com.yahoo.document.predicate.FeatureRange) FeatureSet(com.yahoo.document.predicate.FeatureSet) Document(com.yahoo.document.Document) SerializationTestUtils.serializeDocument(com.yahoo.document.serialization.SerializationTestUtils.serializeDocument) SerializationTestUtils.deserializeDocument(com.yahoo.document.serialization.SerializationTestUtils.deserializeDocument) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 89 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class SystemTestCase method testSystemTest.

public void testSystemTest() {
    DocumentType type = manager.getDocumentType("article");
    Document inDocument = new Document(type, "doc:article:boringarticle:longarticle");
    annotate(inDocument);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(inDocument);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buffer);
    Document outDocument = new Document(deserializer);
    consume(outDocument);
}
Also used : DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document)

Example 90 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class StringTestCase method testAnnotatorConsumer.

/**
 * Test for bug 4066566. No assertions, but works if it runs without exceptions.
 */
@Test
public void testAnnotatorConsumer() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/datatypes/documentmanager.blog.sd");
    DocumentType blogType = manager.getDocumentType("blog");
    Document doc = new Document(blogType, "doc:blog:http://blogs.sun.com/praveenm");
    doc.setFieldValue("url", new StringFieldValue("http://blogs.sun.com/praveenm"));
    doc.setFieldValue("title", new StringFieldValue("Beginning JavaFX"));
    doc.setFieldValue("author", new StringFieldValue("Praveen Mohan"));
    doc.setFieldValue("body", new StringFieldValue("JavaFX can expand its wings across different domains such as manufacturing, logistics, retail, etc. Many companies have adopted it - IBM, Oracle, Yahoo, Honeywell. Even the non-IT industries such as GE, WIPRO, Ford etc. So it is a success for Christopher Oliver and Richard Bair. Scott Mcnealy is happy"));
    doc = annotate(doc, manager);
    doc = serializeAndDeserialize(doc, manager);
    doc = consume(doc, manager);
    System.err.println(doc);
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test) AbstractTypesTest(com.yahoo.document.annotation.AbstractTypesTest)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8