use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method oldMapTest.
@Test
public void oldMapTest() throws IOException {
String fields = "{ \"actualmap\": [" + " { \"key\": \"nalle\", \"value\": \"kalle\"}," + " { \"key\": \"tralle\", \"value\": \"skalle\"} ]}";
String docId = "id:unittest:testmap::whee";
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("actualmap");
Map<?, ?> generatedMap = (Map<?, ?>) ((Map<?, ?>) generated.get("fields")).get("actualmap");
assertEquals(populateMap(inputMap), generatedMap);
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonWriterTestCase method hideEmptyStringsTest.
@Test
public void hideEmptyStringsTest() throws IOException {
String fields = "{" + " \"something\": \"\"," + " \"nalle\": \"bamse\"" + "}";
String filteredFields = "{" + " \"nalle\": \"bamse\"" + "}";
Document doc = readDocumentFromJson("id:unittest:smoke::whee", fields);
assertEqualJson(asDocument("id:unittest:smoke::whee", filteredFields), JsonWriter.toByteArray(doc));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class PredicateFieldValueSerializationTestCase method assertDeserialize.
private static void assertDeserialize(String fileName, Predicate expected) throws IOException {
Document document = docFactory.createDocument();
document.setFieldValue(PREDICATE_FIELD, new PredicateFieldValue(expected));
SerializationTestUtils.assertSerializationMatchesCpp(PREDICATE_FILES, fileName, document, docFactory);
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class Bug4475379TestCase method testClone.
@Test
public void testClone() {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.bug4475379.cfg");
DocumentType type = manager.getDocumentType("blog");
Document doc = new Document(type, "doc:this:is:a:test");
doc.setFieldValue("body", new StringFieldValue(""));
annotate(manager, doc);
Document anotherDoc = doc.clone();
assertThat(doc, equalTo(anotherDoc));
}
use of com.yahoo.document.Document 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));
}
}
Aggregations