Search in sources :

Example 1 with CacheOperation

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

the class AnnotationCacheOperationSourceTests method multipleComposedAnnotations.

@Test
public void multipleComposedAnnotations() {
    Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
    Iterator<CacheOperation> it = ops.iterator();
    CacheOperation cacheOperation = it.next();
    assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
    assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("directly declared"));
    assertThat(cacheOperation.getKey()).isEqualTo("");
    cacheOperation = it.next();
    assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
    assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCache"));
    assertThat(cacheOperation.getKey()).isEqualTo("composedKey");
    cacheOperation = it.next();
    assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
    assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("foo"));
    assertThat(cacheOperation.getKey()).isEqualTo("");
    cacheOperation = it.next();
    assertThat(cacheOperation).isInstanceOf(CacheEvictOperation.class);
    assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCacheEvict"));
    assertThat(cacheOperation.getKey()).isEqualTo("composedEvictionKey");
}
Also used : CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Test(org.junit.jupiter.api.Test)

Example 2 with CacheOperation

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

the class AnnotationCacheOperationSourceTests method customKeyGeneratorInherited.

@Test
public void customKeyGeneratorInherited() {
    Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGeneratorInherited", 1);
    CacheOperation cacheOperation = ops.iterator().next();
    assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
}
Also used : CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Test(org.junit.jupiter.api.Test)

Example 3 with CacheOperation

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

the class AnnotationCacheOperationSourceTests method cacheConfigFromInterface.

@Test
public void cacheConfigFromInterface() {
    Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheConfig");
    CacheOperation cacheOperation = ops.iterator().next();
    assertSharedConfig(cacheOperation, "", "", "", "myCache");
}
Also used : CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Test(org.junit.jupiter.api.Test)

Example 4 with CacheOperation

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

the class AnnotationCacheOperationSourceTests method validateNoCacheIsValid.

@Test
public void validateNoCacheIsValid() {
    // Valid as a CacheResolver might return the cache names to use with other info
    Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified");
    CacheOperation cacheOperation = ops.iterator().next();
    assertThat(cacheOperation.getCacheNames()).as("cache names set must not be null").isNotNull();
    assertThat(cacheOperation.getCacheNames().size()).as("no cache names specified").isEqualTo(0);
}
Also used : CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Test(org.junit.jupiter.api.Test)

Example 5 with CacheOperation

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

the class AnnotationCacheOperationSourceTests method customClassLevelWithCustomCacheName.

@Test
public void customClassLevelWithCustomCacheName() {
    Collection<CacheOperation> ops = getOps(AnnotatedClassWithCustomDefault.class, "methodLevelCacheName", 1);
    CacheOperation cacheOperation = ops.iterator().next();
    assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom");
}
Also used : CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Test(org.junit.jupiter.api.Test)

Aggregations

CacheOperation (cn.taketoday.cache.interceptor.CacheOperation)44 Test (org.junit.jupiter.api.Test)42 CacheableOperation (cn.taketoday.cache.interceptor.CacheableOperation)6 CacheEvictOperation (cn.taketoday.cache.interceptor.CacheEvictOperation)4 TypedStringValue (cn.taketoday.beans.factory.config.TypedStringValue)2 ManagedMap (cn.taketoday.beans.factory.support.ManagedMap)2 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)2 CachePutOperation (cn.taketoday.cache.interceptor.CachePutOperation)2 Collection (java.util.Collection)2 Element (org.w3c.dom.Element)2