|
|
|
@ -49,7 +49,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
@Rule |
|
|
|
@Rule |
|
|
|
public final ExpectedException exception = ExpectedException.none(); |
|
|
|
public final ExpectedException exception = ExpectedException.none(); |
|
|
|
|
|
|
|
|
|
|
|
private AnnotationCacheOperationSource source = new AnnotationCacheOperationSource(); |
|
|
|
private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) { |
|
|
|
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) { |
|
|
|
@ -85,6 +85,11 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
assertTrue(it.next() instanceof CacheEvictOperation); |
|
|
|
assertTrue(it.next() instanceof CacheEvictOperation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void emptyCaching() throws Exception { |
|
|
|
|
|
|
|
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "emptyCaching", 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void singularStereotype() throws Exception { |
|
|
|
public void singularStereotype() throws Exception { |
|
|
|
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1); |
|
|
|
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1); |
|
|
|
@ -272,17 +277,20 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
assertSharedConfig(cacheOperation, "classKeyGenerator", "classCacheManager", "", "classCacheName"); |
|
|
|
assertSharedConfig(cacheOperation, "classKeyGenerator", "classCacheManager", "", "classCacheName"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager, |
|
|
|
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager, |
|
|
|
String cacheResolver, String... cacheNames) { |
|
|
|
String cacheResolver, String... cacheNames) { |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Wrong key manager", keyGenerator, actual.getKeyGenerator()); |
|
|
|
assertEquals("Wrong key manager", keyGenerator, actual.getKeyGenerator()); |
|
|
|
assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager()); |
|
|
|
assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager()); |
|
|
|
assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver()); |
|
|
|
assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver()); |
|
|
|
assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size()); |
|
|
|
assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size()); |
|
|
|
Arrays.stream(cacheNames).forEach( |
|
|
|
Arrays.stream(cacheNames).forEach( |
|
|
|
cacheName -> assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(), |
|
|
|
cacheName -> assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(), |
|
|
|
actual.getCacheNames().contains(cacheName))); |
|
|
|
actual.getCacheNames().contains(cacheName))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class AnnotatedClass { |
|
|
|
private static class AnnotatedClass { |
|
|
|
|
|
|
|
|
|
|
|
@Cacheable("test") |
|
|
|
@Cacheable("test") |
|
|
|
@ -298,6 +306,10 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
public void caching() { |
|
|
|
public void caching() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Caching |
|
|
|
|
|
|
|
public void emptyCaching() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Cacheable(cacheNames = "test", keyGenerator = "custom") |
|
|
|
@Cacheable(cacheNames = "test", keyGenerator = "custom") |
|
|
|
public void customKeyGenerator() { |
|
|
|
public void customKeyGenerator() { |
|
|
|
} |
|
|
|
} |
|
|
|
@ -361,6 +373,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CacheConfig(cacheNames = "classCacheName", |
|
|
|
@CacheConfig(cacheNames = "classCacheName", |
|
|
|
keyGenerator = "classKeyGenerator", |
|
|
|
keyGenerator = "classKeyGenerator", |
|
|
|
cacheManager = "classCacheManager", cacheResolver = "classCacheResolver") |
|
|
|
cacheManager = "classCacheManager", cacheResolver = "classCacheResolver") |
|
|
|
@ -383,6 +396,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CacheConfigFoo |
|
|
|
@CacheConfigFoo |
|
|
|
private static class AnnotatedClassWithCustomDefault { |
|
|
|
private static class AnnotatedClassWithCustomDefault { |
|
|
|
|
|
|
|
|
|
|
|
@ -391,6 +405,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CacheConfig(cacheNames = "classCacheName", |
|
|
|
@CacheConfig(cacheNames = "classCacheName", |
|
|
|
keyGenerator = "classKeyGenerator", |
|
|
|
keyGenerator = "classKeyGenerator", |
|
|
|
cacheManager = "classCacheManager") |
|
|
|
cacheManager = "classCacheManager") |
|
|
|
@ -409,6 +424,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CacheConfigFoo |
|
|
|
@CacheConfigFoo |
|
|
|
@CacheConfig(cacheNames = "myCache") // multiple sources
|
|
|
|
@CacheConfig(cacheNames = "myCache") // multiple sources
|
|
|
|
private static class MultipleCacheConfig { |
|
|
|
private static class MultipleCacheConfig { |
|
|
|
@ -418,48 +434,58 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Cacheable("foo") |
|
|
|
@Cacheable("foo") |
|
|
|
public @interface CacheableFoo { |
|
|
|
public @interface CacheableFoo { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Cacheable(cacheNames = "foo", keyGenerator = "custom") |
|
|
|
@Cacheable(cacheNames = "foo", keyGenerator = "custom") |
|
|
|
public @interface CacheableFooCustomKeyGenerator { |
|
|
|
public @interface CacheableFooCustomKeyGenerator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Cacheable(cacheNames = "foo", cacheManager = "custom") |
|
|
|
@Cacheable(cacheNames = "foo", cacheManager = "custom") |
|
|
|
public @interface CacheableFooCustomCacheManager { |
|
|
|
public @interface CacheableFooCustomCacheManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Cacheable(cacheNames = "foo", cacheResolver = "custom") |
|
|
|
@Cacheable(cacheNames = "foo", cacheResolver = "custom") |
|
|
|
public @interface CacheableFooCustomCacheResolver { |
|
|
|
public @interface CacheableFooCustomCacheResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@CacheEvict("foo") |
|
|
|
@CacheEvict("foo") |
|
|
|
public @interface EvictFoo { |
|
|
|
public @interface EvictFoo { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@Target(ElementType.METHOD) |
|
|
|
@CacheEvict("bar") |
|
|
|
@CacheEvict("bar") |
|
|
|
public @interface EvictBar { |
|
|
|
public @interface EvictBar { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.TYPE) |
|
|
|
@Target(ElementType.TYPE) |
|
|
|
@CacheConfig(keyGenerator = "classKeyGenerator", cacheManager = "classCacheManager", cacheResolver = "classCacheResolver") |
|
|
|
@CacheConfig(keyGenerator = "classKeyGenerator", |
|
|
|
|
|
|
|
cacheManager = "classCacheManager", |
|
|
|
|
|
|
|
cacheResolver = "classCacheResolver") |
|
|
|
public @interface CacheConfigFoo { |
|
|
|
public @interface CacheConfigFoo { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target({ ElementType.METHOD, ElementType.TYPE }) |
|
|
|
@Target({ ElementType.METHOD, ElementType.TYPE }) |
|
|
|
@Cacheable(cacheNames = "shadowed cache name", key = "shadowed key") |
|
|
|
@Cacheable(cacheNames = "shadowed cache name", key = "shadowed key") |
|
|
|
@ -475,6 +501,7 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
String key() default ""; |
|
|
|
String key() default ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target({ ElementType.METHOD, ElementType.TYPE }) |
|
|
|
@Target({ ElementType.METHOD, ElementType.TYPE }) |
|
|
|
@CacheEvict(cacheNames = "shadowed cache name", key = "shadowed key") |
|
|
|
@CacheEvict(cacheNames = "shadowed cache name", key = "shadowed key") |
|
|
|
@ -490,4 +517,4 @@ public class AnnotationCacheOperationSourceTests { |
|
|
|
String key() default ""; |
|
|
|
String key() default ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|