CAMEL-11297: camel-ehcache-starter : auto discovery cache manager.

Allow to configure if a cache manager eventually already configured on
the component should be overridden or not by the CacheManagerCustomizer.


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

Branch: refs/heads/master
Commit: 24d9de0422485ddce6a08b71e1fe236cd04d3b55
Parents: 77640af
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Fri May 19 15:26:23 2017 +0200
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Fri May 19 16:39:20 2017 +0200

----------------------------------------------------------------------
 .../EhcacheComponentAutoConfiguration.java      | 12 +--
 .../customizer/CacheManagerCustomizer.java      | 23 +++++-
 .../CacheManagerCustomizerConfiguration.java    | 49 +++++++++++
 ...heManagerConfigurerNotEnabledGlobalTest.java | 37 ---------
 ...agerConfigurerNotEnabledOnComponentTest.java | 37 ---------
 .../CacheManagerConfigurerNotEnabledTest.java   | 37 ---------
 ...acheManagerConfigurerNotEnabledTestBase.java | 48 -----------
 .../springboot/CacheManagerConfigurerTest.java  | 63 --------------
 .../CacheManagerCustomizerNoOverrideTest.java   | 87 ++++++++++++++++++++
 ...heManagerCustomizerNotEnabledGlobalTest.java | 37 +++++++++
 ...agerCustomizerNotEnabledOnComponentTest.java | 37 +++++++++
 .../CacheManagerCustomizerNotEnabledTest.java   | 37 +++++++++
 ...acheManagerCustomizerNotEnabledTestBase.java | 48 +++++++++++
 .../CacheManagerCustomizerOverrideTest.java     | 87 ++++++++++++++++++++
 .../springboot/CacheManagerCustomizerTest.java  | 63 ++++++++++++++
 .../src/test/resources/application.properties   |  2 +-
 16 files changed, 472 insertions(+), 232 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
index 3412c67..79466cc 100644
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
@@ -114,14 +114,14 @@ public class EhcacheComponentAutoConfiguration extends 
AllNestedConditions {
         }
         IntrospectionSupport.setProperties(camelContext,
                 camelContext.getTypeConverter(), component, parameters);
-        boolean useConfigurers = globalConfiguration.getConfigurer()
+        boolean useConfigurers = globalConfiguration.getCustomizer()
                 .isEnabled()
-                && componentConfiguration.getConfigurer().isEnabled();
+                && componentConfiguration.getCustomizer().isEnabled();
         if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) {
-            for (ComponentCustomizer<EhcacheComponent> configurer : 
customizers) {
-                LOGGER.debug("Configure component {}, with configurer {}",
-                        component, configurer);
-                configurer.customize(component);
+            for (ComponentCustomizer<EhcacheComponent> customizer : 
customizers) {
+                LOGGER.debug("Configure component {}, with customizer {}",
+                        component, customizer);
+                customizer.customize(component);
             }
         }
         return component;

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizer.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizer.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizer.java
index f3a8e59..4942169 100644
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizer.java
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizer.java
@@ -27,6 +27,7 @@ import 
org.springframework.boot.autoconfigure.AutoConfigureBefore;
 import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.Ordered;
 import org.springframework.core.annotation.Order;
@@ -36,16 +37,28 @@ import org.springframework.core.annotation.Order;
  * {@link CacheManager} instance and bind it to the {@link EhcacheComponent}
  * component.
  *
- * This configurer can be disabled either by disable all the
+ * This customizer can be disabled/enabled with different strategies:
+ *
+ * 1. globally using:
+ *    camel.component.customizer.enable = true/false
+ *
+ * 2. for component:
+ *    camel.component.ehcache.customizer.enabled = true/false
+ *
+ * 3. individually:
+ *    camel.component.ehcache.customizer.cache-manager.enabled = true/false
  */
 @Order(Ordered.LOWEST_PRECEDENCE)
 @Configuration
-@ConditionalOnProperty(name = 
"camel.component.ehcache.configurer.cache-manager.enabled", matchIfMissing = 
true)
+@ConditionalOnProperty(name = 
"camel.component.ehcache.customizer.cache-manager.enabled", matchIfMissing = 
true)
 @AutoConfigureAfter(CamelAutoConfiguration.class)
 @AutoConfigureBefore(EhcacheComponentAutoConfiguration.class)
+@EnableConfigurationProperties(CacheManagerCustomizerConfiguration.class)
 public class CacheManagerCustomizer extends AllNestedConditions implements 
ComponentCustomizer<EhcacheComponent> {
     @Autowired
     private CacheManager cacheManager;
+    @Autowired
+    private CacheManagerCustomizerConfiguration configuration;
 
     public CacheManagerCustomizer() {
         super(ConfigurationPhase.REGISTER_BEAN);
@@ -53,7 +66,11 @@ public class CacheManagerCustomizer extends 
AllNestedConditions implements Compo
 
     @Override
     public void customize(EhcacheComponent component) {
-        component.setCacheManager(cacheManager);
+        // Set the cache manager only if the customizer is configured to always
+        // set it or if no cache manager is already configured on component
+        if (configuration.isOverride() || component.getCacheManager() == null) 
{
+            component.setCacheManager(cacheManager);
+        }
     }
 
     // 
*************************************************************************

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizerConfiguration.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizerConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizerConfiguration.java
new file mode 100644
index 0000000..8db3850
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheManagerCustomizerConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.component.ehcache.springboot.customizer;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = 
"camel.component.ehcache.customizer.cache-manager")
+public class CacheManagerCustomizerConfiguration {
+    /**
+     * Enable or disable the cache-manager customizer.
+     */
+    private boolean enabled = true;
+
+    /**
+     * Configure if the cache manager eventually set on the component should 
be overridden by the customizer.
+     */
+    private boolean override;
+
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public boolean isOverride() {
+        return override;
+    }
+
+    public void setOverride(boolean override) {
+        this.override = override;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledGlobalTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledGlobalTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledGlobalTest.java
deleted file mode 100644
index 303ba06..0000000
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledGlobalTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.component.ehcache.springboot;
-
-import org.junit.runner.RunWith;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
-    classes = {
-        CacheManagerConfigurerNotEnabledTestBase.TestConfiguration.class
-    },
-    properties = {
-        "debug=false",
-        "camel.component.configurer.enabled=false"
-    })
-public class CacheManagerConfigurerNotEnabledGlobalTest extends 
CacheManagerConfigurerNotEnabledTestBase {
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledOnComponentTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledOnComponentTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledOnComponentTest.java
deleted file mode 100644
index 444d76b..0000000
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledOnComponentTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.component.ehcache.springboot;
-
-import org.junit.runner.RunWith;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
-    classes = {
-        CacheManagerConfigurerNotEnabledTestBase.TestConfiguration.class
-    },
-    properties = {
-        "debug=false",
-        "camel.component.ehcache.configurer.enabled=false"
-    })
-public class CacheManagerConfigurerNotEnabledOnComponentTest extends 
CacheManagerConfigurerNotEnabledTestBase {
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTest.java
deleted file mode 100644
index e43a635..0000000
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.component.ehcache.springboot;
-
-import org.junit.runner.RunWith;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
-    classes = {
-        CacheManagerConfigurerNotEnabledTestBase.TestConfiguration.class
-    },
-    properties = {
-        "debug=false",
-        "camel.component.ehcache.configurer.cache-manager.enabled=false"
-    })
-public class CacheManagerConfigurerNotEnabledTest extends 
CacheManagerConfigurerNotEnabledTestBase {
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTestBase.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTestBase.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTestBase.java
deleted file mode 100644
index fb65b4b..0000000
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerNotEnabledTestBase.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.component.ehcache.springboot;
-
-import org.apache.camel.component.ehcache.EhcacheComponent;
-import org.ehcache.CacheManager;
-import org.ehcache.config.builders.CacheManagerBuilder;
-import org.junit.Assert;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-class CacheManagerConfigurerNotEnabledTestBase {
-    @Autowired
-    CacheManager cacheManager;
-    @Autowired
-    EhcacheComponent component;
-
-    @Test
-    public void testComponentConfiguration() throws Exception {
-        Assert.assertNotNull(cacheManager);
-        Assert.assertNotNull(component);
-        Assert.assertNull(component.getCacheManager());
-    }
-
-    @Configuration
-    public static class TestConfiguration {
-        @Bean(initMethod = "init", destroyMethod = "close")
-        public CacheManager cacheManager() {
-            return CacheManagerBuilder.newCacheManagerBuilder().build();
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerTest.java
deleted file mode 100644
index 3a15d44..0000000
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerConfigurerTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.component.ehcache.springboot;
-
-import org.apache.camel.component.ehcache.EhcacheComponent;
-import org.ehcache.CacheManager;
-import org.ehcache.config.builders.CacheManagerBuilder;
-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.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
-    classes = {
-        CacheManagerConfigurerTest.TestConfiguration.class
-    },
-    properties = {
-        "debug=false",
-    })
-public class CacheManagerConfigurerTest {
-    @Autowired
-    CacheManager cacheManager;
-    @Autowired
-    EhcacheComponent component;
-
-    @Test
-    public void testComponentConfiguration() throws Exception {
-        Assert.assertNotNull(cacheManager);
-        Assert.assertNotNull(component);
-        Assert.assertEquals(cacheManager, component.getCacheManager());
-    }
-
-    @Configuration
-    public static class TestConfiguration {
-        @Bean(initMethod = "init", destroyMethod = "close")
-        public CacheManager cacheManager() {
-            return CacheManagerBuilder.newCacheManagerBuilder().build();
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNoOverrideTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNoOverrideTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNoOverrideTest.java
new file mode 100644
index 0000000..598e6cb
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNoOverrideTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.ehcache.CacheManager;
+import org.ehcache.config.builders.CacheManagerBuilder;
+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.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerNoOverrideTest.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.component.ehcache.customizer.cache-manager.enabled=true",
+        "camel.component.ehcache.customizer.cache-manager.override=false"
+    })
+public class CacheManagerCustomizerNoOverrideTest {
+    private static final CacheManager CACHE_MANAGER = 
CacheManagerBuilder.newCacheManagerBuilder().build();
+    @Autowired
+    CacheManager cacheManager;
+    @Autowired
+    EhcacheComponent component;
+
+    @Test
+    public void testComponentConfiguration() throws Exception {
+        Assert.assertNotNull(cacheManager);
+        Assert.assertNotNull(component);
+        Assert.assertNotNull(component.getCacheManager());
+        Assert.assertEquals(CACHE_MANAGER, component.getCacheManager());
+    }
+
+    @Configuration
+    @AutoConfigureAfter(CamelAutoConfiguration.class)
+    @AutoConfigureBefore(EhcacheComponentAutoConfiguration.class)
+    public static class TestConfiguration {
+
+        @Order(Ordered.HIGHEST_PRECEDENCE)
+        @Bean
+        public ComponentCustomizer<EhcacheComponent> customizer() {
+            return new ComponentCustomizer<EhcacheComponent>() {
+                @Override
+                public void customize(EhcacheComponent component) {
+                    component.setCacheManager(CACHE_MANAGER);
+                }
+            };
+        }
+
+        @Bean(initMethod = "init", destroyMethod = "close")
+        public CacheManager cacheManager() {
+            return CacheManagerBuilder.newCacheManagerBuilder().build();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledGlobalTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledGlobalTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledGlobalTest.java
new file mode 100644
index 0000000..c7bdd9f
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledGlobalTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerNotEnabledTestBase.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.component.customizer.enabled=false"
+    })
+public class CacheManagerCustomizerNotEnabledGlobalTest extends 
CacheManagerCustomizerNotEnabledTestBase {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledOnComponentTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledOnComponentTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledOnComponentTest.java
new file mode 100644
index 0000000..7a16ddb
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledOnComponentTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerNotEnabledTestBase.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.component.ehcache.customizer.enabled=false"
+    })
+public class CacheManagerCustomizerNotEnabledOnComponentTest extends 
CacheManagerCustomizerNotEnabledTestBase {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTest.java
new file mode 100644
index 0000000..76d1791
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerNotEnabledTestBase.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.component.ehcache.customizer.cache-manager.enabled=false"
+    })
+public class CacheManagerCustomizerNotEnabledTest extends 
CacheManagerCustomizerNotEnabledTestBase {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTestBase.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTestBase.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTestBase.java
new file mode 100644
index 0000000..0a4b6a1
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTestBase.java
@@ -0,0 +1,48 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.ehcache.CacheManager;
+import org.ehcache.config.builders.CacheManagerBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+class CacheManagerCustomizerNotEnabledTestBase {
+    @Autowired
+    CacheManager cacheManager;
+    @Autowired
+    EhcacheComponent component;
+
+    @Test
+    public void testComponentConfiguration() throws Exception {
+        Assert.assertNotNull(cacheManager);
+        Assert.assertNotNull(component);
+        Assert.assertNull(component.getCacheManager());
+    }
+
+    @Configuration
+    public static class TestConfiguration {
+        @Bean(initMethod = "init", destroyMethod = "close")
+        public CacheManager cacheManager() {
+            return CacheManagerBuilder.newCacheManagerBuilder().build();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerOverrideTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerOverrideTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerOverrideTest.java
new file mode 100644
index 0000000..086bab5
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerOverrideTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.ehcache.CacheManager;
+import org.ehcache.config.builders.CacheManagerBuilder;
+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.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerOverrideTest.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.component.ehcache.customizer.cache-manager.enabled=true",
+        "camel.component.ehcache.customizer.cache-manager.override=true"
+    })
+public class CacheManagerCustomizerOverrideTest {
+    private static final CacheManager CACHE_MANAGER = 
CacheManagerBuilder.newCacheManagerBuilder().build();
+    @Autowired
+    CacheManager cacheManager;
+    @Autowired
+    EhcacheComponent component;
+
+    @Test
+    public void testComponentConfiguration() throws Exception {
+        Assert.assertNotNull(cacheManager);
+        Assert.assertNotNull(component);
+        Assert.assertNotNull(component.getCacheManager());
+        Assert.assertEquals(cacheManager, component.getCacheManager());
+    }
+
+    @Configuration
+    @AutoConfigureAfter(CamelAutoConfiguration.class)
+    @AutoConfigureBefore(EhcacheComponentAutoConfiguration.class)
+    public static class TestConfiguration {
+
+        @Order(Ordered.HIGHEST_PRECEDENCE)
+        @Bean
+        public ComponentCustomizer<EhcacheComponent> customizer() {
+            return new ComponentCustomizer<EhcacheComponent>() {
+                @Override
+                public void customize(EhcacheComponent component) {
+                    component.setCacheManager(CACHE_MANAGER);
+                }
+            };
+        }
+
+        @Bean(initMethod = "init", destroyMethod = "close")
+        public CacheManager cacheManager() {
+            return CacheManagerBuilder.newCacheManagerBuilder().build();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerTest.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerTest.java
new file mode 100644
index 0000000..6a74037
--- /dev/null
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.component.ehcache.springboot;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.ehcache.CacheManager;
+import org.ehcache.config.builders.CacheManagerBuilder;
+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.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        CacheManagerCustomizerTest.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+    })
+public class CacheManagerCustomizerTest {
+    @Autowired
+    CacheManager cacheManager;
+    @Autowired
+    EhcacheComponent component;
+
+    @Test
+    public void testComponentConfiguration() throws Exception {
+        Assert.assertNotNull(cacheManager);
+        Assert.assertNotNull(component);
+        Assert.assertEquals(cacheManager, component.getCacheManager());
+    }
+
+    @Configuration
+    public static class TestConfiguration {
+        @Bean(initMethod = "init", destroyMethod = "close")
+        public CacheManager cacheManager() {
+            return CacheManagerBuilder.newCacheManagerBuilder().build();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/24d9de04/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/resources/application.properties
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/resources/application.properties
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/resources/application.properties
index 33406d2..3a5de5b 100644
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/resources/application.properties
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/resources/application.properties
@@ -1 +1 @@
-spring.main.banner-mode=off
+spring.main.banner-mode = off

Reply via email to