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());
}
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);
}
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));
}
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);
}
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);
}
Aggregations