polishing .beans tests

This commit is contained in:
Chris Beams 2008-12-24 20:17:43 +00:00
parent 751daf95a1
commit 915ad0a8d9
32 changed files with 286 additions and 245 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@ -28,7 +28,7 @@ import org.springframework.beans.factory.wiring.BeanWiringInfo;
* @author Rick Evans
* @author Chris Beams
*/
public class AnnotationBeanWiringInfoResolverTests {
public final class AnnotationBeanWiringInfoResolverTests {
@Test
public void testResolveWiringInfo() throws Exception {

View File

@ -16,9 +16,9 @@
<property name="age"><value>25</value></property>
</bean>
<bean id="testFactory1" class="org.springframework.beans.factory.DummyFactory"/>
<bean id="testFactory1" class="test.beans.DummyFactory"/>
<bean id="testFactory2" class="org.springframework.beans.factory.DummyFactory">
<bean id="testFactory2" class="test.beans.DummyFactory">
<property name="singleton"><value>false</value></property>
</bean>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@ -17,6 +17,7 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Arrays;
import java.util.List;
@ -29,9 +30,10 @@ import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils;
import test.beans.DummyFactory;
import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.TestBean;
@ -42,7 +44,13 @@ import test.beans.TestBean;
* @author Chris Beams
* @since 04.07.2003
*/
public class BeanFactoryUtilsTests {
public final class BeanFactoryUtilsTests {
private static final Class<?> CLASS = BeanFactoryUtilsTests.class;
private static final Resource ROOT_CONTEXT = qualifiedResource(CLASS, "root.xml");
private static final Resource MIDDLE_CONTEXT = qualifiedResource(CLASS, "middle.xml");
private static final Resource LEAF_CONTEXT = qualifiedResource(CLASS, "leaf.xml");
private static final Resource DEPENDENT_BEANS_CONTEXT = qualifiedResource(CLASS, "dependentBeans.xml");
private ConfigurableListableBeanFactory listableBeanFactory;
@ -52,10 +60,10 @@ public class BeanFactoryUtilsTests {
public void setUp() {
// Interesting hierarchical factory to test counts.
// Slow to read so we cache it.
XmlBeanFactory grandParent = new XmlBeanFactory(new ClassPathResource("root.xml", getClass()));
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("middle.xml", getClass()), grandParent);
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("leaf.xml", getClass()), parent);
this.dependentBeansBF = new XmlBeanFactory(new ClassPathResource("dependentBeans.xml", getClass()));
XmlBeanFactory grandParent = new XmlBeanFactory(ROOT_CONTEXT);
XmlBeanFactory parent = new XmlBeanFactory(MIDDLE_CONTEXT, grandParent);
XmlBeanFactory child = new XmlBeanFactory(LEAF_CONTEXT, parent);
this.dependentBeansBF = new XmlBeanFactory(DEPENDENT_BEANS_CONTEXT);
dependentBeansBF.preInstantiateSingletons();
this.listableBeanFactory = child;
}

View File

@ -16,6 +16,8 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -25,10 +27,10 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.xml.XmlBeanFactory;
@ -38,9 +40,10 @@ import org.springframework.core.io.ClassPathResource;
/**
* @author Guillaume Poirier
* @author Juergen Hoeller
* @author Chris Beams
* @since 10.03.2004
*/
public class ConcurrentBeanFactoryTests extends TestCase {
public final class ConcurrentBeanFactoryTests {
private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
@ -62,11 +65,12 @@ public class ConcurrentBeanFactoryTests extends TestCase {
private BeanFactory factory;
private final Set set = Collections.synchronizedSet(new HashSet());
private final Set<TestRun> set = Collections.synchronizedSet(new HashSet<TestRun>());
private Throwable ex = null;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("concurrent.xml", getClass()));
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
@ -76,20 +80,22 @@ public class ConcurrentBeanFactoryTests extends TestCase {
this.factory = factory;
}
@Test
public void testSingleThread() {
for (int i = 0; i < 100; i++) {
performTest();
}
}
@Test
public void testConcurrent() {
for (int i = 0; i < 100; i++) {
TestRun run = new TestRun();
run.setDaemon(true);
set.add(run);
}
for (Iterator it = new HashSet(set).iterator(); it.hasNext();) {
TestRun run = (TestRun) it.next();
for (Iterator<TestRun> it = new HashSet<TestRun>(set).iterator(); it.hasNext();) {
TestRun run = it.next();
run.start();
}
logger.info("Thread creation over, " + set.size() + " still active.");

View File

@ -70,7 +70,9 @@ import org.springframework.core.io.UrlResource;
import org.springframework.util.StopWatch;
import test.beans.DerivedTestBean;
import test.beans.DummyFactory;
import test.beans.ITestBean;
import test.beans.LifecycleBean;
import test.beans.NestedTestBean;
import test.beans.TestBean;
@ -83,7 +85,7 @@ import test.beans.TestBean;
* @author Sam Brannen
* @author Chris Beams
*/
public class DefaultListableBeanFactoryTests {
public final class DefaultListableBeanFactoryTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
@ -2370,4 +2372,22 @@ public class DefaultListableBeanFactoryTests {
}
private static class KnowsIfInstantiated {
private static boolean instantiated;
public static void clearInstantiationRecord() {
instantiated = false;
}
public static boolean wasInstantiated() {
return instantiated;
}
public KnowsIfInstantiated() {
instantiated = true;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@ -17,11 +17,12 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
/**
@ -29,19 +30,22 @@ import org.springframework.util.Assert;
* @author Juergen Hoeller
* @author Chris Beams
*/
public class FactoryBeanTests {
public final class FactoryBeanTests {
private static final Class<?> CLASS = FactoryBeanTests.class;
private static final Resource RETURNS_NULL_CONTEXT = qualifiedResource(CLASS, "returnsNull.xml");
private static final Resource WITH_AUTOWIRING_CONTEXT = qualifiedResource(CLASS, "withAutowiring.xml");
@Test
public void testFactoryBeanReturnsNull() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("factoryBeanReturnsNull.xml", getClass()));
XmlBeanFactory factory = new XmlBeanFactory(RETURNS_NULL_CONTEXT);
Object result = factory.getBean("factoryBean");
assertNull(result);
}
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
XmlBeanFactory factory =
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory);
@ -58,8 +62,7 @@ public class FactoryBeanTests {
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
XmlBeanFactory factory =
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory);

View File

@ -1,94 +0,0 @@
/*
* Copyright 2002-2005 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;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Bean exposing a map. Used for bean factory tests.
*
* @author Rod Johnson
* @since 05.06.2003
*/
public class HasMap {
private Map map;
private Set set;
private Properties props;
private Object[] objectArray;
private Class[] classArray;
private Integer[] intArray;
private HasMap() {
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
public Set getSet() {
return set;
}
public void setSet(Set set) {
this.set = set;
}
public Properties getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
public Object[] getObjectArray() {
return objectArray;
}
public void setObjectArray(Object[] objectArray) {
this.objectArray = objectArray;
}
public Class[] getClassArray() {
return classArray;
}
public void setClassArray(Class[] classArray) {
this.classArray = classArray;
}
public Integer[] getIntegerArray() {
return intArray;
}
public void setIntegerArray(Integer[] is) {
intArray = is;
}
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2002-2005 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;
public class KnowsIfInstantiated {
private static boolean instantiated;
public static void clearInstantiationRecord() {
instantiated = false;
}
public static boolean wasInstantiated() {
return instantiated;
}
public KnowsIfInstantiated() {
instantiated = true;
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2002-2005 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;
/**
* Simple test of BeanFactory initialization
* @author Rod Johnson
* @since 12.03.2003
*/
public class MustBeInitialized implements InitializingBean {
private boolean inited;
/**
* @see InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
this.inited = true;
}
/**
* Dummy business method that will fail unless the factory
* managed the bean's lifecycle correctly
*/
public void businessMethod() {
if (!this.inited)
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* 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.
@ -16,10 +16,11 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import java.util.Arrays;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
@ -28,10 +29,12 @@ import test.beans.TestBean;
/**
* @author Juergen Hoeller
* @author Chris Beams
* @since 04.07.2006
*/
public class SharedBeanRegistryTests extends TestCase {
public final class SharedBeanRegistryTests {
@Test
public void testSingletons() {
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
@ -39,7 +42,7 @@ public class SharedBeanRegistryTests extends TestCase {
beanRegistry.registerSingleton("tb", tb);
assertSame(tb, beanRegistry.getSingleton("tb"));
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", new ObjectFactory() {
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", new ObjectFactory<Object>() {
public Object getObject() throws BeansException {
return new TestBean();
}
@ -58,6 +61,7 @@ public class SharedBeanRegistryTests extends TestCase {
assertEquals(0, beanRegistry.getSingletonNames().length);
}
@Test
public void testDisposableBean() {
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();

View File

@ -102,7 +102,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
public void testWithConstantOnClassWithPackageLevelVisibility() throws Exception {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
fr.setBeanName("org.springframework.beans.factory.PackageLevelVisibleBean.CONSTANT");
fr.setBeanName("test.beans.PackageLevelVisibleBean.CONSTANT");
fr.afterPropertiesSet();
assertEquals("Wuby", fr.getObject());
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package org.springframework.beans.factory.xml;
import java.beans.PropertyEditorSupport;
import java.util.StringTokenizer;
@ -24,8 +24,16 @@ import junit.framework.Assert;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyBatchUpdateException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanIsNotAFactoryException;
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import test.beans.DummyFactory;
import test.beans.LifecycleBean;
import test.beans.TestBean;
/**
@ -328,3 +336,31 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
}
}
/**
* Simple test of BeanFactory initialization
* @author Rod Johnson
* @since 12.03.2003
*/
class MustBeInitialized implements InitializingBean {
private boolean inited;
/**
* @see InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
this.inited = true;
}
/**
* Dummy business method that will fail unless the factory
* managed the bean's lifecycle correctly
*/
public void businessMethod() {
if (!this.inited)
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
}
}

View File

@ -14,7 +14,11 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package org.springframework.beans.factory.xml;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory;
import junit.framework.Assert;

View File

@ -19,7 +19,6 @@ package org.springframework.beans.factory.xml;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.factory.CountingFactory;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;

View File

@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package org.springframework.beans.factory.xml;
import org.springframework.beans.factory.FactoryBean;
import test.beans.TestBean;

View File

@ -16,8 +16,8 @@
package org.springframework.beans.factory.xml;
import org.springframework.beans.factory.DummyFactory;
import test.beans.DummyFactory;
import test.beans.TestBean;
/**

View File

@ -33,7 +33,6 @@ import java.util.TreeSet;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.HasMap;
import org.springframework.beans.factory.config.ListFactoryBean;
import org.springframework.beans.factory.config.MapFactoryBean;
import org.springframework.beans.factory.config.SetFactoryBean;
@ -443,3 +442,78 @@ public class XmlBeanCollectionTests {
}
}
/**
* Bean exposing a map. Used for bean factory tests.
*
* @author Rod Johnson
* @since 05.06.2003
*/
class HasMap {
private Map map;
private Set set;
private Properties props;
private Object[] objectArray;
private Class[] classArray;
private Integer[] intArray;
private HasMap() {
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
public Set getSet() {
return set;
}
public void setSet(Set set) {
this.set = set;
}
public Properties getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
public Object[] getObjectArray() {
return objectArray;
}
public void setObjectArray(Object[] objectArray) {
this.objectArray = objectArray;
}
public Class[] getClassArray() {
return classArray;
}
public void setClassArray(Class[] classArray) {
this.classArray = classArray;
}
public Integer[] getIntegerArray() {
return intArray;
}
public void setIntegerArray(Integer[] is) {
intArray = is;
}
}

View File

@ -25,16 +25,15 @@ import junit.framework.Assert;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.AbstractListableBeanFactoryTests;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.DummyFactory;
import org.springframework.beans.factory.LifecycleBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.ClassPathResource;
import test.beans.DummyFactory;
import test.beans.ITestBean;
import test.beans.LifecycleBean;
import test.beans.TestBean;
/**

View File

@ -109,14 +109,14 @@
<property name="name"><idref bean="verbose"/></property>
</bean>
<bean id="emptyMap" class="org.springframework.beans.factory.HasMap">
<bean id="emptyMap" class="org.springframework.beans.factory.xml.HasMap">
<property name="map">
<map>
</map>
</property>
</bean>
<bean id="literalMap" class="org.springframework.beans.factory.HasMap">
<bean id="literalMap" class="org.springframework.beans.factory.xml.HasMap">
<property name="map">
<map>
<entry key="foo" value="bar"/>
@ -126,7 +126,7 @@
</property>
</bean>
<bean id="mixedMap" class="org.springframework.beans.factory.HasMap">
<bean id="mixedMap" class="org.springframework.beans.factory.xml.HasMap">
<property name="map">
<map>
<entry key-ref="fooKey">
@ -158,7 +158,7 @@
<constructor-arg value="jenny"/>
</bean>
<bean id="pMixedMap" class="org.springframework.beans.factory.HasMap" scope="prototype">
<bean id="pMixedMap" class="org.springframework.beans.factory.xml.HasMap" scope="prototype">
<property name="map">
<map>
<entry key="foo" value="bar"/>
@ -167,7 +167,7 @@
</property>
</bean>
<bean id="mixedMapWithList" class="org.springframework.beans.factory.HasMap">
<bean id="mixedMapWithList" class="org.springframework.beans.factory.xml.HasMap">
<property name="map">
<map>
<entry>
@ -199,7 +199,7 @@
</property>
</bean>
<bean id="emptySet" class="org.springframework.beans.factory.HasMap">
<bean id="emptySet" class="org.springframework.beans.factory.xml.HasMap">
<property name="set">
<set>
</set>
@ -207,7 +207,7 @@
</bean>
<bean id="set" class="org.springframework.beans.factory.HasMap">
<bean id="set" class="org.springframework.beans.factory.xml.HasMap">
<property name="set">
<set>
<value>bar</value>
@ -217,7 +217,7 @@
</property>
</bean>
<bean id="emptyProps" class="org.springframework.beans.factory.HasMap">
<bean id="emptyProps" class="org.springframework.beans.factory.xml.HasMap">
<property name="props">
<props>
</props>
@ -225,7 +225,7 @@
</bean>
<bean id="props" class="org.springframework.beans.factory.HasMap">
<bean id="props" class="org.springframework.beans.factory.xml.HasMap">
<property name="props">
<props>
<prop key="foo">bar</prop>
@ -234,7 +234,7 @@
</property>
</bean>
<bean id="propsViaMap" class="org.springframework.beans.factory.HasMap">
<bean id="propsViaMap" class="org.springframework.beans.factory.xml.HasMap">
<property name="props">
<map>
<entry key="foo" value="bar"/>
@ -243,7 +243,7 @@
</property>
</bean>
<bean id="objectArray" class="org.springframework.beans.factory.HasMap">
<bean id="objectArray" class="org.springframework.beans.factory.xml.HasMap">
<property name="objectArray">
<list>
<value>one</value>
@ -252,7 +252,7 @@
</property>
</bean>
<bean id="classArray" class="org.springframework.beans.factory.HasMap">
<bean id="classArray" class="org.springframework.beans.factory.xml.HasMap">
<property name="classArray">
<list>
<value>java.lang.String</value>
@ -261,7 +261,7 @@
</property>
</bean>
<bean id="integerArray" class="org.springframework.beans.factory.HasMap">
<bean id="integerArray" class="org.springframework.beans.factory.xml.HasMap">
<property name="integerArray">
<list>
<value>0</value>

View File

@ -14,12 +14,17 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package test.beans;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import test.beans.TestBean;
/**
* Simple factory to allow testing of FactoryBean support in AbstractBeanFactory.
@ -30,10 +35,11 @@ import test.beans.TestBean;
* factories get this lifecycle callback if they want.
*
* @author Rod Johnson
* @author Chris Beams
* @since 10.03.2003
*/
public class DummyFactory
implements FactoryBean, BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
implements FactoryBean<Object>, BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
public static final String SINGLETON_NAME = "Factory singleton";
@ -159,7 +165,7 @@ public class DummyFactory
}
}
public Class getObjectType() {
public Class<?> getObjectType() {
return TestBean.class;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@ -14,9 +14,14 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package test.beans;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
@ -24,6 +29,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
*
* @author Rod Johnson
* @author Colin Sampaleanu
* @author Chris Beams
* @since 12.03.2003
*/
public class LifecycleBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* 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.
@ -14,15 +14,16 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package test.beans;
/**
* Used in the tests for the FieldRetrievingFactoryBean class
* (c.f. FieldRetrievingFactoryBeanTests)
* @see org.springframework.beans.factory.config.FieldRetrievingFactoryBeanTests
*
* @author Rick Evans
* @author Chris Beams
*/
class PackageLevelVisibleBean {
public static final String CONSTANT = "Wuby";
}

View File

@ -0,0 +1,46 @@
/*
* 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 test.util;
import static java.lang.String.format;
import org.springframework.core.io.ClassPathResource;
/**
* Convenience utilities for common operations with test resources.
*
* @author Chris Beams
*/
public class TestResourceUtils {
/**
* Loads a {@link ClassPathResource} qualified by the simple name of clazz,
* and relative to the package for clazz.
*
* <p>Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml',
* this method will return a ClassPathResource representing com/foo/BarTests-context.xml
*
* <p>Intended for use loading context configuration XML files within JUnit tests.
*
* @param clazz
* @param resourceSuffix
*/
public static ClassPathResource qualifiedResource(Class<?> clazz, String resourceSuffix) {
return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
}
}

View File

@ -19,7 +19,7 @@
</property>
</bean>
<bean class="org.springframework.beans.factory.CountingFactory">
<bean class="org.springframework.beans.factory.xml.CountingFactory">
<property name="testBean" ref="rob"/>
</bean>

View File

@ -20,7 +20,7 @@
</property>
</bean>
<bean class="org.springframework.beans.factory.CountingFactory">
<bean class="org.springframework.beans.factory.xml.CountingFactory">
<property name="testBean" ref="rob"/>
</bean>

View File

@ -26,7 +26,7 @@
</property>
</bean>
<bean class="org.springframework.beans.factory.CountingFactory">
<bean class="org.springframework.beans.factory.xml.CountingFactory">
<property name="testBean" ref="rob"/>
</bean>

View File

@ -72,9 +72,9 @@
</bean>
<!-- Test of lifecycle callbacks -->
<bean id="mustBeInitialized" class="org.springframework.beans.factory.MustBeInitialized"/>
<bean id="mustBeInitialized" class="org.springframework.beans.factory.xml.MustBeInitialized"/>
<bean id="lifecycle" class="org.springframework.beans.factory.LifecycleBean"
<bean id="lifecycle" class="test.beans.LifecycleBean"
init-method="declaredInitMethod">
<property name="initMethodDeclared"><value>true</value></property>
</bean>
@ -85,10 +85,10 @@
</bean>
<!-- Factory beans are automatically treated differently -->
<bean id="singletonFactory" class="org.springframework.beans.factory.DummyFactory">
<bean id="singletonFactory" class="test.beans.DummyFactory">
</bean>
<bean id="prototypeFactory" class="org.springframework.beans.factory.DummyFactory">
<bean id="prototypeFactory" class="test.beans.DummyFactory">
<property name="singleton"><value>false</value></property>
</bean>