Search in sources :

Example 51 with AdviceWithRouteBuilder

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

the class AdviceWithOnExceptionMultipleIssueTest method testMultipleAdviceWithExceptionThrown.

@Test
public void testMultipleAdviceWithExceptionThrown() throws Exception {
    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) Test(org.junit.Test)

Example 52 with AdviceWithRouteBuilder

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

the class AdviceWithOnExceptionMultipleIssueTest method testSimpleMultipleAdvice.

@Test
public void testSimpleMultipleAdvice() throws Exception {
    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 {
                }
            });
        }
    });
    context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
        }
    });
    context.start();
    getMockEndpoint("mock:resultA").expectedMessageCount(1);
    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) Test(org.junit.Test)

Example 53 with AdviceWithRouteBuilder

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

the class AdviceWithOnExceptionMultipleIssueTest method testMultipleAdvice.

@Test
public void testMultipleAdvice() throws Exception {
    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.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws 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) Test(org.junit.Test)

Example 54 with AdviceWithRouteBuilder

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

the class SimpleWeaveAddMockLastTest method testWeaveAddMockLast.

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

        @Override
        public void configure() throws Exception {
            weaveAddLast().to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye Camel");
    template.sendBody("seda:start", "Camel");
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test)

Example 55 with AdviceWithRouteBuilder

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

the class AdviceWithWeaveFirstLastTest method testWeaveAddLast.

@Test
public void testWeaveAddLast() throws Exception {
    // START SNIPPET: e2
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            // insert at the end of the existing route, the given piece of route
            weaveAddLast().to("mock:a").transform(constant("Bye World"));
        }
    });
    // END SNIPPET: e2
    context.start();
    getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    Object out = template.requestBody("direct:start", "Hello World");
    assertEquals("Bye World", out);
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test)

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