use of org.apache.camel.impl.DefaultModelJAXBContextFactory in project camel by apache.
the class SpringLoadRouteFromXmlTest method testLoadRouteFromXml.
@Test
public void testLoadRouteFromXml() throws Exception {
assertNotNull("Existing foo route should be there", context.getRoute("foo"));
assertEquals(1, context.getRoutes().size());
// test that existing route works
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedBodiesReceived("Hello World");
template.sendBody("direct:foo", "Hello World");
foo.assertIsSatisfied();
// load bar route from classpath using JAXB
JAXBContext jaxb = new DefaultModelJAXBContextFactory().newJAXBContext();
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
Resource rs = new ClassPathResource("org/apache/camel/itest/jaxb/BarRoute.xml");
Object value = unmarshaller.unmarshal(rs.getInputStream());
// it should be a RoutesDefinition (we can have multiple routes in the same XML file)
RoutesDefinition routes = (RoutesDefinition) value;
assertNotNull("Should load routes from XML", routes);
assertEquals(1, routes.getRoutes().size());
// add the routes to existing CamelContext
context.addRouteDefinitions(routes.getRoutes());
assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
assertEquals(2, context.getRoutes().size());
// test that loaded route works
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedBodiesReceived("Bye World");
template.sendBody("direct:bar", "Bye World");
bar.assertIsSatisfied();
}
Aggregations