use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class SpanTreeTestCase method testCyclicReferences.
@Test
public void testCyclicReferences() {
DocumentTypeManager docMan = new DocumentTypeManager();
AnnotationTypeRegistry reg = docMan.getAnnotationTypeRegistry();
StringFieldValue strfval = new StringFieldValue("hohohoho");
SpanList root = new SpanList();
SpanTree tree = new SpanTree("habahaba", root);
strfval.setSpanTree(tree);
// set up types:
AnnotationType endTagType = new AnnotationType("endtag");
AnnotationType beginTagType = new AnnotationType("begintag");
AnnotationReferenceDataType refToBeginTagDataType = new AnnotationReferenceDataType(beginTagType);
AnnotationReferenceDataType refToEndTagDataType = new AnnotationReferenceDataType(endTagType);
endTagType.setDataType(refToBeginTagDataType);
beginTagType.setDataType(refToEndTagDataType);
// register types:
reg.register(endTagType);
reg.register(beginTagType);
docMan.register(refToBeginTagDataType);
docMan.register(refToEndTagDataType);
// set up annotations and their references to each other:
AnnotationReference refToBeginTag = new AnnotationReference(refToBeginTagDataType);
AnnotationReference refToEndTag = new AnnotationReference(refToEndTagDataType);
Annotation beginTag = new Annotation(beginTagType, refToEndTag);
Annotation endTag = new Annotation(endTagType, refToBeginTag);
refToBeginTag.setReference(beginTag);
refToEndTag.setReference(endTag);
// create spans:
Span beginTagSpan = new Span(0, 1);
Span endTagSpan = new Span(1, 1);
root.add(beginTagSpan);
root.add(endTagSpan);
// annotate spans:
tree.annotate(beginTagSpan, beginTag);
tree.annotate(endTagSpan, endTag);
// none of the below statements should lead to a StackOverflowError:
assertFalse(endTag.toString().equals(beginTag.toString()));
assertTrue(endTag.hashCode() != beginTag.hashCode());
assertFalse(endTag.equals(beginTag));
assertFalse(beginTag.equals(endTag));
StringFieldValue copyString = strfval.clone();
assertEquals(strfval, copyString);
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
serializer.write(new Field("stringfield", DataType.STRING), strfval);
buffer.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(docMan, buffer);
StringFieldValue stringFieldValue2 = new StringFieldValue();
deserializer.read(new Field("stringfield", DataType.STRING), stringFieldValue2);
assertEquals(strfval, stringFieldValue2);
assertNotSame(strfval, stringFieldValue2);
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class XMLNumericFieldErrorMsgTestCase method setupTypes.
private static DocumentTypeManager setupTypes() {
DocumentTypeManager dtm = new DocumentTypeManager();
DocumentType docType = new DocumentType("doctype");
docType.addField("bytefield", DataType.BYTE);
docType.addField("intfield", DataType.INT);
docType.addField("longfield", DataType.LONG);
docType.addField("floatfield", DataType.FLOAT);
docType.addField("doublefield", DataType.DOUBLE);
dtm.register(docType);
return dtm;
}
use of com.yahoo.document.DocumentTypeManager 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));
}
}
use of com.yahoo.document.DocumentTypeManager 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.DocumentTypeManager 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);
}
Aggregations