Search in sources :

Example 6 with RestsDefinition

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();
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) RestsDefinition(org.apache.camel.model.rest.RestsDefinition)

Aggregations

RestsDefinition (org.apache.camel.model.rest.RestsDefinition)6 RestDefinition (org.apache.camel.model.rest.RestDefinition)5 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 CamelContext (org.apache.camel.CamelContext)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 XmlLineNumberParser (org.apache.camel.util.XmlLineNumberParser)1 Resource (org.springframework.core.io.Resource)1 Document (org.w3c.dom.Document)1