use of org.w3c.dom.Document in project camel by apache.
the class DomConverterTest method testDomConverterToBytes.
public void testDomConverterToBytes() throws Exception {
Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
byte[] bytes = new DomConverter().toByteArray(document.getChildNodes(), null);
assertTrue("Should be equal", ObjectHelper.equalByteArray("<hello>world!</hello>".getBytes("UTF-8"), bytes));
}
use of org.w3c.dom.Document in project camel by apache.
the class DomConverterTest method testDomConverterToInputStream.
public void testDomConverterToInputStream() throws Exception {
Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
InputStream is = new DomConverter().toInputStream(document.getChildNodes(), null);
assertEquals("<hello>world!</hello>", context.getTypeConverter().convertTo(String.class, is));
}
use of org.w3c.dom.Document in project camel by apache.
the class JaxpTest method testConvertToDocument.
public void testConvertToDocument() throws Exception {
Document document = converter.convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
assertNotNull(document);
LOG.debug("Found document: " + document);
// lets now convert back again
String text = converter.convertTo(String.class, document);
// The preamble changes a little under Java 1.6 it adds a
// standalone="no" attribute.
assertTrue("Converted to String: " + text, text.endsWith("<hello>world!</hello>"));
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlConverterTest method testToDocumentFromInputStream.
public void testToDocumentFromInputStream() throws Exception {
XmlConverter conv = new XmlConverter();
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
Document out = conv.toDOMDocument(is);
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlConverterTest method testToDocumentFromFile.
public void testToDocumentFromFile() throws Exception {
XmlConverter conv = new XmlConverter();
File file = new File("src/test/resources/org/apache/camel/converter/stream/test.xml");
Document out = conv.toDOMDocument(file);
assertNotNull(out);
String s = context.getTypeConverter().convertTo(String.class, out);
assertTrue(s.contains("<firstName>James</firstName>"));
}
Aggregations