提交 54703bf3 编写于 作者: S Sam Brannen

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
上级 d66f85bd
...@@ -23,8 +23,10 @@ import java.lang.annotation.Target; ...@@ -23,8 +23,10 @@ import java.lang.annotation.Target;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
...@@ -35,11 +37,13 @@ import org.springframework.cache.interceptor.CacheableOperation; ...@@ -35,11 +37,13 @@ import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AliasFor;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* @author Costin Leau * @author Costin Leau
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Sam Brannen
*/ */
public class AnnotationCacheOperationSourceTests { public class AnnotationCacheOperationSourceTests {
...@@ -101,6 +105,36 @@ public class AnnotationCacheOperationSourceTests { ...@@ -101,6 +105,36 @@ public class AnnotationCacheOperationSourceTests {
assertTrue(next.getCacheNames().contains("bar")); 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<CacheOperation> 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<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 3);
Iterator<CacheOperation> 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 @Test
public void customKeyGenerator() { public void customKeyGenerator() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1);
...@@ -275,6 +309,16 @@ public class AnnotationCacheOperationSourceTests { ...@@ -275,6 +309,16 @@ public class AnnotationCacheOperationSourceTests {
public void multipleStereotype() { 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") }) @Caching(cacheable = { @Cacheable(cacheNames = "test", key = "a"), @Cacheable(cacheNames = "test", key = "b") })
public void multipleCaching() { public void multipleCaching() {
} }
...@@ -406,7 +450,7 @@ public class AnnotationCacheOperationSourceTests { ...@@ -406,7 +450,7 @@ public class AnnotationCacheOperationSourceTests {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE }) @Target({ ElementType.METHOD, ElementType.TYPE })
@Cacheable @Cacheable(cacheNames = "shadowed cache name", key = "shadowed key")
public @interface ComposedCacheable { public @interface ComposedCacheable {
@AliasFor(annotation = Cacheable.class, attribute = "cacheNames") @AliasFor(annotation = Cacheable.class, attribute = "cacheNames")
...@@ -419,4 +463,19 @@ public class AnnotationCacheOperationSourceTests { ...@@ -419,4 +463,19 @@ public class AnnotationCacheOperationSourceTests {
String key() default ""; 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册