Skip to content

Commit 54703bf

Browse files
committed
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
1 parent d66f85b commit 54703bf

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import java.lang.reflect.Method;
2424
import java.util.Arrays;
2525
import java.util.Collection;
26+
import java.util.Collections;
2627
import java.util.Iterator;
2728

29+
import org.junit.Ignore;
2830
import org.junit.Rule;
2931
import org.junit.Test;
3032
import org.junit.rules.ExpectedException;
@@ -35,11 +37,13 @@
3537
import org.springframework.core.annotation.AliasFor;
3638
import org.springframework.util.ReflectionUtils;
3739

40+
import static org.hamcrest.CoreMatchers.*;
3841
import static org.junit.Assert.*;
3942

4043
/**
4144
* @author Costin Leau
4245
* @author Stephane Nicoll
46+
* @author Sam Brannen
4347
*/
4448
public class AnnotationCacheOperationSourceTests {
4549

@@ -101,6 +105,36 @@ public void multipleStereotypes() throws Exception {
101105
assertTrue(next.getCacheNames().contains("bar"));
102106
}
103107

108+
// TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation.
109+
@Ignore("Disabled until SPR-13475 is resolved")
110+
@Test
111+
public void singleComposedAnnotation() throws Exception {
112+
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 1);
113+
CacheOperation cacheOperation = ops.iterator().next();
114+
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
115+
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composed")));
116+
}
117+
118+
// TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation.
119+
@Ignore("Disabled until SPR-13475 is resolved")
120+
@Test
121+
public void multipleComposedAnnotations() throws Exception {
122+
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 3);
123+
Iterator<CacheOperation> it = ops.iterator();
124+
125+
CacheOperation cacheOperation = it.next();
126+
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
127+
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
128+
129+
cacheOperation = it.next();
130+
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
131+
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));
132+
133+
cacheOperation = it.next();
134+
assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
135+
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
136+
}
137+
104138
@Test
105139
public void customKeyGenerator() {
106140
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1);
@@ -275,6 +309,16 @@ public void singleStereotype() {
275309
public void multipleStereotype() {
276310
}
277311

312+
@ComposedCacheable("composed")
313+
public void singleComposed() {
314+
}
315+
316+
@ComposedCacheable(cacheNames = "composedCache", key = "composedKey")
317+
@CacheableFoo
318+
@ComposedCacheEvict(cacheNames = "composedCache", key = "composedKey")
319+
public void multipleComposed() {
320+
}
321+
278322
@Caching(cacheable = { @Cacheable(cacheNames = "test", key = "a"), @Cacheable(cacheNames = "test", key = "b") })
279323
public void multipleCaching() {
280324
}
@@ -406,7 +450,7 @@ public void multipleCacheConfig() {
406450

407451
@Retention(RetentionPolicy.RUNTIME)
408452
@Target({ ElementType.METHOD, ElementType.TYPE })
409-
@Cacheable
453+
@Cacheable(cacheNames = "shadowed cache name", key = "shadowed key")
410454
public @interface ComposedCacheable {
411455

412456
@AliasFor(annotation = Cacheable.class, attribute = "cacheNames")
@@ -419,4 +463,19 @@ public void multipleCacheConfig() {
419463
String key() default "";
420464
}
421465

466+
@Retention(RetentionPolicy.RUNTIME)
467+
@Target({ ElementType.METHOD, ElementType.TYPE })
468+
@CacheEvict(cacheNames = "shadowed cache name", key = "shadowed key")
469+
public @interface ComposedCacheEvict {
470+
471+
@AliasFor(annotation = Cacheable.class, attribute = "cacheNames")
472+
String[] value() default {};
473+
474+
@AliasFor(annotation = Cacheable.class, attribute = "cacheNames")
475+
String[] cacheNames() default {};
476+
477+
@AliasFor(annotation = Cacheable.class, attribute = "key")
478+
String key() default "";
479+
}
480+
422481
}

0 commit comments

Comments
 (0)