Search in sources :

Example 46 with Document

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

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForFloats.

@Test
public void requireDescriptiveErrorMsgForFloats() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <floatfield></floatfield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'floatfield': Invalid float \"\""), is(true));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Document(com.yahoo.document.Document) DeserializationException(com.yahoo.document.serialization.DeserializationException) Test(org.junit.Test)

Example 47 with Document

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

the class FieldSetTestCase method doCopyFields.

String doCopyFields(Document source, String fieldSet) {
    FieldSetRepo repo = new FieldSetRepo();
    Document target = new Document(source.getDataType(), source.getId());
    repo.copyFields(source, target, repo.parse(docMan, fieldSet));
    return stringifyFields(target);
}
Also used : Document(com.yahoo.document.Document)

Example 48 with Document

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

the class FieldSetTestCase method doStripFields.

String doStripFields(Document source, String fieldSet) {
    FieldSetRepo repo = new FieldSetRepo();
    Document target = source.clone();
    repo.stripFields(target, repo.parse(docMan, fieldSet));
    return stringifyFields(target);
}
Also used : Document(com.yahoo.document.Document)

Example 49 with Document

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

the class Bug6394548TestCase method testSerializeAndDeserializeMultipleAdjacentStructAnnotations.

@Test
public void testSerializeAndDeserializeMultipleAdjacentStructAnnotations() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.6394548.cfg");
    AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
    AnnotationType featureSetType = registry.getType("morty.RICK_FEATURESET");
    assertNotNull(featureSetType);
    Document doc = new Document(manager.getDocumentType("article"), "doc:article:test");
    StringFieldValue sfv = new StringFieldValue("badger waltz");
    SpanList root = new SpanList();
    SpanNode node = new Span(0, sfv.getString().length());
    root.add(node);
    SpanTree tree = new SpanTree("rick_features", root);
    for (int i = 0; i < 2; ++i) {
        tree.annotate(createBigFeatureSetAnnotation(featureSetType));
    }
    sfv.setSpanTree(tree);
    doc.setFieldValue("title", sfv);
    System.out.println(doc.toXml());
    String annotationsBefore = dumpAllAnnotations(tree);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
    serializer.write(doc);
    buffer.flip();
    DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(manager, buffer);
    Document doc2 = new Document(deserializer);
    System.out.println(doc2.toXml());
    StringFieldValue readString = (StringFieldValue) doc2.getFieldValue("title");
    SpanTree readTree = readString.getSpanTree("rick_features");
    assertNotNull(readTree);
    String annotationsAfter = dumpAllAnnotations(readTree);
    System.out.println("before:\n" + annotationsBefore);
    System.out.println("after:\n" + annotationsAfter);
    assertEquals(annotationsBefore, annotationsAfter);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Example 50 with Document

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

the class AbstractDocumentApiTestCase method requireThatSyncSessionWorks.

@Test
public void requireThatSyncSessionWorks() {
    SyncSession session = access().createSyncSession(new SyncParameters());
    DocumentType type = access().getDocumentTypeManager().getDocumentType("music");
    Document doc1 = new Document(type, new DocumentId("doc:music:1"));
    Document doc2 = new Document(type, new DocumentId("doc:music:2"));
    session.put(new DocumentPut(doc1));
    session.put(new DocumentPut(doc2));
    assertEquals(doc1, session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:2")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:2")));
    session.destroy();
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

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