Search in sources :

Example 1 with DefaultJCacheOperationSource

use of cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource in project today-infrastructure by TAKETODAY.

the class JCacheJavaConfigTests method fullCachingConfig.

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

Example 2 with DefaultJCacheOperationSource

use of cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource in project today-infrastructure by TAKETODAY.

the class JCacheJavaConfigTests method exceptionCacheResolverLazilyRequired.

@Test
public void exceptionCacheResolverLazilyRequired() {
    try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class)) {
        DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
        assertThat(cos.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
        JCacheableService<?> service = context.getBean(JCacheableService.class);
        service.cache("id");
        // This call requires the cache manager to be set
        assertThatIllegalStateException().isThrownBy(() -> service.cacheWithException("test", false));
    }
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) DefaultJCacheOperationSource(cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultJCacheOperationSource

use of cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource in project today-infrastructure by TAKETODAY.

the class JCacheJavaConfigTests method bothSetOnlyResolverIsUsed.

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

Example 4 with DefaultJCacheOperationSource

use of cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource in project today-framework by TAKETODAY.

the class JCacheJavaConfigTests method emptyConfigSupport.

@Test
public void emptyConfigSupport() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
    DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
    assertThat(cos.getCacheResolver()).isNotNull();
    assertThat(cos.getCacheResolver().getClass()).isEqualTo(SimpleCacheResolver.class);
    assertThat(((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager()).isSameAs(context.getBean(CacheManager.class));
    assertThat(cos.getExceptionCacheResolver()).isNull();
    context.close();
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) DefaultJCacheOperationSource(cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource) NoOpCacheManager(cn.taketoday.cache.support.NoOpCacheManager) ConcurrentMapCacheManager(cn.taketoday.cache.concurrent.ConcurrentMapCacheManager) SimpleCacheManager(cn.taketoday.cache.support.SimpleCacheManager) CacheManager(cn.taketoday.cache.CacheManager) SimpleCacheResolver(cn.taketoday.cache.interceptor.SimpleCacheResolver) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultJCacheOperationSource

use of cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource in project today-framework by TAKETODAY.

the class JCacheJavaConfigTests method bothSetOnlyResolverIsUsed.

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

Aggregations

DefaultJCacheOperationSource (cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource)10 Test (org.junit.jupiter.api.Test)10 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)8 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)8 SimpleCacheResolver (cn.taketoday.cache.interceptor.SimpleCacheResolver)4 CacheManager (cn.taketoday.cache.CacheManager)2 ConcurrentMapCacheManager (cn.taketoday.cache.concurrent.ConcurrentMapCacheManager)2 CacheErrorHandler (cn.taketoday.cache.interceptor.CacheErrorHandler)2 CacheResolver (cn.taketoday.cache.interceptor.CacheResolver)2 KeyGenerator (cn.taketoday.cache.interceptor.KeyGenerator)2 NamedCacheResolver (cn.taketoday.cache.interceptor.NamedCacheResolver)2 SimpleCacheErrorHandler (cn.taketoday.cache.interceptor.SimpleCacheErrorHandler)2 SimpleKeyGenerator (cn.taketoday.cache.interceptor.SimpleKeyGenerator)2 JCacheInterceptor (cn.taketoday.cache.jcache.interceptor.JCacheInterceptor)2 NoOpCacheManager (cn.taketoday.cache.support.NoOpCacheManager)2 SimpleCacheManager (cn.taketoday.cache.support.SimpleCacheManager)2 GenericXmlApplicationContext (cn.taketoday.context.support.GenericXmlApplicationContext)2 SomeKeyGenerator (cn.taketoday.contextsupport.testfixture.cache.SomeKeyGenerator)2