Search in sources :

Example 6 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXml3.

public void testAddRouteDefinitionsFromXml3() throws Exception {
    RouteDefinition route = loadRoute("route3.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRoutes().size());
    assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
    getMockEndpoint("mock:foo").whenExchangeReceived(2, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setException(new IllegalArgumentException("Damn"));
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:handled").expectedBodiesReceived("Bye World");
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteDefinition(org.apache.camel.model.RouteDefinition) JAXBException(javax.xml.bind.JAXBException)

Example 7 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXml.

public void testAddRouteDefinitionsFromXml() throws Exception {
    RouteDefinition route = loadRoute("route1.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRoutes().size());
    assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

Example 8 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method testRemoveRouteDefinitionsFromXml.

public void testRemoveRouteDefinitionsFromXml() throws Exception {
    RouteDefinition route = loadRoute("route1.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRouteDefinitions().size());
    assertEquals(1, context.getRoutes().size());
    assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
    context.removeRouteDefinition(route);
    assertEquals(0, context.getRoutes().size());
    assertNull(context.getRouteStatus("foo"));
    assertEquals(0, context.getRouteDefinitions().size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

Example 9 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXmlIsPrepared.

public void testAddRouteDefinitionsFromXmlIsPrepared() throws Exception {
    RouteDefinition route = loadRoute("route1.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRoutes().size());
    assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
    // should be prepared, check parents has been set
    assertNotNull("Parent should be set on outputs");
    route = context.getRouteDefinition("foo");
    for (ProcessorDefinition<?> output : route.getOutputs()) {
        assertNotNull("Parent should be set on output", output.getParent());
        assertEquals(route, output.getParent());
    }
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

Example 10 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsAfterExceptionFromXml.

public void testAddRouteDefinitionsAfterExceptionFromXml() throws Exception {
    RouteDefinition route = loadRoute("route4_error.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    try {
        context.addRouteDefinition(route);
    } catch (Exception e) {
    // catch this is error to simulate test case!!!!
    }
    // load route with same id
    route = loadRoute("route4_ok.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRoutes().size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) JAXBException(javax.xml.bind.JAXBException)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)102 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)17 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 FromDefinition (org.apache.camel.model.FromDefinition)9 HashMap (java.util.HashMap)6 Processor (org.apache.camel.Processor)6 ConnectException (java.net.ConnectException)5 Exchange (org.apache.camel.Exchange)5 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)5 IOException (java.io.IOException)4 Map (java.util.Map)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)4 HystrixDefinition (org.apache.camel.model.HystrixDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 ModelCamelContext (org.apache.camel.model.ModelCamelContext)4