|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
26 | 26 | import java.util.Collections;
|
27 | 27 | import java.util.Iterator;
|
28 | 28 |
|
29 |
| -import org.junit.Ignore; |
30 | 29 | import org.junit.Rule;
|
31 | 30 | import org.junit.Test;
|
32 | 31 | import org.junit.rules.ExpectedException;
|
@@ -105,34 +104,46 @@ public void multipleStereotypes() throws Exception {
|
105 | 104 | assertTrue(next.getCacheNames().contains("bar"));
|
106 | 105 | }
|
107 | 106 |
|
108 |
| - // TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation. |
109 |
| - @Ignore("Disabled until SPR-13475 is resolved") |
110 | 107 | @Test
|
111 | 108 | public void singleComposedAnnotation() throws Exception {
|
112 |
| - Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 1); |
113 |
| - CacheOperation cacheOperation = ops.iterator().next(); |
| 109 | + Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2); |
| 110 | + Iterator<CacheOperation> it = ops.iterator(); |
| 111 | + |
| 112 | + CacheOperation cacheOperation = it.next(); |
| 113 | + assertThat(cacheOperation, instanceOf(CacheableOperation.class)); |
| 114 | + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared"))); |
| 115 | + assertThat(cacheOperation.getKey(), equalTo("")); |
| 116 | + |
| 117 | + cacheOperation = it.next(); |
114 | 118 | assertThat(cacheOperation, instanceOf(CacheableOperation.class));
|
115 |
| - assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composed"))); |
| 119 | + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); |
| 120 | + assertThat(cacheOperation.getKey(), equalTo("composedKey")); |
116 | 121 | }
|
117 | 122 |
|
118 |
| - // TODO [SPR-13475] Enable test once @Cache* is supported as a composed annotation. |
119 |
| - @Ignore("Disabled until SPR-13475 is resolved") |
120 | 123 | @Test
|
121 | 124 | public void multipleComposedAnnotations() throws Exception {
|
122 |
| - Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 3); |
| 125 | + Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4); |
123 | 126 | Iterator<CacheOperation> it = ops.iterator();
|
124 | 127 |
|
125 | 128 | CacheOperation cacheOperation = it.next();
|
126 | 129 | assertThat(cacheOperation, instanceOf(CacheableOperation.class));
|
| 130 | + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared"))); |
| 131 | + assertThat(cacheOperation.getKey(), equalTo("")); |
| 132 | + |
| 133 | + cacheOperation = it.next(); |
| 134 | + assertThat(cacheOperation, instanceOf(CacheableOperation.class)); |
127 | 135 | assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
|
| 136 | + assertThat(cacheOperation.getKey(), equalTo("composedKey")); |
128 | 137 |
|
129 | 138 | cacheOperation = it.next();
|
130 | 139 | assertThat(cacheOperation, instanceOf(CacheableOperation.class));
|
131 | 140 | assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));
|
| 141 | + assertThat(cacheOperation.getKey(), equalTo("")); |
132 | 142 |
|
133 | 143 | cacheOperation = it.next();
|
134 | 144 | assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
|
135 |
| - assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); |
| 145 | + assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCacheEvict"))); |
| 146 | + assertThat(cacheOperation.getKey(), equalTo("composedEvictionKey")); |
136 | 147 | }
|
137 | 148 |
|
138 | 149 | @Test
|
@@ -309,13 +320,15 @@ public void singleStereotype() {
|
309 | 320 | public void multipleStereotype() {
|
310 | 321 | }
|
311 | 322 |
|
312 |
| - @ComposedCacheable("composed") |
| 323 | + @Cacheable("directly declared") |
| 324 | + @ComposedCacheable(cacheNames = "composedCache", key = "composedKey") |
313 | 325 | public void singleComposed() {
|
314 | 326 | }
|
315 | 327 |
|
| 328 | + @Cacheable("directly declared") |
316 | 329 | @ComposedCacheable(cacheNames = "composedCache", key = "composedKey")
|
317 | 330 | @CacheableFoo
|
318 |
| - @ComposedCacheEvict(cacheNames = "composedCache", key = "composedKey") |
| 331 | + @ComposedCacheEvict(cacheNames = "composedCacheEvict", key = "composedEvictionKey") |
319 | 332 | public void multipleComposed() {
|
320 | 333 | }
|
321 | 334 |
|
@@ -443,38 +456,37 @@ public void multipleCacheConfig() {
|
443 | 456 |
|
444 | 457 | @Retention(RetentionPolicy.RUNTIME)
|
445 | 458 | @Target(ElementType.TYPE)
|
446 |
| - @CacheConfig(keyGenerator = "classKeyGenerator", |
447 |
| - cacheManager = "classCacheManager", cacheResolver = "classCacheResolver") |
| 459 | + @CacheConfig(keyGenerator = "classKeyGenerator", cacheManager = "classCacheManager", cacheResolver = "classCacheResolver") |
448 | 460 | public @interface CacheConfigFoo {
|
449 | 461 | }
|
450 | 462 |
|
451 | 463 | @Retention(RetentionPolicy.RUNTIME)
|
452 | 464 | @Target({ ElementType.METHOD, ElementType.TYPE })
|
453 | 465 | @Cacheable(cacheNames = "shadowed cache name", key = "shadowed key")
|
454 |
| - public @interface ComposedCacheable { |
| 466 | + @interface ComposedCacheable { |
455 | 467 |
|
456 |
| - @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") |
| 468 | + @AliasFor(annotation = Cacheable.class) |
457 | 469 | String[] value() default {};
|
458 | 470 |
|
459 |
| - @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") |
| 471 | + @AliasFor(annotation = Cacheable.class) |
460 | 472 | String[] cacheNames() default {};
|
461 | 473 |
|
462 |
| - @AliasFor(annotation = Cacheable.class, attribute = "key") |
| 474 | + @AliasFor(annotation = Cacheable.class) |
463 | 475 | String key() default "";
|
464 | 476 | }
|
465 | 477 |
|
466 | 478 | @Retention(RetentionPolicy.RUNTIME)
|
467 | 479 | @Target({ ElementType.METHOD, ElementType.TYPE })
|
468 | 480 | @CacheEvict(cacheNames = "shadowed cache name", key = "shadowed key")
|
469 |
| - public @interface ComposedCacheEvict { |
| 481 | + @interface ComposedCacheEvict { |
470 | 482 |
|
471 |
| - @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") |
| 483 | + @AliasFor(annotation = CacheEvict.class) |
472 | 484 | String[] value() default {};
|
473 | 485 |
|
474 |
| - @AliasFor(annotation = Cacheable.class, attribute = "cacheNames") |
| 486 | + @AliasFor(annotation = CacheEvict.class) |
475 | 487 | String[] cacheNames() default {};
|
476 | 488 |
|
477 |
| - @AliasFor(annotation = Cacheable.class, attribute = "key") |
| 489 | + @AliasFor(annotation = CacheEvict.class) |
478 | 490 | String key() default "";
|
479 | 491 | }
|
480 | 492 |
|
|
0 commit comments