Skip to content

Commit 3a5cc3d

Browse files
committed
JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider
Issue: SPR-13342
1 parent f5210ce commit 3a5cc3d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package org.springframework.cache.jcache;
1818

19+
import javax.annotation.Resource;
1920
import javax.cache.CacheManager;
2021
import javax.cache.Caching;
2122
import javax.cache.configuration.MutableConfiguration;
23+
import javax.cache.spi.CachingProvider;
2224

2325
import org.junit.After;
2426
import org.junit.Ignore;
@@ -48,7 +50,10 @@ public class JCacheEhCacheTests extends AbstractAnnotationTests {
4850

4951
@Override
5052
protected ConfigurableApplicationContext getApplicationContext() {
51-
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableCachingConfig.class);
53+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
54+
context.getBeanFactory().registerSingleton("cachingProvider", getCachingProvider());
55+
context.register(EnableCachingConfig.class);
56+
context.refresh();
5257
jCacheManager = context.getBean("jCacheManager", CacheManager.class);
5358
return context;
5459
}
@@ -68,10 +73,18 @@ public void testCustomCacheManager() {
6873
}
6974

7075

76+
protected CachingProvider getCachingProvider() {
77+
return Caching.getCachingProvider();
78+
}
79+
80+
7181
@Configuration
7282
@EnableCaching
7383
static class EnableCachingConfig extends CachingConfigurerSupport {
7484

85+
@Resource
86+
CachingProvider cachingProvider;
87+
7588
@Override
7689
@Bean
7790
public org.springframework.cache.CacheManager cacheManager() {
@@ -80,7 +93,7 @@ public org.springframework.cache.CacheManager cacheManager() {
8093

8194
@Bean
8295
public CacheManager jCacheManager() {
83-
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
96+
CacheManager cacheManager = this.cachingProvider.getCacheManager();
8497
MutableConfiguration<Object, Object> mutableConfiguration = new MutableConfiguration<Object, Object>();
8598
mutableConfiguration.setStoreByValue(false); // otherwise value has to be Serializable
8699
cacheManager.createCache("testCache", mutableConfiguration);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@
1616

1717
package org.springframework.cache.jcache;
1818

19+
import javax.cache.Caching;
20+
import javax.cache.spi.CachingProvider;
21+
1922
/**
2023
* Just here to be run against EHCache 3, whereas the original JCacheEhCacheTests
2124
* runs against EhCache 2.x with the EhCache-JCache add-on.
2225
*
2326
* @author Juergen Hoeller
27+
* @since 4.2.1
2428
*/
2529
public class JCacheEhCache3Tests extends JCacheEhCacheTests {
2630

31+
@Override
32+
protected CachingProvider getCachingProvider() {
33+
return Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
34+
}
35+
2736
}

0 commit comments

Comments
 (0)