Search in sources :

Example 61 with AdviceWithRouteBuilder

use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.

the class AdviceWithWeaveByToUriCBRTest method testAdviceCBR.

public void testAdviceCBR() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            weaveByToUri("direct:branch*").replace().to("mock:foo");
            mockEndpointsAndSkip("direct:branch*");
        }
    });
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 62 with AdviceWithRouteBuilder

use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.

the class AdviceWithWeaveByTypeCBRTest method testWeaveByType.

public void testWeaveByType() throws Exception {
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            weaveByType(ChoiceDefinition.class).replace().to("mock:baz");
        }
    });
    getMockEndpoint("mock:baz").expectedMessageCount(1);
    template.sendBody("direct:start", "World");
    assertMockEndpointsSatisfied();
}
Also used : ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 63 with AdviceWithRouteBuilder

use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.

the class AdviceWithIssueTest method testAdviceWithInterceptFrom.

public void testAdviceWithInterceptFrom() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptFrom().to("mock:from");
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:from").expectedBodiesReceived("World");
    getMockEndpoint("mock:from").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT, "direct://start");
    template.sendBody("direct:start", "World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 64 with AdviceWithRouteBuilder

use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.

the class AdviceWithIssueTest method testAdviceWithInterceptSendToEndpoint.

public void testAdviceWithInterceptSendToEndpoint() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock:result").to("mock:to");
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:to").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:to").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT, "mock://result");
    template.sendBody("direct:start", "World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 65 with AdviceWithRouteBuilder

use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.

the class AdviceWithOnExceptionMultipleIssueTest method testMultipleAdviceWithExceptionThrown.

public void testMultipleAdviceWithExceptionThrown() throws Exception {
    context.addRoutes(createRouteBuilder());
    context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock:resultA").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    throw new Exception("my exception");
                }
            });
        }
    });
    context.start();
    getMockEndpoint("mock:resultA").expectedMessageCount(0);
    template.sendBody("direct:startA", "a trigger");
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Aggregations

AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)94 RouteDefinition (org.apache.camel.model.RouteDefinition)17 Test (org.junit.Test)17 Exchange (org.apache.camel.Exchange)10 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)10 Processor (org.apache.camel.Processor)9 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)3 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)3 SedaEndpoint (org.apache.camel.component.seda.SedaEndpoint)2 ToDefinition (org.apache.camel.model.ToDefinition)2 ObjectName (javax.management.ObjectName)1 Endpoint (org.apache.camel.Endpoint)1 StatefulService (org.apache.camel.StatefulService)1 AdviceWithTask (org.apache.camel.builder.AdviceWithTask)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)1 LogDefinition (org.apache.camel.model.LogDefinition)1 SplitDefinition (org.apache.camel.model.SplitDefinition)1 InSequence (org.jboss.arquillian.junit.InSequence)1 Before (org.junit.Before)1