Search in sources :

Example 56 with AdviceWithRouteBuilder

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

the class AdviceWithTransactionIssueTest method testAdviceWithAddLast.

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

        @Override
        public void configure() throws Exception {
            weaveAddLast().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 57 with AdviceWithRouteBuilder

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

the class AdviceWithTest method shouldMockEndpoints.

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

        @Override
        public void configure() throws Exception {
            replaceFromWith("seda:start");
            weaveAddLast().to("mock:result");
        }
    });
    camelContext.start();
    MockEndpoint mock = camelContext.getEndpoint("mock:result", MockEndpoint.class);
    // Given
    String msg = "msg";
    mock.expectedBodiesReceived(msg);
    // When
    producerTemplate.sendBody("seda:start", msg);
    // Then
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 58 with AdviceWithRouteBuilder

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

the class AdvisedRouteTest method adviseCamelContext.

@Test
@InSequence(1)
public void adviseCamelContext(ModelCamelContext context) throws Exception {
    context.getRouteDefinition("route").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() {
            interceptSendToEndpoint("{{to}}").skipSendToOriginalEndpoint().to("mock:outbound");
        }
    });
    context.startAllRoutes();
}
Also used : AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 59 with AdviceWithRouteBuilder

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

the class DirectVmTwoCamelContextAdviceWithTest method testTwoCamelContext.

public void testTwoCamelContext() throws Exception {
    // add route
    context.addRoutes(createRouteBuilder());
    // advice
    context.getRouteDefinition("step-1a").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            weaveAddLast().to("mock:results");
        }
    });
    // start camel
    context.start();
    context2.start();
    MockEndpoint endpoint = getMockEndpoint("mock:results");
    endpoint.expectedBodiesReceived("Bye");
    template.sendBody("direct:step-1a", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 60 with AdviceWithRouteBuilder

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

the class AdviceWithRouteScopedErrorHandlerIssueTest method testAdviceWith.

public void testAdviceWith() throws Exception {
    context.getRouteDefinition("route-a").adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("direct:bar").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
        }
    });
    getMockEndpoint("mock:error").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(0);
    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