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