From 54703bf3f8c048e3454289eed35f6099f868bf68 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 23 Sep 2015 00:27:14 -0400 Subject: [PATCH] Introduce ignored, failing tests for SPR-13475 This commit introduces ignored, failing tests that demonstrate that the @Cache* annotations are not yet supported as merged composed annotations. Issue: SPR-13475 --- .../AnnotationCacheOperationSourceTests.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java index cb6a7810be0..35091c83a31 100644 --- a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java +++ b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java @@ -23,8 +23,10 @@ import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -35,11 +37,13 @@ import org.springframework.cache.interceptor.CacheableOperation; import org.springframework.core.annotation.AliasFor; import org.springframework.util.ReflectionUtils; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; /** * @author Costin Leau * @author Stephane Nicoll + * @author Sam Brannen */ public class AnnotationCacheOperationSourceTests { @@ -101,6 +105,36 @@ public class AnnotationCacheOperationSourceTests { assertTrue(next.getCacheNames().contains("bar")); } + // TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation. + @Ignore("Disabled until SPR-13475 is resolved") + @Test + public void singleComposedAnnotation() throws Exception { + Collection ops = getOps(AnnotatedClass.class, "singleComposed", 1); + CacheOperation cacheOperation = ops.iterator().next(); + assertThat(cacheOperation, instanceOf(CacheableOperation.class)); + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composed"))); + } + + // TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation. + @Ignore("Disabled until SPR-13475 is resolved") + @Test + public void multipleComposedAnnotations() throws Exception { + Collection ops = getOps(AnnotatedClass.class, "multipleComposed", 3); + Iterator it = ops.iterator(); + + CacheOperation cacheOperation = it.next(); + assertThat(cacheOperation, instanceOf(CacheableOperation.class)); + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); + + cacheOperation = it.next(); + assertThat(cacheOperation, instanceOf(CacheableOperation.class)); + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo"))); + + cacheOperation = it.next(); + assertThat(cacheOperation, instanceOf(CacheEvictOperation.class)); + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); + } + @Test public void customKeyGenerator() { Collection ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1); @@ -275,6 +309,16 @@ public class AnnotationCacheOperationSourceTests { public void multipleStereotype() { } + @ComposedCacheable("composed") + public void singleComposed() { + } + + @ComposedCacheable(cacheNames = "composedCache", key = "composedKey") + @CacheableFoo + @ComposedCacheEvict(cacheNames = "composedCache", key = "composedKey") + public void multipleComposed() { + } + @Caching(cacheable = { @Cacheable(cacheNames = "test", key = "a"), @Cacheable(cacheNames = "test", key = "b") }) public void multipleCaching() { } @@ -406,7 +450,7 @@ public class AnnotationCacheOperationSourceTests { @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) - @Cacheable + @Cacheable(cacheNames = "shadowed cache name", key = "shadowed key") public @interface ComposedCacheable { @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") @@ -419,4 +463,19 @@ public class AnnotationCacheOperationSourceTests { String key() default ""; } + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.METHOD, ElementType.TYPE }) + @CacheEvict(cacheNames = "shadowed cache name", key = "shadowed key") + public @interface ComposedCacheEvict { + + @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") + String[] value() default {}; + + @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") + String[] cacheNames() default {}; + + @AliasFor(annotation = Cacheable.class, attribute = "key") + String key() default ""; + } + } \ No newline at end of file