Search in sources :

Example 96 with Document

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

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForBytes.

@Test
public void requireDescriptiveErrorMsgForBytes() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <bytefield></bytefield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'bytefield': Invalid byte \"\""), 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 97 with Document

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

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForDoubles.

@Test
public void requireDescriptiveErrorMsgForDoubles() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <doublefield></doublefield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'doublefield': Invalid double \"\""), 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 98 with Document

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

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForLongs.

@Test
public void requireDescriptiveErrorMsgForLongs() throws Exception {
    DocumentTypeManager dtm = setupTypes();
    try {
        VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(new ByteArrayInputStream(("<document id=\"doc:foo:bar\" type=\"doctype\">" + "  <longfield></longfield>" + "</document>").getBytes(StandardCharsets.UTF_8)), dtm);
        new Document(documentReader);
        fail("Sorry mac");
    } catch (DeserializationException e) {
        assertThat(e.getMessage(), e.getMessage().contains("Field 'longfield': Invalid long \"\""), 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 99 with Document

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

the class FieldSetTestCase method testStripFields.

@Test
public void testStripFields() {
    Document doc = getTestDocument();
    doc.removeFieldValue("rawattr");
    assertEquals("floatattr:3.56", doStripFields(doc, "[body]"));
    assertEquals("stringattr:tjohei,intattr:50,byteattr:30,floatattr:3.56", doStripFields(doc, "[all]"));
    assertEquals("stringattr:tjohei,intattr:50,byteattr:30", doStripFields(doc, "[header]"));
    assertEquals("byteattr:30,floatattr:3.56", doStripFields(doc, "testdoc:floatattr,byteattr"));
}
Also used : Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 100 with Document

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

the class FieldSetTestCase method testCopyDocumentFields.

@Test
public void testCopyDocumentFields() {
    Document doc = getTestDocument();
    doc.removeFieldValue("rawattr");
    assertEquals("floatattr:3.56", doCopyFields(doc, "[body]"));
    assertEquals("stringattr:tjohei,intattr:50,byteattr:30,floatattr:3.56", doCopyFields(doc, "[all]"));
    assertEquals("stringattr:tjohei,intattr:50,byteattr:30", doCopyFields(doc, "[header]"));
    assertEquals("byteattr:30,floatattr:3.56", doCopyFields(doc, "testdoc:floatattr,byteattr"));
}
Also used : 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