You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/05/24 14:55:37 UTC
[2/2] camel git commit: CAMEL-11318: camel-ehcache: allow to
configure named caches programmatically
CAMEL-11318: camel-ehcache: allow to configure named caches programmatically
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f3004024
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f3004024
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f3004024
Branch: refs/heads/master
Commit: f30040249de5381d53d6b5f5e6ee74b7b373e32f
Parents: e3139a0
Author: lburgazzoli <lb...@gmail.com>
Authored: Wed May 24 16:54:26 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Wed May 24 16:54:48 2017 +0200
----------------------------------------------------------------------
.../src/main/docs/ehcache-component.adoc | 6 +-
.../component/ehcache/EhcacheComponent.java | 15 ++
.../component/ehcache/EhcacheConfiguration.java | 37 +++-
.../camel/component/ehcache/EhcacheManager.java | 16 +-
.../ehcache/EhcacheCacheConfigurationTest.java | 167 +++++++++++++++++++
.../ehcache/EhcacheConfigurationTest.java | 141 +++++-----------
.../EhcacheComponentConfiguration.java | 25 ++-
.../CacheConfigurationCustomizer.java | 100 +++++++++++
...cheConfigurationCustomizerConfiguration.java | 54 ++++++
.../main/resources/META-INF/spring.factories | 1 +
...ManagerCustomizerEnabledOnComponentTest.java | 38 -----
.../CacheManagerCustomizerEnabledTest.java | 39 -----
.../CacheManagerCustomizerEnabledTestBase.java | 48 ------
.../CacheManagerCustomizerNoOverrideTest.java | 87 ----------
...heManagerCustomizerNotEnabledGlobalTest.java | 37 ----
...agerCustomizerNotEnabledOnComponentTest.java | 38 -----
.../CacheManagerCustomizerNotEnabledTest.java | 37 ----
...acheManagerCustomizerNotEnabledTestBase.java | 48 ------
.../CacheManagerCustomizerOverrideTest.java | 87 ----------
.../springboot/CacheManagerCustomizerTest.java | 63 -------
...anagerCustomizerWithoutCacheManagerTest.java | 53 ------
...onfigurationCustomizerEnabledAppendTest.java | 121 ++++++++++++++
...nfigurationCustomizerEnabledReplaceTest.java | 121 ++++++++++++++
...igurationCustomizerNotEnabledGlobalTest.java | 37 ++++
...tionCustomizerNotEnabledOnComponentTest.java | 38 +++++
...heConfigurationCustomizerNotEnabledTest.java | 37 ++++
...nfigurationCustomizerNotEnabledTestBase.java | 70 ++++++++
...ManagerCustomizerEnabledOnComponentTest.java | 38 +++++
.../CacheManagerCustomizerEnabledTest.java | 39 +++++
.../CacheManagerCustomizerEnabledTestBase.java | 48 ++++++
.../CacheManagerCustomizerNoOverrideTest.java | 88 ++++++++++
...heManagerCustomizerNotEnabledGlobalTest.java | 37 ++++
...agerCustomizerNotEnabledOnComponentTest.java | 38 +++++
.../CacheManagerCustomizerNotEnabledTest.java | 37 ++++
...acheManagerCustomizerNotEnabledTestBase.java | 48 ++++++
.../CacheManagerCustomizerOverrideTest.java | 88 ++++++++++
.../customizer/CacheManagerCustomizerTest.java | 63 +++++++
...anagerCustomizerWithoutCacheManagerTest.java | 53 ++++++
38 files changed, 1456 insertions(+), 682 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/main/docs/ehcache-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/main/docs/ehcache-component.adoc b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
index 468aa15..99d970a 100644
--- a/components/camel-ehcache/src/main/docs/ehcache-component.adoc
+++ b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
@@ -37,7 +37,7 @@ format, `?option=value&option=#beanRef&...`
// component options: START
-The Ehcache component supports 6 options which are listed below.
+The Ehcache component supports 7 options which are listed below.
@@ -48,6 +48,7 @@ The Ehcache component supports 6 options which are listed below.
| **cacheManager** (common) | The cache manager | | CacheManager
| **cacheManager Configuration** (common) | The cache manager configuration | | Configuration
| **cacheConfiguration** (common) | The default cache configuration to be used to create caches. | | CacheConfiguration<?,?>
+| **cachesConfigurations** (common) | A map of caches configurations to be used to create caches. | | Map
| **cacheConfigurationUri** (common) | URI pointing to the Ehcache XML configuration file's location | | String
| **resolveProperty Placeholders** (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
|=======================================================================
@@ -70,7 +71,7 @@ with the following path and query parameters:
| **cacheName** | *Required* the cache name | | String
|=======================================================================
-#### Query Parameters (16 parameters):
+#### Query Parameters (17 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
|=======================================================================
@@ -88,6 +89,7 @@ with the following path and query parameters:
| **action** (producer) | To configure the default cache action. If an action is set in the message header then the operation from the header takes precedence. | | String
| **key** (producer) | To configure the default action key. If a key is set in the message header then the key from the header takes precedence. | | Object
| **configuration** (advanced) | The default cache configuration to be used to create caches. | | CacheConfiguration<?,?>
+| **configurations** (advanced) | A map of cache configuration to be used to create caches. | | Map
| **keyType** (advanced) | The cache key type default java.lang.Object | java.lang.Object | String
| **synchronous** (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
| **valueType** (advanced) | The cache value type default java.lang.Object | java.lang.Object | String
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
index cb00afc..2061fa4 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
@@ -171,6 +171,21 @@ public class EhcacheComponent extends DefaultComponent {
return this.configuration.getConfiguration();
}
+ public Map<String, CacheConfiguration<?, ?>> getCachesConfigurations() {
+ return configuration.getConfigurations();
+ }
+
+ /**
+ * A map of caches configurations to be used to create caches.
+ */
+ public void setCachesConfigurations(Map<String, CacheConfiguration<?, ?>> configurations) {
+ configuration.setConfigurations(configurations);
+ }
+
+ public void addCachesConfigurations(Map<String, CacheConfiguration<?, ?>> configurations) {
+ configuration.addConfigurations(configurations);
+ }
+
public String getCacheConfigurationUri() {
return this.configuration.getConfigurationUri();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
index 4e63c0e..aca84bc 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
@@ -17,7 +17,9 @@
package org.apache.camel.component.ehcache;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.camel.RuntimeCamelException;
@@ -47,6 +49,8 @@ public class EhcacheConfiguration implements Cloneable {
private String configurationUri;
@UriParam(label = "advanced")
private CacheConfiguration<?, ?> configuration;
+ @UriParam(label = "advanced")
+ private Map<String, CacheConfiguration<?, ?>> configurations;
@UriParam(label = "advanced", javaType = "java.lang.String", defaultValue = "java.lang.Object")
private Class<?> keyType = Object.class;
@UriParam(label = "advanced", javaType = "java.lang.String", defaultValue = "java.lang.Object")
@@ -218,16 +222,39 @@ public class EhcacheConfiguration implements Cloneable {
/**
* The default cache configuration to be used to create caches.
*/
- public <K, V> void setConfiguration(CacheConfiguration<K, V> configuration) {
+ public void setConfiguration(CacheConfiguration<?, ?> configuration) {
this.configuration = configuration;
}
- public <K, V> CacheConfiguration<K, V> getConfiguration() {
- return (CacheConfiguration<K, V>)configuration;
+ public CacheConfiguration<?, ?> getConfiguration() {
+ return configuration;
+ }
+
+ public boolean hasConfiguration() {
+ return ObjectHelper.isNotEmpty(configuration);
}
- public <K, V> CacheConfiguration<K, V> getMandatoryConfiguration() {
- return ObjectHelper.notNull(getConfiguration(), "CacheConfiguration");
+ public boolean hasConfiguration(String name) {
+ return ObjectHelper.applyIfNotEmpty(configurations, c -> c.containsKey(name), () -> false);
+ }
+
+ /**
+ * A map of cache configuration to be used to create caches.
+ */
+ public Map<String, CacheConfiguration<?, ?>> getConfigurations() {
+ return configurations;
+ }
+
+ public void setConfigurations(Map<String, CacheConfiguration<?, ?>> configurations) {
+ this.configurations = Map.class.cast(configurations);
+ }
+
+ public void addConfigurations(Map<String, CacheConfiguration<?, ?>> configurations) {
+ if (this.configurations == null) {
+ this.configurations = new HashMap<>();
+ }
+
+ this.configurations.putAll(configurations);
}
public Class<?> getKeyType() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
index bc7b8c3..af9a51d 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
@@ -28,8 +28,12 @@ import org.ehcache.CacheManager;
import org.ehcache.UserManagedCache;
import org.ehcache.config.CacheConfiguration;
import org.ehcache.config.builders.UserManagedCacheBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class EhcacheManager implements Service {
+ private static final Logger LOGGER = LoggerFactory.getLogger(EhcacheManager.class);
+
private final EhcacheConfiguration configuration;
private final CacheManager cacheManager;
private final ConcurrentMap<String, UserManagedCache<?, ?>> userCaches;
@@ -59,13 +63,23 @@ public class EhcacheManager implements Service {
public <K, V> Cache<K, V> getCache(String name, Class<K> keyType, Class<V> valueType) throws Exception {
Cache<K, V> cache = cacheManager.getCache(name, keyType, valueType);
if (cache == null && configuration != null && configuration.isCreateCacheIfNotExist()) {
- CacheConfiguration<K, V> cacheConfiguration = configuration.getConfiguration();
+ CacheConfiguration<K, V> cacheConfiguration = null;
+
+ if (configuration.hasConfiguration(name)) {
+ LOGGER.debug("Using custom cache configuration for cache {}", name);
+ cacheConfiguration = CacheConfiguration.class.cast(configuration.getConfigurations().get(name));
+ } else if (configuration.hasConfiguration()) {
+ LOGGER.debug("Using global cache configuration for cache {}", name);
+ cacheConfiguration = CacheConfiguration.class.cast(configuration.getConfiguration());
+ }
if (cacheConfiguration != null) {
cache = cacheManager.createCache(name, cacheConfiguration);
} else {
// If a cache configuration is not provided, create a User Managed
// Cache
+ LOGGER.debug("Using a UserManagedCache for cache {} as no configuration has been found", name);
+
cache = Cache.class.cast(userCaches.computeIfAbsent(
name,
key -> UserManagedCacheBuilder.newUserManagedCacheBuilder(keyType, valueType).build(true)
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheCacheConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheCacheConfigurationTest.java b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheCacheConfigurationTest.java
new file mode 100644
index 0000000..5e5608b
--- /dev/null
+++ b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheCacheConfigurationTest.java
@@ -0,0 +1,167 @@
+/**
+ * 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;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.ehcache.Cache;
+import org.ehcache.CacheManager;
+import org.ehcache.UserManagedCache;
+import org.ehcache.config.ResourcePools;
+import org.ehcache.config.ResourceType;
+import org.ehcache.config.SizedResourcePool;
+import org.ehcache.config.builders.CacheConfigurationBuilder;
+import org.ehcache.config.builders.CacheManagerBuilder;
+import org.ehcache.config.builders.ResourcePoolsBuilder;
+import org.ehcache.config.units.EntryUnit;
+import org.ehcache.config.units.MemoryUnit;
+import org.junit.Test;
+
+public class EhcacheCacheConfigurationTest extends CamelTestSupport {
+ @EndpointInject(uri = "ehcache:myProgrammaticCacheConf?configuration=#myProgrammaticConfiguration")
+ private EhcacheEndpoint ehcacheProgrammaticConf;
+ @EndpointInject(uri = "ehcache:myFileCacheConf?keyType=java.lang.String&valueType=java.lang.String&configurationUri=classpath:ehcache/ehcache-file-config.xml")
+ private EhcacheEndpoint ehcacheFileConf;
+ @EndpointInject(uri = "ehcache:myUserCacheConf")
+ private EhcacheEndpoint ehcacheUserConf;
+ @EndpointInject(uri = "ehcache:myCache?cacheManager=#myCacheManager&keyType=java.lang.String&valueType=java.lang.String")
+ private EhcacheEndpoint ehcacheCacheManager;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind(
+ "myProgrammaticConfiguration",
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(100, EntryUnit.ENTRIES)
+ .offheap(1, MemoryUnit.MB))
+ .build()
+ );
+ registry.bind(
+ "myCacheManager",
+ CacheManagerBuilder.newCacheManagerBuilder()
+ .withCache(
+ "myCache",
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(100, EntryUnit.ENTRIES)
+ .offheap(1, MemoryUnit.MB))
+ ).build(true)
+ );
+
+ return registry;
+ }
+
+ // *****************************
+ // Test
+ // *****************************
+
+ @Test
+ public void testProgrammaticConfiguration() throws Exception {
+ Cache<String, String> cache = getCache(ehcacheProgrammaticConf, "myProgrammaticCacheConf");
+ ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
+
+ SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
+ assertNotNull(h);
+ assertEquals(100, h.getSize());
+ assertEquals(EntryUnit.ENTRIES, h.getUnit());
+
+ SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
+ assertNotNull(o);
+ assertEquals(1, o.getSize());
+ assertEquals(MemoryUnit.MB, o.getUnit());
+ }
+
+ @Test
+ public void testFileConfiguration() throws Exception {
+ Cache<String, String> cache = getCache(ehcacheFileConf, "myFileCacheConf");
+ ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
+
+ SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
+ assertNotNull(h);
+ assertEquals(150, h.getSize());
+ assertEquals(EntryUnit.ENTRIES, h.getUnit());
+ }
+
+ @Test
+ public void testUserConfiguration() throws Exception {
+ fluentTemplate()
+ .withHeader(EhcacheConstants.ACTION, EhcacheConstants.ACTION_PUT)
+ .withHeader(EhcacheConstants.KEY, "user-key")
+ .withBody("user-val")
+ .to("direct:ehcacheUserConf")
+ .send();
+
+ Cache<Object, Object> cache = ehcacheUserConf.getManager().getCache("myUserCacheConf", Object.class, Object.class);
+
+ assertTrue(cache instanceof UserManagedCache);
+ assertEquals("user-val", cache.get("user-key"));
+ }
+
+ @Test
+ public void testCacheManager() throws Exception {
+ assertEquals(
+ context().getRegistry().lookupByNameAndType("myCacheManager", CacheManager.class),
+ ehcacheCacheManager.getManager().getCacheManager()
+ );
+
+ Cache<String, String> cache = getCache(ehcacheCacheManager, "myCache");
+ ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
+
+ SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
+ assertNotNull(h);
+ assertEquals(100, h.getSize());
+ assertEquals(EntryUnit.ENTRIES, h.getUnit());
+
+ SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
+ assertNotNull(o);
+ assertEquals(1, o.getSize());
+ assertEquals(MemoryUnit.MB, o.getUnit());
+ }
+
+ protected Cache<String, String> getCache(EhcacheEndpoint endpoint, String cacheName) throws Exception {
+ return endpoint.getManager().getCache(cacheName, String.class, String.class);
+ }
+
+ // ****************************
+ // Route
+ // ****************************
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:ehcacheProgrammaticConf")
+ .to(ehcacheProgrammaticConf);
+ from("direct:ehcacheFileConf")
+ .to(ehcacheFileConf);
+ from("direct:ehcacheUserConf")
+ .to(ehcacheUserConf);
+ from("direct:ehcacheCacheManager")
+ .to(ehcacheCacheManager);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheConfigurationTest.java b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheConfigurationTest.java
index 6eabab0..6f6e877 100644
--- a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheConfigurationTest.java
+++ b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheConfigurationTest.java
@@ -17,60 +17,56 @@
package org.apache.camel.component.ehcache;
+import java.util.Collections;
+
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.ehcache.Cache;
-import org.ehcache.CacheManager;
-import org.ehcache.UserManagedCache;
-import org.ehcache.config.ResourcePools;
+import org.ehcache.config.CacheRuntimeConfiguration;
import org.ehcache.config.ResourceType;
-import org.ehcache.config.SizedResourcePool;
import org.ehcache.config.builders.CacheConfigurationBuilder;
-import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.EntryUnit;
import org.ehcache.config.units.MemoryUnit;
+import org.ehcache.core.Ehcache;
import org.junit.Test;
public class EhcacheConfigurationTest extends CamelTestSupport {
- @EndpointInject(uri = "ehcache:myProgrammaticCacheConf?configuration=#myProgrammaticConfiguration")
- private EhcacheEndpoint ehcacheProgrammaticConf;
- @EndpointInject(uri = "ehcache:myFileCacheConf?keyType=java.lang.String&valueType=java.lang.String&configurationUri=classpath:ehcache/ehcache-file-config.xml")
- private EhcacheEndpoint ehcacheFileConf;
- @EndpointInject(uri = "ehcache:myUserCacheConf")
- private EhcacheEndpoint ehcacheUserConf;
- @EndpointInject(uri = "ehcache:myCache?cacheManager=#myCacheManager&keyType=java.lang.String&valueType=java.lang.String")
- private EhcacheEndpoint ehcacheCacheManager;
+ @EndpointInject(uri = "ehcache:globalConfig")
+ EhcacheEndpoint globalConfig;
+ @EndpointInject(uri = "ehcache:customConfig")
+ EhcacheEndpoint customConfig;
@Override
protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- registry.bind(
- "myProgrammaticConfiguration",
+ EhcacheComponent component = new EhcacheComponent();
+ component.setCacheConfiguration(
CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class,
String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(100, EntryUnit.ENTRIES)
.offheap(1, MemoryUnit.MB))
- .build()
+ .build()
);
- registry.bind(
- "myCacheManager",
- CacheManagerBuilder.newCacheManagerBuilder()
- .withCache(
- "myCache",
- CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ component.setCachesConfigurations(
+ Collections.singletonMap(
+ "customConfig",
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class,
String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
- .heap(100, EntryUnit.ENTRIES)
- .offheap(1, MemoryUnit.MB))
- ).build(true)
+ .heap(200, EntryUnit.ENTRIES)
+ .offheap(2, MemoryUnit.MB))
+ .build()
+ )
);
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("ehcache", component);
+
return registry;
}
@@ -79,70 +75,24 @@ public class EhcacheConfigurationTest extends CamelTestSupport {
// *****************************
@Test
- public void testProgrammaticConfiguration() throws Exception {
- Cache<String, String> cache = getCache(ehcacheProgrammaticConf, "myProgrammaticCacheConf");
- ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
-
- SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
- assertNotNull(h);
- assertEquals(100, h.getSize());
- assertEquals(EntryUnit.ENTRIES, h.getUnit());
-
- SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
- assertNotNull(o);
- assertEquals(1, o.getSize());
- assertEquals(MemoryUnit.MB, o.getUnit());
- }
-
- @Test
- public void testFileConfiguration() throws Exception {
- Cache<String, String> cache = getCache(ehcacheFileConf, "myFileCacheConf");
- ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
-
- SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
- assertNotNull(h);
- assertEquals(150, h.getSize());
- assertEquals(EntryUnit.ENTRIES, h.getUnit());
- }
-
- @Test
- public void testUserConfiguration() throws Exception {
- fluentTemplate()
- .withHeader(EhcacheConstants.ACTION, EhcacheConstants.ACTION_PUT)
- .withHeader(EhcacheConstants.KEY, "user-key")
- .withBody("user-val")
- .to("direct:ehcacheUserConf")
- .send();
-
- Cache<Object, Object> cache = ehcacheUserConf.getManager().getCache("myUserCacheConf", Object.class, Object.class);
-
- assertTrue(cache instanceof UserManagedCache);
- assertEquals("user-val", cache.get("user-key"));
- }
-
- @Test
- public void testCacheManager() throws Exception {
- assertEquals(
- context().getRegistry().lookupByNameAndType("myCacheManager", CacheManager.class),
- ehcacheCacheManager.getManager().getCacheManager()
- );
-
- Cache<String, String> cache = getCache(ehcacheCacheManager, "myCache");
- ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();
-
- SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
- assertNotNull(h);
- assertEquals(100, h.getSize());
- assertEquals(EntryUnit.ENTRIES, h.getUnit());
-
- SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
- assertNotNull(o);
- assertEquals(1, o.getSize());
- assertEquals(MemoryUnit.MB, o.getUnit());
- }
-
- protected Cache<String, String> getCache(EhcacheEndpoint endpoint, String cacheName) throws Exception {
- return endpoint.getManager().getCache(cacheName, String.class, String.class);
+ public void testConfiguration() throws Exception {
+ Cache<String, String> globalConfigCache = globalConfig.getManager().getCache("globalConfig", String.class, String.class);
+ Cache<String, String> customConfigCache = customConfig.getManager().getCache("customConfig", String.class, String.class);
+
+ assertTrue(globalConfigCache instanceof Ehcache);
+ assertTrue(customConfigCache instanceof Ehcache);
+
+ CacheRuntimeConfiguration<String, String> gc = globalConfigCache.getRuntimeConfiguration();
+ assertEquals(100, gc.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize());
+ assertEquals(EntryUnit.ENTRIES, gc.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getUnit());
+ assertEquals(1, gc.getResourcePools().getPoolForResource(ResourceType.Core.OFFHEAP).getSize());
+ assertEquals(MemoryUnit.MB, gc.getResourcePools().getPoolForResource(ResourceType.Core.OFFHEAP).getUnit());
+
+ CacheRuntimeConfiguration<String, String> cc = customConfigCache.getRuntimeConfiguration();
+ assertEquals(200, cc.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize());
+ assertEquals(EntryUnit.ENTRIES, cc.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getUnit());
+ assertEquals(2, cc.getResourcePools().getPoolForResource(ResourceType.Core.OFFHEAP).getSize());
+ assertEquals(MemoryUnit.MB, cc.getResourcePools().getPoolForResource(ResourceType.Core.OFFHEAP).getUnit());
}
// ****************************
@@ -153,14 +103,9 @@ public class EhcacheConfigurationTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("direct:ehcacheProgrammaticConf")
- .to(ehcacheProgrammaticConf);
- from("direct:ehcacheFileConf")
- .to(ehcacheFileConf);
- from("direct:ehcacheUserConf")
- .to(ehcacheUserConf);
- from("direct:ehcacheCacheManager")
- .to(ehcacheCacheManager);
+ from("direct:ehcache")
+ .to(globalConfig)
+ .to(customConfig);
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
index b14da5f..4f7288d 100644
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
@@ -16,9 +16,10 @@
*/
package org.apache.camel.component.ehcache.springboot;
+import java.util.Map;
import java.util.Set;
import javax.annotation.Generated;
-import org.apache.camel.component.ehcache.EhcacheComponent;
+
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
import org.ehcache.CacheManager;
import org.ehcache.config.CacheConfiguration;
@@ -61,6 +62,10 @@ public class EhcacheComponentConfiguration
@NestedConfigurationProperty
private CacheConfiguration<?, ?> cacheConfiguration;
/**
+ * A map of caches configurations to be used to create caches.
+ */
+ private Map<String, CacheConfiguration<?, ?>> cachesConfigurations;
+ /**
* URI pointing to the Ehcache XML configuration file's location
*/
private String cacheConfigurationUri;
@@ -106,6 +111,15 @@ public class EhcacheComponentConfiguration
this.cacheConfiguration = cacheConfiguration;
}
+ public Map<String, CacheConfiguration<?, ?>> getCachesConfigurations() {
+ return cachesConfigurations;
+ }
+
+ public void setCachesConfigurations(
+ Map<String, CacheConfiguration<?, ?>> cachesConfigurations) {
+ this.cachesConfigurations = cachesConfigurations;
+ }
+
public String getCacheConfigurationUri() {
return cacheConfigurationUri;
}
@@ -166,6 +180,7 @@ public class EhcacheComponentConfiguration
* The default cache configuration to be used to create caches.
*/
private CacheConfiguration configuration;
+ private Map configurations;
/**
* The cache key type, default "java.lang.Object"
*/
@@ -267,6 +282,14 @@ public class EhcacheComponentConfiguration
this.configuration = configuration;
}
+ public Map getConfigurations() {
+ return configurations;
+ }
+
+ public void setConfigurations(Map configurations) {
+ this.configurations = configurations;
+ }
+
public String getKeyType() {
return keyType;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizer.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizer.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizer.java
new file mode 100644
index 0000000..f82d857
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizer.java
@@ -0,0 +1,100 @@
+/**
+ * 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 java.util.Map;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.component.ehcache.springboot.EhcacheComponentAutoConfiguration;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.ehcache.config.CacheConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+
+/**
+ * A simple implementation of {@link ComponentCustomizer} that auto discovers a
+ * {@link org.ehcache.config.CacheConfiguration} instance and bind it to the
+ * {@link EhcacheComponent} component.
+ *
+ * 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-configuration.enabled = true/false
+ */
+@Order(Ordered.LOWEST_PRECEDENCE)
+@Configuration
+@Conditional(CacheConfigurationCustomizer.NestedConditions.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@AutoConfigureBefore(EhcacheComponentAutoConfiguration.class)
+@EnableConfigurationProperties(CacheConfigurationCustomizerConfiguration.class)
+public class CacheConfigurationCustomizer implements HasId, ComponentCustomizer<EhcacheComponent> {
+ @Autowired(required = false)
+ private Map<String, CacheConfiguration<?, ?>> configurations;
+ @Autowired
+ private CacheConfigurationCustomizerConfiguration configuration;
+
+ @Override
+ public void customize(EhcacheComponent component) {
+ if (configurations != null && configuration.getMode() == CacheConfigurationCustomizerConfiguration.Mode.APPEND) {
+ component.addCachesConfigurations(configurations);
+ }
+ if (configurations != null && configuration.getMode() == CacheConfigurationCustomizerConfiguration.Mode.REPLACE) {
+ component.setCachesConfigurations(configurations);
+ }
+ }
+
+ @Override
+ public String getId() {
+ return "camel.component.ehcache.customizer.cache-configuration";
+ }
+
+ // *************************************************************************
+ // By default ConditionalOnBean works using an OR operation so if you list
+ // a number of classes, the condition succeeds if a single instance of any
+ // class is found.
+ //
+ // A workaround is to use AllNestedConditions and creates some dummy classes
+ // annotated with @ConditionalOnBean
+ //
+ // This should be fixed in spring-boot 2.0 where ConditionalOnBean uses and
+ // AND operation instead of the OR as it does today.
+ // *************************************************************************
+
+ static class NestedConditions extends AllNestedConditions {
+ public NestedConditions() {
+ super(ConfigurationPhase.REGISTER_BEAN);
+ }
+
+ @ConditionalOnBean(CamelAutoConfiguration.class)
+ static class OnCamelAutoConfiguration {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerConfiguration.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerConfiguration.java
new file mode 100644
index 0000000..df2f290
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerConfiguration.java
@@ -0,0 +1,54 @@
+/**
+ * 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-configuration")
+public class CacheConfigurationCustomizerConfiguration {
+ /**
+ * Enable or disable the cache-configuration customizer.
+ */
+ private boolean enabled = true;
+
+ /**
+ * Configure if the cache configurations have be added or they have to replace those already configured on the component.
+ */
+ private Mode mode = Mode.APPEND;
+
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Mode getMode() {
+ return mode;
+ }
+
+ public void setMode(Mode mode) {
+ this.mode = mode;
+ }
+
+ public enum Mode {
+ REPLACE,
+ APPEND
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/resources/META-INF/spring.factories
index 3e2aa80..572e1b0 100644
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,5 @@
## ---------------------------------------------------------------------------
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.camel.component.ehcache.springboot.customizer.CacheManagerCustomizer,\
+org.apache.camel.component.ehcache.springboot.customizer.CacheConfigurationCustomizer,\
org.apache.camel.component.ehcache.springboot.EhcacheComponentAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledOnComponentTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledOnComponentTest.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledOnComponentTest.java
deleted file mode 100644
index b1ac948..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledOnComponentTest.java
+++ /dev/null
@@ -1,38 +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 = {
- CacheManagerCustomizerEnabledTestBase.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.component.customizer.enabled=false",
- "camel.component.ehcache.customizer.enabled=true"
- })
-public class CacheManagerCustomizerEnabledOnComponentTest extends CacheManagerCustomizerEnabledTestBase {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTest.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTest.java
deleted file mode 100644
index 860c6b7..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTest.java
+++ /dev/null
@@ -1,39 +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 = {
- CacheManagerCustomizerEnabledTestBase.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.component.customizer.enabled=false",
- "camel.component.ehcache.customizer.enabled=false",
- "camel.component.ehcache.customizer.cache-manager.enabled=true"
- })
-public class CacheManagerCustomizerEnabledTest extends CacheManagerCustomizerEnabledTestBase {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTestBase.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTestBase.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTestBase.java
deleted file mode 100644
index 5851f3c..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerEnabledTestBase.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 CacheManagerCustomizerEnabledTestBase {
- @Autowired
- CacheManager cacheManager;
- @Autowired
- EhcacheComponent component;
-
- @Test
- public void testComponentConfiguration() throws Exception {
- Assert.assertNotNull(cacheManager);
- Assert.assertNotNull(component);
- Assert.assertNotNull(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/f3004024/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
deleted file mode 100644
index 598e6cb..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNoOverrideTest.java
+++ /dev/null
@@ -1,87 +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.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/f3004024/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
deleted file mode 100644
index c7bdd9f..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledGlobalTest.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 = {
- 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/f3004024/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
deleted file mode 100644
index 330ba6e..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledOnComponentTest.java
+++ /dev/null
@@ -1,38 +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 = {
- CacheManagerCustomizerNotEnabledTestBase.TestConfiguration.class
- },
- properties = {
- "debug=false",
- "camel.component.customizer.enabled=true",
- "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/f3004024/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
deleted file mode 100644
index 76d1791..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTest.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 = {
- 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/f3004024/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
deleted file mode 100644
index 0a4b6a1..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerNotEnabledTestBase.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 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/f3004024/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
deleted file mode 100644
index 086bab5..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerOverrideTest.java
+++ /dev/null
@@ -1,87 +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.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/f3004024/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
deleted file mode 100644
index 6a74037..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerTest.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 = {
- 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/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerWithoutCacheManagerTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerWithoutCacheManagerTest.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerWithoutCacheManagerTest.java
deleted file mode 100644
index c7daab2..0000000
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/CacheManagerCustomizerWithoutCacheManagerTest.java
+++ /dev/null
@@ -1,53 +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.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.Configuration;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootApplication
-@SpringBootTest(
- classes = {
- CacheManagerCustomizerWithoutCacheManagerTest.TestConfiguration.class
- },
- properties = {
- "debug=false",
- })
-public class CacheManagerCustomizerWithoutCacheManagerTest {
- @Autowired
- EhcacheComponent component;
-
- @Test
- public void testComponentConfiguration() throws Exception {
- Assert.assertNotNull(component);
- Assert.assertNull(component.getCacheManager());
- }
-
- @Configuration
- public static class TestConfiguration {
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledAppendTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledAppendTest.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledAppendTest.java
new file mode 100644
index 0000000..4ea7a15
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledAppendTest.java
@@ -0,0 +1,121 @@
+/**
+ * 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 java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.ehcache.config.CacheConfiguration;
+import org.ehcache.config.builders.CacheConfigurationBuilder;
+import org.ehcache.config.builders.ResourcePoolsBuilder;
+import org.ehcache.config.units.EntryUnit;
+import org.ehcache.config.units.MemoryUnit;
+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.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 = {
+ CacheConfigurationCustomizerEnabledAppendTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.component.customizer.enabled=false",
+ "camel.component.ehcache.customizer.enabled=true",
+ "camel.component.ehcache.customizer.cache-configuration.enabled=true",
+ "camel.component.ehcache.customizer.cache-configuration.mode=APPEND"
+ })
+public class CacheConfigurationCustomizerEnabledAppendTest {
+ private static final String CACHE_CONFIG_ID = UUID.randomUUID().toString();
+
+ @Autowired
+ Map<String, CacheConfiguration<?, ?>> configurations;
+ @Autowired
+ EhcacheComponent component;
+
+ @Test
+ public void testComponentConfiguration() throws Exception {
+ Assert.assertNotNull(configurations);
+ Assert.assertEquals(2, configurations.size());
+ Assert.assertNotNull(component);
+ Assert.assertNotNull(component.getCachesConfigurations());
+ Assert.assertEquals(3, component.getCachesConfigurations().size());
+ Assert.assertTrue(component.getCachesConfigurations().containsKey("myConfig1"));
+ Assert.assertTrue(component.getCachesConfigurations().containsKey("myConfig2"));
+ Assert.assertTrue(component.getCachesConfigurations().containsKey(CACHE_CONFIG_ID));
+ }
+
+ @Configuration
+ static class TestConfiguration {
+ @Order(Ordered.HIGHEST_PRECEDENCE)
+ @Bean
+ public ComponentCustomizer<EhcacheComponent> customizer() {
+ return new ComponentCustomizer<EhcacheComponent>() {
+ @Override
+ public void customize(EhcacheComponent component) {
+ component.addCachesConfigurations(Collections.singletonMap(
+ CACHE_CONFIG_ID,
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(2100, EntryUnit.ENTRIES)
+ .offheap(2, MemoryUnit.MB))
+ .build()
+ ));
+ }
+ };
+ }
+
+ @Bean
+ public CacheConfiguration<?, ?> myConfig1() {
+ return CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(100, EntryUnit.ENTRIES)
+ .offheap(1, MemoryUnit.MB))
+ .build();
+ }
+
+ @Bean
+ public CacheConfiguration<?, ?> myConfig2() {
+ return CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(2100, EntryUnit.ENTRIES)
+ .offheap(2, MemoryUnit.MB))
+ .build();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/f3004024/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledReplaceTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledReplaceTest.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledReplaceTest.java
new file mode 100644
index 0000000..7471d19
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/test/java/org/apache/camel/component/ehcache/springboot/customizer/CacheConfigurationCustomizerEnabledReplaceTest.java
@@ -0,0 +1,121 @@
+/**
+ * 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 java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.ehcache.config.CacheConfiguration;
+import org.ehcache.config.builders.CacheConfigurationBuilder;
+import org.ehcache.config.builders.ResourcePoolsBuilder;
+import org.ehcache.config.units.EntryUnit;
+import org.ehcache.config.units.MemoryUnit;
+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.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 = {
+ CacheConfigurationCustomizerEnabledReplaceTest.TestConfiguration.class,
+ },
+ properties = {
+ "debug=false",
+ "camel.component.customizer.enabled=false",
+ "camel.component.ehcache.customizer.enabled=true",
+ "camel.component.ehcache.customizer.cache-configuration.enabled=true",
+ "camel.component.ehcache.customizer.cache-configuration.mode=REPLACE"
+ })
+public class CacheConfigurationCustomizerEnabledReplaceTest {
+ private static final String CACHE_CONFIG_ID = UUID.randomUUID().toString();
+
+ @Autowired
+ Map<String, CacheConfiguration<?, ?>> configurations;
+ @Autowired
+ EhcacheComponent component;
+
+ @Test
+ public void testComponentConfiguration() throws Exception {
+ Assert.assertNotNull(configurations);
+ Assert.assertEquals(2, configurations.size());
+ Assert.assertNotNull(component);
+ Assert.assertNotNull(component.getCachesConfigurations());
+ Assert.assertEquals(2, component.getCachesConfigurations().size());
+ Assert.assertTrue(component.getCachesConfigurations().containsKey("myConfig1"));
+ Assert.assertTrue(component.getCachesConfigurations().containsKey("myConfig2"));
+ Assert.assertFalse(component.getCachesConfigurations().containsKey(CACHE_CONFIG_ID));
+ }
+
+ @Configuration
+ static class TestConfiguration {
+ @Order(Ordered.HIGHEST_PRECEDENCE)
+ @Bean
+ public ComponentCustomizer<EhcacheComponent> customizer() {
+ return new ComponentCustomizer<EhcacheComponent>() {
+ @Override
+ public void customize(EhcacheComponent component) {
+ component.addCachesConfigurations(Collections.singletonMap(
+ CACHE_CONFIG_ID,
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(2100, EntryUnit.ENTRIES)
+ .offheap(2, MemoryUnit.MB))
+ .build()
+ ));
+ }
+ };
+ }
+
+ @Bean
+ public CacheConfiguration<?, ?> myConfig1() {
+ return CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(100, EntryUnit.ENTRIES)
+ .offheap(1, MemoryUnit.MB))
+ .build();
+ }
+
+ @Bean
+ public CacheConfiguration<?, ?> myConfig2() {
+ return CacheConfigurationBuilder.newCacheConfigurationBuilder(
+ String.class,
+ String.class,
+ ResourcePoolsBuilder.newResourcePoolsBuilder()
+ .heap(2100, EntryUnit.ENTRIES)
+ .offheap(2, MemoryUnit.MB))
+ .build();
+ }
+ }
+}
\ No newline at end of file