use of org.apache.camel.model.rest.RestsDefinition in project camel by apache.
the class LoadRestFromXmlTest method testLoadRestFromXml.
public void testLoadRestFromXml() throws Exception {
assertNotNull("Existing foo route should be there", context.getRoute("foo"));
assertEquals(2, 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 rest from XML and add them to the existing camel context
InputStream is = getClass().getResourceAsStream("barRest.xml");
RestsDefinition rests = context.loadRestsDefinition(is);
context.addRestDefinitions(rests.getRests());
for (final RestDefinition restDefinition : rests.getRests()) {
List<RouteDefinition> routeDefinitions = restDefinition.asRouteDefinition(context);
context.addRouteDefinitions(routeDefinitions);
}
assertNotNull("Loaded rest route should be there", context.getRoute("route1"));
assertEquals(3, context.getRoutes().size());
// test that loaded route works
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedBodiesReceived("Bye World");
template.sendBody("seda:get-say-hello-bar", "Bye World");
bar.assertIsSatisfied();
}
Aggregations