Browse Source

JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider

Issue: SPR-13342
pull/856/head
Juergen Hoeller 11 years ago
parent
commit
3a5cc3df80
  1. 17
      spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java
  2. 9
      spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java

17
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java vendored

@ -16,9 +16,11 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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);

9
spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3Tests.java vendored

@ -16,12 +16,21 @@ @@ -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");
}
}

Loading…
Cancel
Save