From 3a5cc3df80347422681d4c6add2f6031c2070704 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Aug 2015 23:09:16 +0200 Subject: [PATCH] JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider Issue: SPR-13342 --- .../cache/jcache/JCacheEhCacheTests.java | 17 +++++++++++++++-- .../cache/jcache/JCacheEhCache3Tests.java | 9 +++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java index 03f9927828a..da5ae2d0dd4 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java @@ -16,9 +16,11 @@ package org.springframework.cache.jcache; +import javax.annotation.Resource; import javax.cache.CacheManager; import javax.cache.Caching; import javax.cache.configuration.MutableConfiguration; +import javax.cache.spi.CachingProvider; import org.junit.After; import org.junit.Ignore; @@ -48,7 +50,10 @@ public class JCacheEhCacheTests extends AbstractAnnotationTests { @Override protected ConfigurableApplicationContext getApplicationContext() { - ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableCachingConfig.class); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.getBeanFactory().registerSingleton("cachingProvider", getCachingProvider()); + context.register(EnableCachingConfig.class); + context.refresh(); jCacheManager = context.getBean("jCacheManager", CacheManager.class); return context; } @@ -68,10 +73,18 @@ public class JCacheEhCacheTests extends AbstractAnnotationTests { } + protected CachingProvider getCachingProvider() { + return Caching.getCachingProvider(); + } + + @Configuration @EnableCaching static class EnableCachingConfig extends CachingConfigurerSupport { + @Resource + CachingProvider cachingProvider; + @Override @Bean public org.springframework.cache.CacheManager cacheManager() { @@ -80,7 +93,7 @@ public class JCacheEhCacheTests extends AbstractAnnotationTests { @Bean public CacheManager jCacheManager() { - CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); + CacheManager cacheManager = this.cachingProvider.getCacheManager(); MutableConfiguration mutableConfiguration = new MutableConfiguration(); mutableConfiguration.setStoreByValue(false); // otherwise value has to be Serializable cacheManager.createCache("testCache", mutableConfiguration); diff --git a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java index 6d54f9a797c..a000d369263 100644 --- a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java +++ b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java @@ -16,12 +16,21 @@ package org.springframework.cache.jcache; +import javax.cache.Caching; +import javax.cache.spi.CachingProvider; + /** * Just here to be run against EHCache 3, whereas the original JCacheEhCacheTests * runs against EhCache 2.x with the EhCache-JCache add-on. * * @author Juergen Hoeller + * @since 4.2.1 */ public class JCacheEhCache3Tests extends JCacheEhCacheTests { + @Override + protected CachingProvider getCachingProvider() { + return Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider"); + } + }