Search in sources :

Example 61 with RouteDefinition

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

the class PropertiesComponentAdviceWithInterceptSendToEndpointTest method testAdviceWithInterceptSendToEndpoint.

public void testAdviceWithInterceptSendToEndpoint() throws Exception {
    RouteDefinition route = context.getRouteDefinition("foo");
    route.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("{{cool.mock}}:res*").to("mock:foo");
        }
    });
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 62 with RouteDefinition

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

the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXml2.

public void testAddRouteDefinitionsFromXml2() throws Exception {
    RouteDefinition route = loadRoute("route2.xml");
    assertNotNull(route);
    assertEquals("foo", route.getId());
    assertEquals(0, context.getRoutes().size());
    context.addRouteDefinition(route);
    assertEquals(1, context.getRoutes().size());
    assertTrue("Route should be stopped", context.getRouteStatus("foo").isStopped());
    context.startRoute("foo");
    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 63 with RouteDefinition

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

the class TwoRouteScopedOnExceptionWithInterceptSendToEndpointIssueWithPredicateTest method testIssue.

public void testIssue() throws Exception {
    final Predicate fail = PredicateBuilder.or(header(Exchange.REDELIVERY_COUNTER).isNull(), header(Exchange.REDELIVERY_COUNTER).isLessThan(5));
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("seda:*").skipSendToOriginalEndpoint().process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    invoked.incrementAndGet();
                    if (fail.matches(exchange)) {
                        throw new ConnectException("Forced");
                    }
                }
            }).to("mock:ok");
        }
    });
    getMockEndpoint("mock:global").expectedMessageCount(0);
    getMockEndpoint("mock:ok").expectedMessageCount(1);
    getMockEndpoint("mock:exhausted").expectedMessageCount(0);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // 5 retry + 1 ok
    assertEquals(6, invoked.get());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteDefinition(org.apache.camel.model.RouteDefinition) RouteBuilder(org.apache.camel.builder.RouteBuilder) ConnectException(java.net.ConnectException) Predicate(org.apache.camel.Predicate) ConnectException(java.net.ConnectException)

Example 64 with RouteDefinition

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

the class RandomLoadBalanceJavaDSLBuilderTest method testNavigateRouteAsJavaDSL.

public void testNavigateRouteAsJavaDSL() throws Exception {
    // this one navigate using the route definition
    StringBuilder sb = new StringBuilder();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    // the start of the route
    sb.append("from(\"" + route.getInputs().get(0).getUri() + "\")");
    // navigate the route and add Java DSL to the sb
    navigateDefinition(route, sb);
    // output the Java DSL
    assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")", sb.toString());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

Example 65 with RouteDefinition

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

the class XmlRouteContextImportTest method verifyRouteContext.

@Test
public void verifyRouteContext() {
    assertThat("Route context is incorrect!", routes, hasSize(1));
    RouteDefinition route = routes.get(0);
    assertThat("Route input is incorrect!", route.getInputs(), hasSize(1));
    assertThat("Route is incorrect!", route.getInputs().get(0).getEndpointUri(), is(equalTo("direct:inbound")));
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) Test(org.junit.Test)

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