|
|
|
@ -16,8 +16,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.context.annotation; |
|
|
|
package org.springframework.context.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
import org.springframework.beans.factory.config.BeanDefinition; |
|
|
|
import org.springframework.beans.factory.config.BeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
@ -34,8 +37,9 @@ import org.springframework.web.context.support.GenericWebApplicationContext; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Mark Fisher |
|
|
|
* @author Mark Fisher |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @author Chris Beams |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
public class ClassPathBeanDefinitionScannerScopeTests { |
|
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_NAME = "default"; |
|
|
|
private static final String DEFAULT_NAME = "default"; |
|
|
|
|
|
|
|
|
|
|
|
@ -50,6 +54,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
private ServletRequestAttributes newRequestAttributesWithSession; |
|
|
|
private ServletRequestAttributes newRequestAttributesWithSession; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); |
|
|
|
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); |
|
|
|
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); |
|
|
|
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); |
|
|
|
@ -63,11 +68,13 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession); |
|
|
|
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void tearDown() throws Exception { |
|
|
|
@After |
|
|
|
|
|
|
|
public void tearDown() throws Exception { |
|
|
|
RequestContextHolder.setRequestAttributes(null); |
|
|
|
RequestContextHolder.setRequestAttributes(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSingletonScopeWithNoProxy() { |
|
|
|
public void testSingletonScopeWithNoProxy() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
@ -88,6 +95,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSingletonScopeIgnoresProxyInterfaces() { |
|
|
|
public void testSingletonScopeIgnoresProxyInterfaces() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
@ -108,6 +116,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSingletonScopeIgnoresProxyTargetClass() { |
|
|
|
public void testSingletonScopeIgnoresProxyTargetClass() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
@ -128,6 +137,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean2.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRequestScopeWithNoProxy() { |
|
|
|
public void testRequestScopeWithNoProxy() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
@ -148,6 +158,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(DEFAULT_NAME, bean2.getName()); |
|
|
|
assertEquals(DEFAULT_NAME, bean2.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRequestScopeWithProxiedInterfaces() { |
|
|
|
public void testRequestScopeWithProxiedInterfaces() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
@ -168,6 +179,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRequestScopeWithProxiedTargetClass() { |
|
|
|
public void testRequestScopeWithProxiedTargetClass() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributes); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
@ -188,6 +200,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSessionScopeWithNoProxy() { |
|
|
|
public void testSessionScopeWithNoProxy() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.NO); |
|
|
|
@ -208,6 +221,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(DEFAULT_NAME, bean2.getName()); |
|
|
|
assertEquals(DEFAULT_NAME, bean2.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSessionScopeWithProxiedInterfaces() { |
|
|
|
public void testSessionScopeWithProxiedInterfaces() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); |
|
|
|
@ -234,6 +248,7 @@ public class ClassPathBeanDefinitionScannerScopeTests extends TestCase { |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
assertEquals(MODIFIED_NAME, bean.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSessionScopeWithProxiedTargetClass() { |
|
|
|
public void testSessionScopeWithProxiedTargetClass() { |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); |
|
|
|
|