use of java.net.URL 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 java.net.URL 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 java.net.URL 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());
}
use of java.net.URL in project camel by apache.
the class CamelContextAddRouteDefinitionsFromXmlTest method parseUri.
protected Object parseUri(String uri) throws JAXBException {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
URL resource = getClass().getResource(uri);
assertNotNull("Cannot find resource on the classpath: " + uri, resource);
Object value = unmarshaller.unmarshal(resource);
return value;
}
use of java.net.URL in project camel by apache.
the class DefaultClassResolverTest method testLoadResourceAsUri.
public void testLoadResourceAsUri() {
DefaultClassResolver resolver = new DefaultClassResolver();
URL url = resolver.loadResourceAsURL("log4j2.properties");
assertNotNull(url);
}
Aggregations