Search in sources :

Example 1 with JCacheInterceptor

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

the class JCacheCustomInterceptorTests method onlyOneInterceptorIsAvailable.

@Test
public void onlyOneInterceptorIsAvailable() {
    Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
    assertThat(interceptors.size()).as("Only one interceptor should be defined").isEqualTo(1);
    JCacheInterceptor interceptor = interceptors.values().iterator().next();
    assertThat(interceptor.getClass()).as("Custom interceptor not defined").isEqualTo(TestCacheInterceptor.class);
}
Also used : JCacheInterceptor(cn.taketoday.cache.jcache.interceptor.JCacheInterceptor) Test(org.junit.jupiter.api.Test)

Example 2 with JCacheInterceptor

use of cn.taketoday.cache.jcache.interceptor.JCacheInterceptor 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 3 with JCacheInterceptor

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

the class JCacheCustomInterceptorTests method onlyOneInterceptorIsAvailable.

@Test
public void onlyOneInterceptorIsAvailable() {
    Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
    assertThat(interceptors.size()).as("Only one interceptor should be defined").isEqualTo(1);
    JCacheInterceptor interceptor = interceptors.values().iterator().next();
    assertThat(interceptor.getClass()).as("Custom interceptor not defined").isEqualTo(TestCacheInterceptor.class);
}
Also used : JCacheInterceptor(cn.taketoday.cache.jcache.interceptor.JCacheInterceptor) Test(org.junit.jupiter.api.Test)

Example 4 with JCacheInterceptor

use of cn.taketoday.cache.jcache.interceptor.JCacheInterceptor in project today-framework 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 5 with JCacheInterceptor

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

the class JCacheNamespaceDrivenTests method testCacheErrorHandler.

@Test
public void testCacheErrorHandler() {
    JCacheInterceptor ci = ctx.getBean(JCacheInterceptor.class);
    assertThat(ci.getErrorHandler()).isSameAs(ctx.getBean("errorHandler", CacheErrorHandler.class));
}
Also used : JCacheInterceptor(cn.taketoday.cache.jcache.interceptor.JCacheInterceptor) CacheErrorHandler(cn.taketoday.cache.interceptor.CacheErrorHandler) Test(org.junit.jupiter.api.Test)

Aggregations

JCacheInterceptor (cn.taketoday.cache.jcache.interceptor.JCacheInterceptor)8 Test (org.junit.jupiter.api.Test)6 CacheErrorHandler (cn.taketoday.cache.interceptor.CacheErrorHandler)4 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 SimpleCacheResolver (cn.taketoday.cache.interceptor.SimpleCacheResolver)2 SimpleKeyGenerator (cn.taketoday.cache.interceptor.SimpleKeyGenerator)2 DefaultJCacheOperationSource (cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 Bean (cn.taketoday.context.annotation.Bean)2 Role (cn.taketoday.context.annotation.Role)2 SomeKeyGenerator (cn.taketoday.contextsupport.testfixture.cache.SomeKeyGenerator)2