This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/master by this push:
     new e5c1987d CAMEL-14297: Introduce RouteBuilderConfigurer
e5c1987d is described below

commit e5c1987dd304af678a50f22b22529c3e321b7fe4
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Aug 11 16:35:53 2020 +0200

    CAMEL-14297: Introduce RouteBuilderConfigurer
---
 .../spring/boot/SpringBootRoutesCollector.java     | 14 +++++
 .../boot/CamelRouteBuilderConfigurerTest.java      | 62 ++++++++++++++++++++++
 .../boot/RouteBuilderConfigurerConfiguration.java  | 31 +++++++++++
 3 files changed, 107 insertions(+)

diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
index d75d278..96d80d4 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
@@ -20,11 +20,14 @@ import java.io.FileNotFoundException;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.RouteBuilderConfigurer;
 import org.apache.camel.main.DefaultRoutesCollector;
 import org.apache.camel.model.RouteTemplatesDefinition;
 import org.apache.camel.model.RoutesDefinition;
@@ -50,6 +53,17 @@ public class SpringBootRoutesCollector extends 
DefaultRoutesCollector {
     public List<RoutesBuilder> collectRoutesFromRegistry(final CamelContext 
camelContext, final String excludePattern, final String includePattern) {
         final List<RoutesBuilder> routes = new ArrayList<>();
 
+        Set<RouteBuilderConfigurer> configurers = 
camelContext.getRegistry().findByType(RouteBuilderConfigurer.class);
+        for (RouteBuilderConfigurer configurer : configurers) {
+            RouteBuilder rb = new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    configurer.accept(this);
+                }
+            };
+            routes.add(rb);
+        }
+
         final AntPathMatcher matcher = new AntPathMatcher();
         for (RoutesBuilder routesBuilder : 
applicationContext.getBeansOfType(RoutesBuilder.class, true, true).values()) {
             // filter out abstract classes
diff --git 
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelRouteBuilderConfigurerTest.java
 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelRouteBuilderConfigurerTest.java
new file mode 100644
index 0000000..fd5f815
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelRouteBuilderConfigurerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(
+    classes = {
+        CamelRouteBuilderConfigurerTest.class,
+            RouteBuilderConfigurerConfiguration.class }
+)
+public class CamelRouteBuilderConfigurerTest extends Assert {
+
+    // Collaborators fixtures
+
+    @Autowired
+    CamelContext camelContext;
+
+    @Test
+    public void shouldDetectRoutes() throws Exception {
+        // When
+        Route route = camelContext.getRoute("foo");
+
+        // Then
+        assertNotNull(route);
+
+        MockEndpoint mock = camelContext.getEndpoint("mock:result", 
MockEndpoint.class);
+        mock.expectedBodiesReceived("Hello World");
+
+        
camelContext.createFluentProducerTemplate().to("direct:start").withBody("Hello 
World").send();
+
+        mock.assertIsSatisfied();
+    }
+
+}
\ No newline at end of file
diff --git 
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/RouteBuilderConfigurerConfiguration.java
 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/RouteBuilderConfigurerConfiguration.java
new file mode 100644
index 0000000..23aae0c
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/RouteBuilderConfigurerConfiguration.java
@@ -0,0 +1,31 @@
+/*
+ * 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.spring.boot;
+
+import org.apache.camel.builder.RouteBuilderConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RouteBuilderConfigurerConfiguration {
+
+    @Bean
+    public RouteBuilderConfigurer myRoute() {
+        return rb -> rb.from("direct:start").routeId("foo").to("mock:result");
+    }
+
+}

Reply via email to