@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
@Test public void findAllMergedAnnotationsOnClassWithInterface() throws Exception { Method m = TransactionalServiceImpl.class.getMethod("doIt"); Set<Transactional> allMergedAnnotations = findAllMergedAnnotations(m, Transactional.class); assertEquals(1, allMergedAnnotations.size()); }
@Test public void findMultipleNoninheritedComposedAnnotationsOnClass() { Class<?> element = MultipleNoninheritedComposedCachesClass.class; Set<Cacheable> cacheables = findAllMergedAnnotations(element, Cacheable.class); assertNotNull(cacheables); assertEquals(2, cacheables.size()); Iterator<Cacheable> iterator = cacheables.iterator(); Cacheable cacheable1 = iterator.next(); Cacheable cacheable2 = iterator.next(); assertEquals("noninheritedCache1", cacheable1.value()); assertEquals("noninheritedCache2", cacheable2.value()); }
@Test public void findMultipleNoninheritedComposedAnnotationsOnSuperclass() { Class<?> element = SubMultipleNoninheritedComposedCachesClass.class; Set<Cacheable> cacheables = findAllMergedAnnotations(element, Cacheable.class); assertNotNull(cacheables); assertEquals(2, cacheables.size()); Iterator<Cacheable> iterator = cacheables.iterator(); Cacheable cacheable1 = iterator.next(); Cacheable cacheable2 = iterator.next(); assertEquals("noninheritedCache1", cacheable1.value()); assertEquals("noninheritedCache2", cacheable2.value()); }
private void assertFindAllMergedAnnotationsBehavior(AnnotatedElement element) { assertNotNull(element); Set<Cacheable> cacheables = findAllMergedAnnotations(element, Cacheable.class); assertNotNull(cacheables); assertEquals(2, cacheables.size()); Iterator<Cacheable> iterator = cacheables.iterator(); Cacheable fooCacheable = iterator.next(); Cacheable barCacheable = iterator.next(); assertEquals("fooKey", fooCacheable.key()); assertEquals("fooCache", fooCacheable.value()); assertEquals("barKey", barCacheable.key()); assertEquals("barCache", barCacheable.value()); }
@Override public Collection<LimiterOperation<Semaphore>> parseAnnotations(AnnotatedElement ae) { Collection<HSemaphore> hSemaphores = AnnotatedElementUtils.findAllMergedAnnotations(ae, HSemaphore.class); if (CollectionUtils.isEmpty(hSemaphores)) { return null; } Collection<LimiterOperation<Semaphore>> retVal = new ArrayList<>(); for (HSemaphore hSemaphore : hSemaphores) { retVal.addAll(parseSemaphoreAnnotations(ae, hSemaphore)); } return retVal; }
@Override public Collection<LimiterOperation<Lock>> parseAnnotations(AnnotatedElement ae) { Collection<HLock> hLocks = AnnotatedElementUtils.findAllMergedAnnotations(ae, HLock.class); if (CollectionUtils.isEmpty(hLocks)) { return null; } Collection<LimiterOperation<Lock>> retVal = new ArrayList<>(); for (HLock hLock : hLocks) { retVal.addAll(parseLockAnnotations(ae, hLock)); } return retVal; }
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.size() < 1) { return null; } if (annotations.size() > 1) { throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); } return annotations.iterator().next().value(); }
@Override public Collection<LimiterOperation<RateLimiter>> parseAnnotations(AnnotatedElement ae) { Collection<HRateLimiter> hRateLimiters = AnnotatedElementUtils.findAllMergedAnnotations(ae, HRateLimiter.class); if (CollectionUtils.isEmpty(hRateLimiters)) { return null; } Collection<LimiterOperation<RateLimiter>> retVal = new ArrayList<>(); for (HRateLimiter hRateLimiter : hRateLimiters) { retVal.addAll(parseRateLimiterAnnotations(ae, hRateLimiter)); } return retVal; }
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.size() < 1) { return null; } if (annotations.size() > 1) { throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); } return annotations.iterator().next().value(); }
private String defaultValue(Method method, String pathVariable) { Set<ApiImplicitParam> apiImplicitParams = AnnotatedElementUtils.findAllMergedAnnotations(method, ApiImplicitParam.class); for (ApiImplicitParam apiImplicitParam : apiImplicitParams) { if (pathVariable.equals(apiImplicitParam.name())) { return apiImplicitParam.allowableValues().split(",")[0].trim(); } } throw new IllegalArgumentException("no default value for " + pathVariable); }
@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }