Search in sources :

Example 1 with MediaTypeAnnotation

use of org.exquery.serialization.annotation.MediaTypeAnnotation 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

Override (java.lang.Override)1 DOMSource (javax.xml.transform.dom.DOMSource)1 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)1 MediaTypeAnnotation (org.exquery.serialization.annotation.MediaTypeAnnotation)1 Literal (org.exquery.xquery.Literal)1 Type (org.exquery.xquery.Type)1 Test (org.junit.Test)1 Diff (org.xmlunit.diff.Diff)1