You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2014/11/24 09:51:12 UTC

camel git commit: [Spring Boot] Added support for multiple CamelContext configurations.

Repository: camel
Updated Branches:
  refs/heads/master ad38d52b7 -> 7e2a5dd24


[Spring Boot] Added support for multiple CamelContext configurations.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7e2a5dd2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7e2a5dd2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7e2a5dd2

Branch: refs/heads/master
Commit: 7e2a5dd2473733f5f21113ef47d3be5b6ee043fd
Parents: ad38d52
Author: Henryk Konsek <he...@gmail.com>
Authored: Mon Nov 24 09:50:45 2014 +0100
Committer: Henryk Konsek <he...@gmail.com>
Committed: Mon Nov 24 09:51:00 2014 +0100

----------------------------------------------------------------------
 .../camel/spring/boot/RoutesCollector.java      | 11 +++++----
 .../spring/boot/CamelAutoConfigurationTest.java | 24 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7e2a5dd2/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
index 40e6f1a..f9db4dd 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
@@ -33,7 +33,7 @@ public class RoutesCollector implements BeanPostProcessor, ApplicationContextAwa
     private ApplicationContext applicationContext;
 
     @Autowired(required = false)
-    private CamelContextConfiguration camelContextConfiguration;
+    private CamelContextConfiguration[] camelContextConfigurations;
 
     @Override
     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
@@ -53,9 +53,11 @@ public class RoutesCollector implements BeanPostProcessor, ApplicationContextAwa
                     throw new RuntimeException(e);
                 }
             }
-            if (camelContextConfiguration != null) {
-                LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
-                camelContextConfiguration.beforeApplicationStart(camelContext);
+            if (camelContextConfigurations != null) {
+                for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
+                    LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
+                    camelContextConfiguration.beforeApplicationStart(camelContext);
+                }
             }
         }
         return bean;
@@ -63,6 +65,7 @@ public class RoutesCollector implements BeanPostProcessor, ApplicationContextAwa
 
     @Override
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        LOG.debug("Injecting Spring application context into RoutesCollector: {}");
         this.applicationContext = applicationContext;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7e2a5dd2/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
index e4f6572..d1f3b60 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
@@ -22,6 +22,7 @@ import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringCamelContext;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -33,6 +34,7 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import static org.apache.camel.spring.boot.TestConfig.CONTEXT_NAME;
 import static org.apache.camel.spring.boot.TestConfig.ROUTE_ID;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -129,6 +131,11 @@ public class CamelAutoConfigurationTest extends Assert {
     }
 
     @Test
+    public void shouldChangeContextNameViaConfigurationCallback() {
+        assertEquals(CONTEXT_NAME, camelContext.getName());
+    }
+
+    @Test
     public void shouldStartRoute() {
         // Given
         String message = "msg";
@@ -146,8 +153,14 @@ public class CamelAutoConfigurationTest extends Assert {
 @Configuration
 class TestConfig {
 
+    // Constants
+
     static final String ROUTE_ID = "testRoute";
 
+    static final String CONTEXT_NAME = "customName";
+
+    // Test beans
+
     @Bean
     RouteBuilder routeBuilder() {
         return new RouteBuilder() {
@@ -164,4 +177,15 @@ class TestConfig {
         return mock(CamelContextConfiguration.class);
     }
 
+    @Bean
+    CamelContextConfiguration nameConfiguration() {
+        return new CamelContextConfiguration() {
+            @Override
+            public void beforeApplicationStart(CamelContext camelContext) {
+                SpringCamelContext springCamelContext = (SpringCamelContext) camelContext;
+                springCamelContext.setName(CONTEXT_NAME);
+            }
+        };
+    }
+
 }
\ No newline at end of file