Search in sources :

Example 86 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithCBRTest method testAdviceCBR.

public void testAdviceCBR() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            weaveById("foo").after().to("mock:foo2");
            weaveById("bar").after().to("mock:bar2");
        }
    });
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
    template.sendBody("direct:start", "Hi World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 87 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithCBRTest method testAdviceToStringCBR.

public void testAdviceToStringCBR() throws Exception {
    RouteDefinition route = context.getRouteDefinitions().get(0);
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            weaveByToString("To[mock:foo]").after().to("mock:foo2");
            weaveByToString("To[mock:bar]").after().to("mock:bar2");
        }
    });
    getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
    getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
    template.sendBody("direct:start", "Hi World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 88 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class SplitterWithCustomThreadPoolExecutorTest method getSplitter.

protected SplitDefinition getSplitter() {
    SplitDefinition result = null;
    List<RouteDefinition> routeDefinitions = context.getRouteDefinitions();
    for (RouteDefinition routeType : routeDefinitions) {
        result = firstSplitterType(routeType.getOutputs());
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) SplitDefinition(org.apache.camel.model.SplitDefinition)

Example 89 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class TraceInitIdOnAllNodesTest method testInitIdsOnAllNodes.

public void testInitIdsOnAllNodes() throws Exception {
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());
    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());
    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());
    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());
    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());
    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());
    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());
    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());
    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) OtherwiseDefinition(org.apache.camel.model.OtherwiseDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition)

Example 90 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithTwoRoutesOnExceptionTest method testAdviceWithB.

public void testAdviceWithB() throws Exception {
    RouteDefinition route = context.getRouteDefinition("b");
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
        }
    });
    getMockEndpoint("mock:b").expectedMessageCount(0);
    getMockEndpoint("mock:error").expectedMessageCount(1);
    getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
    template.sendBody("direct:b", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)102 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)17 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 FromDefinition (org.apache.camel.model.FromDefinition)9 HashMap (java.util.HashMap)6 Processor (org.apache.camel.Processor)6 ConnectException (java.net.ConnectException)5 Exchange (org.apache.camel.Exchange)5 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)5 IOException (java.io.IOException)4 Map (java.util.Map)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)4 HystrixDefinition (org.apache.camel.model.HystrixDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 ModelCamelContext (org.apache.camel.model.ModelCamelContext)4