use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XsltBuilderTest method testXsltTransformerFile.
public void testXsltTransformerFile() throws Exception {
File styleSheet = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
XsltBuilder builder = new XsltBuilder();
builder.setTransformerFile(styleSheet);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
builder.process(exchange);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XsltBuilderTest method testXsltTransformerInputStream.
public void testXsltTransformerInputStream() throws Exception {
File styleSheet = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
XsltBuilder builder = new XsltBuilder();
builder.setTransformerInputStream(new FileInputStream(styleSheet));
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
builder.process(exchange);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XsltBuilderTest method testXsltOutputFile.
public void testXsltOutputFile() throws Exception {
URL styleSheet = getClass().getResource("example.xsl");
XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile();
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml");
builder.process(exchange);
assertIsInstanceOf(File.class, exchange.getOut().getBody());
File file = new File("target/xslt/xsltout.xml");
assertTrue("Output file should exist", file.exists());
String body = exchange.getOut().getBody(String.class);
assertTrue(body.endsWith("<goodbye>world!</goodbye>"));
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XsltBuilderTest method testNotFailNullBody.
public void testNotFailNullBody() throws Exception {
URL styleSheet = getClass().getResource("example.xsl");
XsltBuilder builder = XsltBuilder.xslt(styleSheet);
builder.setFailOnNullBody(false);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(null);
builder.process(exchange);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye/>", exchange.getOut().getBody(String.class));
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XsltBuilderTest method testXsltOutputFileDelete.
public void testXsltOutputFileDelete() throws Exception {
URL styleSheet = getClass().getResource("example.xsl");
XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile().deleteOutputFile();
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml");
builder.process(exchange);
assertIsInstanceOf(File.class, exchange.getOut().getBody());
File file = new File("target/xslt/xsltout.xml");
assertTrue("Output file should exist", file.exists());
String body = exchange.getOut().getBody(String.class);
assertTrue(body.endsWith("<goodbye>world!</goodbye>"));
// now done the exchange
List<Synchronization> onCompletions = exchange.handoverCompletions();
UnitOfWorkHelper.doneSynchronizations(exchange, onCompletions, log);
// the file should be deleted
assertFalse("Output file should be deleted", file.exists());
}
Aggregations