This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-16757 in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/CAMEL-16757 by this push: new 9e9419f CAMEL-16757: camel-core - Global error handling, interceptor in all DSL 9e9419f is described below commit 9e9419f9cf0b55b4da5e80ba0e298987245183b6 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jul 7 14:47:36 2021 +0200 CAMEL-16757: camel-core - Global error handling, interceptor in all DSL --- .../model/RoutesConfigurationBuilderTest.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderTest.java b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderTest.java new file mode 100644 index 0000000..7e24ea2 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.model; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.builder.RoutesConfigurationsBuilder; +import org.apache.camel.support.OrderedComparator; +import org.junit.jupiter.api.Test; + +public class RoutesConfigurationBuilderTest extends ContextTestSupport { + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testRoutesConfiguration() throws Exception { + List<RoutesBuilder> routes = new ArrayList<>(); + + routes.add(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .throwException(new IllegalArgumentException("Foo")); + } + }); + routes.add(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start2") + .throwException(new IllegalArgumentException("Foo2")); + } + }); + routes.add(new RoutesConfigurationsBuilder() { + @Override + public void configuration() throws Exception { + // global routes configuration + routesConfiguration().onException(Exception.class).handled(true).to("mock:error"); + } + }); + context.start(); + + // sort routes according to ordered + routes.sort(OrderedComparator.get()); + + // first add the routes configurations as they are globally for all routes + for (RoutesBuilder builder : routes) { + if (builder instanceof org.apache.camel.RoutesConfigurationsBuilder) { + org.apache.camel.RoutesConfigurationsBuilder rcb = (org.apache.camel.RoutesConfigurationsBuilder) builder; + context.addRoutesConfigurations(rcb); + } + } + // then add the routes + for (RoutesBuilder builder : routes) { + context.addRoutes(builder); + } + + getMockEndpoint("mock:error").expectedBodiesReceived("Hello World", "Bye World"); + + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:start2", "Bye World"); + + assertMockEndpointsSatisfied(); + } + +}