moving unit tests from .testsuite -> .context
This commit is contained in:
parent
0572d9d1a4
commit
b4e61dd9df
|
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.INestedTestBean;
|
import org.springframework.beans.INestedTestBean;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.NestedTestBean;
|
import org.springframework.beans.NestedTestBean;
|
||||||
|
|
@ -39,9 +40,11 @@ import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
public class CommonAnnotationBeanPostProcessorTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPostConstructAndPreDestroy() {
|
public void testPostConstructAndPreDestroy() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
|
||||||
|
|
@ -53,6 +56,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroyCalled);
|
assertTrue(bean.destroyCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPostConstructAndPreDestroyWithManualConfiguration() {
|
public void testPostConstructAndPreDestroyWithManualConfiguration() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
||||||
|
|
@ -67,6 +71,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroyCalled);
|
assertTrue(bean.destroyCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerialization() throws Exception {
|
public void testSerialization() throws Exception {
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor)
|
CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor)
|
||||||
|
|
@ -77,6 +82,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroyCalled);
|
assertTrue(bean.destroyCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerializationWithManualConfiguration() throws Exception {
|
public void testSerializationWithManualConfiguration() throws Exception {
|
||||||
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
|
||||||
bpp.setInitAnnotationType(PostConstruct.class);
|
bpp.setInitAnnotationType(PostConstruct.class);
|
||||||
|
|
@ -89,6 +95,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroyCalled);
|
assertTrue(bean.destroyCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testResourceInjection() {
|
public void testResourceInjection() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -110,6 +117,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroy2Called);
|
assertTrue(bean.destroy2Called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testResourceInjectionWithTwoProcessors() {
|
public void testResourceInjectionWithTwoProcessors() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -134,6 +142,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroy2Called);
|
assertTrue(bean.destroy2Called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testResourceInjectionFromJndi() {
|
public void testResourceInjectionFromJndi() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -158,6 +167,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroy2Called);
|
assertTrue(bean.destroy2Called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtendedResourceInjection() {
|
public void testExtendedResourceInjection() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -198,6 +208,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroy2Called);
|
assertTrue(bean.destroy2Called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtendedResourceInjectionWithOverriding() {
|
public void testExtendedResourceInjectionWithOverriding() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -246,6 +257,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
|
||||||
assertTrue(bean.destroy2Called);
|
assertTrue(bean.destroy2Called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtendedEjbInjection() {
|
public void testExtendedEjbInjection() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue