@Test public void validateNoCacheIsValid() { // Valid as a CacheResolver might return the cache names to use with other info Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified"); CacheOperation cacheOperation = ops.iterator().next(); assertNotNull("cache names set must not be null", cacheOperation.getCacheNames()); assertEquals("no cache names specified", 0, cacheOperation.getCacheNames().size()); }
@Test public void multipleStereotypes() { Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3); Iterator<CacheOperation> it = ops.iterator(); assertTrue(it.next() instanceof CacheableOperation); CacheOperation next = it.next(); assertTrue(next instanceof CacheEvictOperation); assertTrue(next.getCacheNames().contains("foo")); next = it.next(); assertTrue(next instanceof CacheEvictOperation); assertTrue(next.getCacheNames().contains("bar")); }
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager, String cacheResolver, String... cacheNames) { assertEquals("Wrong key manager", keyGenerator, actual.getKeyGenerator()); assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager()); assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver()); assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size()); Arrays.stream(cacheNames).forEach(cacheName -> assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(), actual.getCacheNames().contains(cacheName))); }
@Test public void singleComposedAnnotation() { Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2); Iterator<CacheOperation> it = ops.iterator(); CacheOperation cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheableOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared"))); assertThat(cacheOperation.getKey(), equalTo("")); cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheableOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); assertThat(cacheOperation.getKey(), equalTo("composedKey")); }
@Test public void multipleComposedAnnotations() { Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4); Iterator<CacheOperation> it = ops.iterator(); CacheOperation cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheableOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared"))); assertThat(cacheOperation.getKey(), equalTo("")); cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheableOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache"))); assertThat(cacheOperation.getKey(), equalTo("composedKey")); cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheableOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo"))); assertThat(cacheOperation.getKey(), equalTo("")); cacheOperation = it.next(); assertThat(cacheOperation, instanceOf(CacheEvictOperation.class)); assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCacheEvict"))); assertThat(cacheOperation.getKey(), equalTo("composedEvictionKey")); }
@Test public void testMultipleCachingSource() { Collection<CacheOperation> ops = getOps("multipleCaching"); assertEquals(2, ops.size()); Iterator<CacheOperation> it = ops.iterator(); CacheOperation next = it.next(); assertTrue(next instanceof CacheableOperation); assertTrue(next.getCacheNames().contains("test")); assertEquals("#a", next.getKey()); next = it.next(); assertTrue(next instanceof CacheableOperation); assertTrue(next.getCacheNames().contains("test")); assertEquals("#b", next.getKey()); }