Search in sources :

Example 1 with DeserializationException

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

the class XMLNumericFieldErrorMsgTestCase method requireDescriptiveErrorMsgForIntegers.

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

use of com.yahoo.document.serialization.DeserializationException 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 3 with DeserializationException

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

the class VespaXmlFieldReaderTestCase method assertThrows.

private static void assertThrows(Field field, String fieldXml, String expected) throws Exception {
    DocumentTypeManager docManager = new DocumentTypeManager();
    DocumentType docType = new DocumentType("my_type");
    docType.addField(field);
    docManager.register(docType);
    String documentXml = "<document id='doc:scheme:' type='my_type'><" + field.getName() + ">" + fieldXml + "</" + field.getName() + "></document>";
    InputStream in = new ByteArrayInputStream(documentXml.getBytes(StandardCharsets.UTF_8));
    Document doc = new Document(docType, "doc:scheme:");
    try {
        new VespaXMLFieldReader(in, docManager).read(null, doc);
        fail();
    } catch (DeserializationException e) {
        assertEquals(expected, e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DeserializationException(com.yahoo.document.serialization.DeserializationException)

Example 4 with DeserializationException

use of com.yahoo.document.serialization.DeserializationException 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 5 with DeserializationException

use of com.yahoo.document.serialization.DeserializationException 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)

Aggregations

DeserializationException (com.yahoo.document.serialization.DeserializationException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.yahoo.document.Document)5 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)1