Search in sources :

Example 31 with AdviceWithRouteBuilder

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

the class AdviceWithTasksTest method testReplace.

public void testReplace() throws Exception {
    // START SNIPPET: e1
    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 replace it with the following route path
            weaveById("bar").replace().multicast().to("mock:a").to("mock:b");
        }
    });
    // END SNIPPET: e1
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    getMockEndpoint("mock:a").expectedMessageCount(1);
    getMockEndpoint("mock:b").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 32 with AdviceWithRouteBuilder

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

the class AdviceWithTasksToStringPatternTest method testRemove.

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

        @Override
        public void configure() throws Exception {
            weaveByToString(".*bar.*").remove();
        }
    });
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertTrue("Should have removed mock:bar endpoint", context.hasEndpoint("mock:bar") == null);
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 33 with AdviceWithRouteBuilder

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

the class AdviceWithTasksToStringPatternTest method testBefore.

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

        @Override
        public void configure() throws Exception {
            weaveByToString(".*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)

Example 34 with AdviceWithRouteBuilder

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

the class AdviceWithAutoStartupTest method testAdvised.

public void testAdvised() throws Exception {
    assertFalse(context.getRouteStatus("foo").isStarted());
    assertFalse(context.getRouteStatus("bar").isStarted());
    context.getRouteDefinition("bar").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            replaceFromWith("seda:newBar");
        }
    });
    assertFalse(context.getRouteStatus("foo").isStarted());
    assertFalse(context.getRouteStatus("bar").isStarted());
    context.startRoute("foo");
    context.startRoute("bar");
    assertTrue(context.getRouteStatus("foo").isStarted());
    assertTrue(context.getRouteStatus("bar").isStarted());
    getMockEndpoint("mock:newBar").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 35 with AdviceWithRouteBuilder

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

the class AdviceWithMockEndpointsHavingParameterTest method testAdvisedMockEndpoints.

public void testAdvisedMockEndpoints() throws Exception {
    // advice the first route using the inlined AdviceWith route builder
    // which has extended capabilities than the regular route builder
    context.getRouteDefinitions().get(1).adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            // mock all endpoints (will mock in all routes)
            mockEndpoints();
        }
    });
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:foo").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:log:start").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:seda:foo").expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // additional test to ensure correct endpoints in registry
    assertNotNull(context.hasEndpoint("direct:start"));
    assertNotNull(context.hasEndpoint("seda:foo"));
    assertNotNull(context.hasEndpoint("log:foo?showHeaders=false"));
    assertNotNull(context.hasEndpoint("log:start?showAll=true"));
    assertNotNull(context.hasEndpoint("mock:result"));
    // all the endpoints was mocked
    assertNotNull(context.hasEndpoint("mock:direct:start"));
    assertNotNull(context.hasEndpoint("mock:seda:foo"));
    assertNotNull(context.hasEndpoint("mock:log:start"));
    assertNotNull(context.hasEndpoint("mock:log:foo"));
}
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