Search in sources :

Example 21 with AdviceWithRouteBuilder

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

the class AdviceWithWeaveByStringOnChoiceTest method testWeaveByToStringShoultNotThrowUnsupportedOperationException.

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

        @Override
        public void configure() throws Exception {
            weaveByToString(".*mock:foo.*").replace().to("mock:bar");
        }
    });
    context.start();
    getMockEndpoint("mock:foo").expectedMessageCount(0);
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 22 with AdviceWithRouteBuilder

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

the class AdviceWithReplaceFromTest method testReplaceFromUri.

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

        @Override
        public void configure() throws Exception {
            // replace the input in the route with a new endpoint uri
            replaceFromWith("seda:foo");
        }
    });
    getMockEndpoint("mock:result").expectedMessageCount(1);
    // has been replaced to a seda endpoint instead
    template.sendBody("seda:foo", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 23 with AdviceWithRouteBuilder

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

the class AdviceWithReplaceFromTest method testReplaceFromEndpoint.

public void testReplaceFromEndpoint() throws Exception {
    final Endpoint endpoint = context.getEndpoint("seda:foo");
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            // replace the input in the route with a new endpoint
            replaceFromWith(endpoint);
        }
    });
    getMockEndpoint("mock:result").expectedMessageCount(1);
    // has been replaced to a seda endpoint instead
    template.sendBody("seda:foo", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : Endpoint(org.apache.camel.Endpoint) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 24 with AdviceWithRouteBuilder

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

the class AdviceWithTasksMatchTest method testReplaceMultipleIds.

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

        @Override
        public void configure() throws Exception {
            // replace all gold id's with the following route path
            weaveById("gold*").replace().multicast().to("mock:a").to("mock:b");
        }
    });
    getMockEndpoint("mock:foo").expectedMessageCount(0);
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    getMockEndpoint("mock:a").expectedMessageCount(2);
    getMockEndpoint("mock:b").expectedMessageCount(2);
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 25 with AdviceWithRouteBuilder

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

the class AdviceWithTasksOnExceptionTest method testBeforeWithOnException.

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

        @Override
        public void configure() throws Exception {
            // weave the node in the route which has id = bar
            // and insert the following route path before the adviced node
            weaveById("bar").before().to("mock:a").transform(constant("Bye World"));
        }
    });
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : 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