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