Search in sources :

Example 41 with AdviceWithRouteBuilder

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

the class AdviceWithWeaveFirstLastTest method testWeaveAddFirst.

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

        @Override
        public void configure() throws Exception {
            // insert at first the given piece of route to the existing route
            weaveAddFirst().to("mock:a").transform(constant("Bye World"));
        }
    });
    // END SNIPPET: e1
    context.start();
    getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:foo").expectedBodiesReceived("Bye 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) Test(org.junit.Test)

Example 42 with AdviceWithRouteBuilder

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

the class IsUseAdviceWithJUnit4Test method testIsUseAdviceWith.

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

        public void configure() throws Exception {
            replaceFromWith(directEndPointURI);
            interceptSendToEndpoint(providerEndPointURI).to("mock:intercepted").skipSendToOriginalEndpoint();
        }
    });
    // we must manually start when we are done with all the advice with
    context.start();
    getMockEndpoint(mockEndPointURI).expectedBodiesReceived("a trigger");
    getMockEndpoint("mock:intercepted").expectedBodiesReceived("a trigger");
    template.sendBody(directEndPointURI, "a trigger");
    assertMockEndpointsSatisfied();
    assertNotNull(context.hasEndpoint(directEndPointURI));
    assertNotNull(context.hasEndpoint(mockEndPointURI));
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test)

Example 43 with AdviceWithRouteBuilder

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

the class AdviceWithTransactionIssueTest method testAdviceWithWeaveById.

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

        @Override
        public void configure() throws Exception {
            weaveById("mock-b*").after().to("mock:last");
        }
    });
    context.start();
    MockEndpoint mockLast = getMockEndpoint("mock:last");
    mockLast.expectedBodiesReceived("bar");
    mockLast.setExpectedMessageCount(1);
    template.sendBody("activemq:queue:start", "bar");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test)

Example 44 with AdviceWithRouteBuilder

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

the class JMSTransactionIsTransactedRedeliveredTest method testTransactionSuccess.

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

        @Override
        public void configure() throws Exception {
            onException(AssertionError.class).to("log:error", "mock:error");
        }
    });
    context.start();
    // there should be no assertion errors
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Bye World");
    // success at 3rd attempt
    mock.message(0).header("count").isEqualTo(3);
    MockEndpoint jetty = getMockEndpoint("mock:jetty");
    jetty.expectedMessageCount(1);
    template.sendBody("activemq:queue:okay", "Hello World");
    mock.assertIsSatisfied();
    jetty.assertIsSatisfied();
    error.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test)

Example 45 with AdviceWithRouteBuilder

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

the class AdviceWithTransactionIssueTest method testAdviceWithWeaveById.

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

        @Override
        public void configure() throws Exception {
            weaveById("mock-b*").after().to("mock:last");
        }
    });
    context.start();
    MockEndpoint mockLast = getMockEndpoint("mock:last");
    mockLast.expectedBodiesReceived("bar");
    mockLast.setExpectedMessageCount(1);
    template.sendBody("seda:start", "bar");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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