JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider

Issue: SPR-13342
This commit is contained in:
Juergen Hoeller 2015-08-12 23:09:16 +02:00
parent f5210ce0c8
commit 3a5cc3df80
2 changed files with 24 additions and 2 deletions

View File

@ -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<Object, Object> mutableConfiguration = new MutableConfiguration<Object, Object>();
mutableConfiguration.setStoreByValue(false); // otherwise value has to be Serializable
cacheManager.createCache("testCache", mutableConfiguration);

View File

@ -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");
}
}