Search in sources :

Example 1 with DefaultJCacheOperationSource

use of org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource in project spring-framework by spring-projects.

the class JCacheJavaConfigTests method bothSetOnlyResolverIsUsed.

@Test
public void bothSetOnlyResolverIsUsed() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfigSupport.class);
    DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
    assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
    assertSame(context.getBean("keyGenerator"), cos.getKeyGenerator());
    assertSame(context.getBean("exceptionCacheResolver"), cos.getExceptionCacheResolver());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultJCacheOperationSource(org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource) Test(org.junit.Test)

Example 2 with DefaultJCacheOperationSource

use of org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource in project spring-framework by spring-projects.

the class JCacheJavaConfigTests method fullCachingConfig.

@Test
public void fullCachingConfig() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
    DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
    assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
    assertSame(context.getBean("cacheResolver", CacheResolver.class), cos.getCacheResolver());
    assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class), cos.getExceptionCacheResolver());
    JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
    assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JCacheInterceptor(org.springframework.cache.jcache.interceptor.JCacheInterceptor) DefaultJCacheOperationSource(org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource) SimpleCacheErrorHandler(org.springframework.cache.interceptor.SimpleCacheErrorHandler) CacheErrorHandler(org.springframework.cache.interceptor.CacheErrorHandler) SimpleCacheResolver(org.springframework.cache.interceptor.SimpleCacheResolver) CacheResolver(org.springframework.cache.interceptor.CacheResolver) NamedCacheResolver(org.springframework.cache.interceptor.NamedCacheResolver) SomeKeyGenerator(org.springframework.cache.config.SomeKeyGenerator) KeyGenerator(org.springframework.cache.interceptor.KeyGenerator) SimpleKeyGenerator(org.springframework.cache.interceptor.SimpleKeyGenerator) Test(org.junit.Test)

Example 3 with DefaultJCacheOperationSource

use of org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource in project spring-framework by spring-projects.

the class JCacheJavaConfigTests method emptyConfigSupport.

@Test
public void emptyConfigSupport() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
    DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
    assertNotNull(cos.getCacheResolver());
    assertEquals(SimpleCacheResolver.class, cos.getCacheResolver().getClass());
    assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager());
    assertNull(cos.getExceptionCacheResolver());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultJCacheOperationSource(org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) NoOpCacheManager(org.springframework.cache.support.NoOpCacheManager) Test(org.junit.Test)

Example 4 with DefaultJCacheOperationSource

use of org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource in project spring-framework by spring-projects.

the class JCacheJavaConfigTests method exceptionCacheResolverLazilyRequired.

@Test
public void exceptionCacheResolverLazilyRequired() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class);
    try {
        DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
        assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
        JCacheableService<?> service = context.getBean(JCacheableService.class);
        service.cache("id");
        // This call requires the cache manager to be set
        thrown.expect(IllegalStateException.class);
        service.cacheWithException("test", false);
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultJCacheOperationSource(org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource) Test(org.junit.Test)

Example 5 with DefaultJCacheOperationSource

use of org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource in project spring-framework by spring-projects.

the class JCacheNamespaceDrivenTests method cacheResolver.

@Test
public void cacheResolver() {
    ConfigurableApplicationContext context = new GenericXmlApplicationContext("/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml");
    DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class);
    assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DefaultJCacheOperationSource(org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DefaultJCacheOperationSource (org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 CacheManager (org.springframework.cache.CacheManager)1 ConcurrentMapCacheManager (org.springframework.cache.concurrent.ConcurrentMapCacheManager)1 SomeKeyGenerator (org.springframework.cache.config.SomeKeyGenerator)1 CacheErrorHandler (org.springframework.cache.interceptor.CacheErrorHandler)1 CacheResolver (org.springframework.cache.interceptor.CacheResolver)1 KeyGenerator (org.springframework.cache.interceptor.KeyGenerator)1 NamedCacheResolver (org.springframework.cache.interceptor.NamedCacheResolver)1 SimpleCacheErrorHandler (org.springframework.cache.interceptor.SimpleCacheErrorHandler)1 SimpleCacheResolver (org.springframework.cache.interceptor.SimpleCacheResolver)1 SimpleKeyGenerator (org.springframework.cache.interceptor.SimpleKeyGenerator)1 JCacheInterceptor (org.springframework.cache.jcache.interceptor.JCacheInterceptor)1 NoOpCacheManager (org.springframework.cache.support.NoOpCacheManager)1 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)1 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)1