Search in sources :

Example 1 with MethodAnnotation

use of org.exquery.serialization.annotation.MethodAnnotation in project exist by eXist-db.

the class RegistryFunctionsTest method outputMethod.

@Test
public void outputMethod() throws SerializationAnnotationException, TransformerException, IOException, SAXException {
    // test setup
    final String methodStr = "html5";
    final MethodAnnotation method = new MethodAnnotation();
    method.setName(SerializationAnnotationName.method.getQName());
    method.setLiterals(new Literal[] { new Literal() {

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

        @Override
        public String getValue() {
            return methodStr;
        }
    } });
    method.initialise();
    // execute serialize method
    final MemTreeBuilder builder = new MemTreeBuilder();
    builder.startDocument();
    RegistryFunctions.serializeSerializationAnnotation(builder, method);
    builder.endDocument();
    // assert result
    final String xmlResult = documentToString(builder.getDocument());
    final Source srcExpected = Input.fromString("<method xmlns=\"http://www.w3.org/2010/xslt-xquery-serialization\">" + methodStr + "</method>").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) Diff(org.xmlunit.diff.Diff) Literal(org.exquery.xquery.Literal) MethodAnnotation(org.exquery.serialization.annotation.MethodAnnotation) 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 MethodAnnotation (org.exquery.serialization.annotation.MethodAnnotation)1 Literal (org.exquery.xquery.Literal)1 Type (org.exquery.xquery.Type)1 Test (org.junit.Test)1 Diff (org.xmlunit.diff.Diff)1