From 8b73c0affbeab0aaa76e8e1bfa4a50d68a2bb8fc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 24 Mar 2014 11:51:21 +0100 Subject: [PATCH] Added ASM-based tests for custom scoping annotations Issue: SPR-11574 --- .../AnnotationScopeMetadataResolverTests.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java index eccfe7a6f26..5f0de59982c 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationScopeMetadataResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.context.annotation; +import java.io.IOException; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -27,6 +28,9 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; import static org.junit.Assert.*; @@ -84,6 +88,17 @@ public final class AnnotationScopeMetadataResolverTests { assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode()); } + @Test + public void testCustomRequestScopeViaAsm() throws IOException { + MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory(); + MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName()); + AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata()); + ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); + assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata); + assertEquals("request", scopeMetadata.getScopeName()); + assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode()); + } + @Test public void testCustomRequestScopeWithAttribute() { AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScopeWithAttribute.class); @@ -93,6 +108,17 @@ public final class AnnotationScopeMetadataResolverTests { assertEquals(ScopedProxyMode.TARGET_CLASS, scopeMetadata.getScopedProxyMode()); } + @Test + public void testCustomRequestScopeWithAttributeViaAsm() throws IOException { + MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory(); + MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttribute.class.getName()); + AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata()); + ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); + assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata); + assertEquals("request", scopeMetadata.getScopeName()); + assertEquals(ScopedProxyMode.TARGET_CLASS, scopeMetadata.getScopedProxyMode()); + } + @Test(expected=IllegalArgumentException.class) public void testCtorWithNullScopedProxyMode() { new AnnotationScopeMetadataResolver(null);