moving unit tests from .testsuite -> .context

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@411 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Chris Beams 2008-12-14 20:13:56 +00:00
parent 015f9bb766
commit fc7855123a
33 changed files with 129 additions and 9 deletions

View File

@ -0,0 +1,82 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.config;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.ObjectFactory;
/**
* @author Juergen Hoeller
*/
public class SimpleMapScope implements Scope, Serializable {
private final Map map = new HashMap();
private final List callbacks = new LinkedList();
public SimpleMapScope() {
}
public final Map getMap() {
return this.map;
}
public Object get(String name, ObjectFactory objectFactory) {
synchronized (this.map) {
Object scopedObject = this.map.get(name);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
this.map.put(name, scopedObject);
}
return scopedObject;
}
}
public Object remove(String name) {
synchronized (this.map) {
return this.map.remove(name);
}
}
public void registerDestructionCallback(String name, Runnable callback) {
this.callbacks.add(callback);
}
public Object resolveContextualObject(String key) {
return null;
}
public void close() {
for (Iterator it = this.callbacks.iterator(); it.hasNext();) {
Runnable runnable = (Runnable) it.next();
runnable.run();
}
}
public String getConversationId() {
return null;
}
}

View File

@ -16,26 +16,31 @@
package org.springframework.context.annotation;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
/**
* @author Mark Fisher
* @author Chris Beams
*/
public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
public class ComponentScanParserBeanDefinitionDefaultsTests {
private static final String TEST_BEAN_NAME = "componentScanParserBeanDefinitionDefaultsTests.DefaultsTestBean";
private static final String LOCATION_PREFIX = "org/springframework/context/annotation/";
@Before
public void setUp() {
DefaultsTestBean.INIT_COUNT = 0;
}
@Test
public void testDefaultLazyInit() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -46,6 +51,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
@Test
public void testLazyInitTrue() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -58,6 +64,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
@Test
public void testLazyInitFalse() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -68,6 +75,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
}
@Test
public void testDefaultAutowire() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -79,6 +87,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
}
@Test
public void testAutowireNo() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -90,6 +99,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
}
@Test
public void testAutowireConstructor() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -102,6 +112,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
}
@Test
public void testAutowireByType() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -115,6 +126,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
}
}
@Test
public void testAutowireByName() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -127,6 +139,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertEquals("pd2", bean.getPropertyDependency2().getName());
}
@Test
public void testDefaultDependencyCheck() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -138,6 +151,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
}
@Test
public void testDependencyCheckAll() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -151,6 +165,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
}
}
@Test
public void testDependencyCheckObjectsWithAutowireByName() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -162,6 +177,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertNotNull("property dependencies should have been autowired", bean.getPropertyDependency2());
}
@Test
public void testDefaultInitAndDestroyMethodsNotDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -173,6 +189,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
@Test
public void testDefaultInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
@ -184,6 +201,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests extends TestCase {
assertTrue("bean should have been destroyed", bean.isDestroyed());
}
@Test
public void testDefaultNonExistingInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);

View File

@ -16,8 +16,9 @@
package org.springframework.context.annotation;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.config.SimpleMapScope;
@ -30,8 +31,9 @@ import example.scannable.ScopedProxyTestBean;
* @author Mark Fisher
* @author Juergen Hoeller
*/
public class ComponentScanParserScopedProxyTests extends TestCase {
public class ComponentScanParserScopedProxyTests {
@Test
public void testDefaultScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyDefaultTests.xml");
@ -41,6 +43,7 @@ public class ComponentScanParserScopedProxyTests extends TestCase {
assertFalse(AopUtils.isAopProxy(bean));
}
@Test
public void testNoScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyNoTests.xml");
@ -50,6 +53,7 @@ public class ComponentScanParserScopedProxyTests extends TestCase {
assertFalse(AopUtils.isAopProxy(bean));
}
@Test
public void testInterfacesScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
@ -60,6 +64,7 @@ public class ComponentScanParserScopedProxyTests extends TestCase {
assertTrue(AopUtils.isJdkDynamicProxy(bean));
}
@Test
public void testTargetClassScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
@ -69,6 +74,7 @@ public class ComponentScanParserScopedProxyTests extends TestCase {
assertTrue(AopUtils.isCglibProxy(bean));
}
@Test
public void testInvalidConfigScopedProxy() {
try {
new ClassPathXmlApplicationContext(

View File

@ -16,13 +16,14 @@
package org.springframework.context.annotation;
import static org.junit.Assert.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -35,9 +36,11 @@ import example.scannable.AutowiredQualifierFooService;
/**
* @author Mark Fisher
* @author Juergen Hoeller
* @author Chris Beams
*/
public class ComponentScanParserTests extends TestCase {
public class ComponentScanParserTests {
@Test
public void testAspectJTypeFilter() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/aspectjTypeFilterTests.xml");
@ -46,18 +49,21 @@ public class ComponentScanParserTests extends TestCase {
assertFalse(context.containsBean("scopedProxyTestBean"));
}
@Test
public void testNonMatchingResourcePattern() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/nonMatchingResourcePatternTests.xml");
assertFalse(context.containsBean("fooServiceImpl"));
}
@Test
public void testMatchingResourcePattern() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/matchingResourcePatternTests.xml");
assertTrue(context.containsBean("fooServiceImpl"));
}
@Test
public void testComponentScanWithAutowiredQualifier() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml");
@ -66,6 +72,7 @@ public class ComponentScanParserTests extends TestCase {
assertEquals("bar", fooService.foo(123));
}
@Test
public void testCustomAnnotationUsedForBothComponentScanAndQualifier() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customAnnotationUsedForBothComponentScanAndQualifierTests.xml");
@ -73,6 +80,7 @@ public class ComponentScanParserTests extends TestCase {
assertNotNull(testBean.getDependency());
}
@Test
public void testCustomTypeFilter() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customTypeFilterTests.xml");

View File

@ -16,23 +16,27 @@
package org.springframework.context.annotation;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* @author Mark Fisher
*/
public class ComponentScanParserWithUserDefinedStrategiesTests extends AbstractDependencyInjectionSpringContextTests {
public class ComponentScanParserWithUserDefinedStrategiesTests {
@Test
public void testCustomBeanNameGenerator() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customNameGeneratorTests.xml");
assertTrue(context.containsBean("testing.fooServiceImpl"));
}
@Test
public void testCustomScopeMetadataResolver() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customScopeResolverTests.xml");
@ -41,6 +45,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests extends AbstractD
assertFalse(bd.isSingleton());
}
@Test
public void testInvalidConstructorBeanNameGenerator() {
try {
new ClassPathXmlApplicationContext(
@ -52,6 +57,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests extends AbstractD
}
}
@Test
public void testInvalidClassNameScopeMetadataResolver() {
try {
new ClassPathXmlApplicationContext(