Search in sources :

Example 81 with MemTreeBuilder

use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.

the class RegistryFunctionsTest method outputMediaType.

@Test
public void outputMediaType() throws URISyntaxException, TransformerException, IOException, SAXException, SerializationAnnotationException {
    // test setup
    final String internetMediaType = "application/octet-stream";
    final MediaTypeAnnotation mediaType = new MediaTypeAnnotation();
    mediaType.setName(SerializationAnnotationName.mediatype.getQName());
    mediaType.setLiterals(new Literal[] { new Literal() {

        @Override
        public Type getType() {
            return Type.STRING;
        }

        @Override
        public String getValue() {
            return internetMediaType;
        }
    } });
    mediaType.initialise();
    // execute serialize method
    final MemTreeBuilder builder = new MemTreeBuilder();
    builder.startDocument();
    RegistryFunctions.serializeSerializationAnnotation(builder, mediaType);
    builder.endDocument();
    // assert result
    final String xmlResult = documentToString(builder.getDocument());
    final Source srcExpected = Input.fromString("<media-type xmlns=\"http://www.w3.org/2010/xslt-xquery-serialization\">" + internetMediaType + "</media-type>").build();
    final Source srcActual = Input.fromString(xmlResult).build();
    final Diff diff = DiffBuilder.compare(srcExpected).withTest(srcActual).checkForIdentical().build();
    assertFalse(diff.toString(), diff.hasDifferences());
}
Also used : Type(org.exquery.xquery.Type) MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) MediaTypeAnnotation(org.exquery.serialization.annotation.MediaTypeAnnotation) Diff(org.xmlunit.diff.Diff) Literal(org.exquery.xquery.Literal) Override(java.lang.Override) DOMSource(javax.xml.transform.dom.DOMSource) Test(org.junit.Test)

Aggregations

MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)81 QName (org.exist.dom.QName)28 XPathException (org.exist.xquery.XPathException)23 Sequence (org.exist.xquery.value.Sequence)19 DocumentBuilderReceiver (org.exist.dom.memtree.DocumentBuilderReceiver)17 SAXException (org.xml.sax.SAXException)16 NodeValue (org.exist.xquery.value.NodeValue)15 IOException (java.io.IOException)14 NodeImpl (org.exist.dom.memtree.NodeImpl)14 Item (org.exist.xquery.value.Item)8 SequenceIterator (org.exist.xquery.value.SequenceIterator)8 Test (org.junit.Test)8 XQueryContext (org.exist.xquery.XQueryContext)7 ValueSequence (org.exist.xquery.value.ValueSequence)7 AttributesImpl (org.xml.sax.helpers.AttributesImpl)7 DocumentImpl (org.exist.dom.memtree.DocumentImpl)6 BrokerPool (org.exist.storage.BrokerPool)6 InputSource (org.xml.sax.InputSource)6 MalformedURLException (java.net.MalformedURLException)5 Path (java.nio.file.Path)5