@Test public void jCacheCacheWithCachesAndCustomConfig() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=one", "spring.cache.cacheNames[1]=two"); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames(), containsInAnyOrder("one", "two")); assertThat(cacheManager.getCacheNames(), hasSize(2)); CompleteConfiguration<?, ?> defaultCacheConfiguration = this.context .getBean(CompleteConfiguration.class); verify(cacheManager.getCacheManager()).createCache("one", defaultCacheConfiguration); verify(cacheManager.getCacheManager()).createCache("two", defaultCacheConfiguration); }
@Test public void jCacheCacheWithProvider() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames()).isEmpty(); assertThat(this.context.getBean(javax.cache.CacheManager.class)) .isEqualTo(cacheManager.getCacheManager()); }
@Test public void jCacheCacheWithCaches() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar"); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar"); }
@Test public void jCacheCacheWithCachesAndCustomConfig() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=one", "spring.cache.cacheNames[1]=two"); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames()).containsOnly("one", "two"); CompleteConfiguration<?, ?> defaultCacheConfiguration = this.context .getBean(CompleteConfiguration.class); verify(cacheManager.getCacheManager()).createCache("one", defaultCacheConfiguration); verify(cacheManager.getCacheManager()).createCache("two", defaultCacheConfiguration); }
@Test public void jCacheCacheWithConfig() throws IOException { String cachingProviderFqn = MockCachingProvider.class.getName(); String configLocation = "org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml"; load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); Resource configResource = new ClassPathResource(configLocation); assertThat(cacheManager.getCacheManager().getURI()) .isEqualTo(configResource.getURI()); }
@Test public void jCacheCacheWithWrongConfig() { String cachingProviderFqn = MockCachingProvider.class.getName(); String configLocation = "org/springframework/boot/autoconfigure/cache/does-not-exist.xml"; this.thrown.expect(BeanCreationException.class); this.thrown.expectMessage("does not exist"); this.thrown.expectMessage(configLocation); load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation); }
@Test public void jCacheCacheWithProvider() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames(), empty()); assertThat(this.context.getBean(javax.cache.CacheManager.class), equalTo(cacheManager.getCacheManager())); }
@Test public void jCacheCacheWithCaches() { String cachingProviderFqn = MockCachingProvider.class.getName(); load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar"); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheNames(), containsInAnyOrder("foo", "bar")); assertThat(cacheManager.getCacheNames(), hasSize(2)); }
@Test public void jCacheCacheWithConfig() throws IOException { String cachingProviderFqn = MockCachingProvider.class.getName(); String configLocation = "org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml"; load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); Resource configResource = new ClassPathResource(configLocation); assertThat(cacheManager.getCacheManager().getURI(), equalTo(configResource.getURI())); }