moving unit tests from .testsuite -> .context

This commit is contained in:
Chris Beams 2008-12-14 08:00:16 +00:00
parent 0572d9d1a4
commit b4e61dd9df
2 changed files with 33 additions and 6 deletions

View File

@ -16,13 +16,14 @@
package org.springframework.context.annotation;
import static org.junit.Assert.*;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.EJB;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.INestedTestBean;
import org.springframework.beans.ITestBean;
import org.springframework.beans.NestedTestBean;
@ -39,9 +40,11 @@ import org.springframework.util.SerializationTestUtils;
/**
* @author Juergen Hoeller
* @author Chris Beams
*/
public class CommonAnnotationBeanPostProcessorTests extends TestCase {
public class CommonAnnotationBeanPostProcessorTests {
@Test
public void testPostConstructAndPreDestroy() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
@ -53,6 +56,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroyCalled);
}
@Test
public void testPostConstructAndPreDestroyWithManualConfiguration() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
@ -67,6 +71,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroyCalled);
}
@Test
public void testSerialization() throws Exception {
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor)
@ -77,6 +82,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroyCalled);
}
@Test
public void testSerializationWithManualConfiguration() throws Exception {
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
bpp.setInitAnnotationType(PostConstruct.class);
@ -89,6 +95,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroyCalled);
}
@Test
public void testResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
@ -110,6 +117,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroy2Called);
}
@Test
public void testResourceInjectionWithTwoProcessors() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
@ -134,6 +142,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroy2Called);
}
@Test
public void testResourceInjectionFromJndi() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
@ -158,6 +167,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroy2Called);
}
@Test
public void testExtendedResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
@ -198,6 +208,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroy2Called);
}
@Test
public void testExtendedResourceInjectionWithOverriding() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
@ -246,6 +257,7 @@ public class CommonAnnotationBeanPostProcessorTests extends TestCase {
assertTrue(bean.destroy2Called);
}
@Test
public void testExtendedEjbInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();

View File

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