diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/annotation/AnnotationBeanWiringInfoResolverTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/annotation/AnnotationBeanWiringInfoResolverTests.java index 0ca26ed1966..b623750f363 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/annotation/AnnotationBeanWiringInfoResolverTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/annotation/AnnotationBeanWiringInfoResolverTests.java @@ -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 { diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/dependentBeans.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-dependentBeans.xml similarity index 100% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/dependentBeans.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-dependentBeans.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/leaf.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-leaf.xml similarity index 100% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/leaf.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-leaf.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/middle.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-middle.xml similarity index 100% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/middle.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-middle.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/root.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-root.xml similarity index 79% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/root.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-root.xml index 3f1289ae7e8..ff33aa02125 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/root.xml +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests-root.xml @@ -16,9 +16,9 @@ 25 - + - + false diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java index a2437df04c3..2186da05b43 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java @@ -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; } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java index d6f03943a8a..5724bd7256c 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java @@ -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 set = Collections.synchronizedSet(new HashSet()); 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 it = new HashSet(set).iterator(); it.hasNext();) { + TestRun run = it.next(); run.start(); } logger.info("Thread creation over, " + set.size() + " still active."); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index eba4cf13431..9ba6eaa8000 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -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); @@ -2369,5 +2371,23 @@ 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; + } + + } } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/factoryBeanReturnsNull.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests-returnsNull.xml similarity index 100% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/factoryBeanReturnsNull.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests-returnsNull.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/factoryBeansWithAutowiring.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests-withAutowiring.xml similarity index 100% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/factoryBeansWithAutowiring.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests-withAutowiring.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java index 94a1fb98d8e..9d1123fe1c3 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java @@ -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); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/HasMap.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/HasMap.java deleted file mode 100644 index 3bac49498b5..00000000000 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/HasMap.java +++ /dev/null @@ -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; - } - -} diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/KnowsIfInstantiated.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/KnowsIfInstantiated.java deleted file mode 100644 index 1bb269dfb7f..00000000000 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/KnowsIfInstantiated.java +++ /dev/null @@ -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; - } - -} diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/MustBeInitialized.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/MustBeInitialized.java deleted file mode 100644 index 16cf5d32688..00000000000 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/MustBeInitialized.java +++ /dev/null @@ -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"); - } - -} \ No newline at end of file diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/SharedBeanRegistryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/SharedBeanRegistryTests.java index 41b178117e0..15dd2bcf93a 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/SharedBeanRegistryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/SharedBeanRegistryTests.java @@ -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() { 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(); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java index 962f0efa215..b231d794c3e 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java @@ -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()); } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractBeanFactoryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractBeanFactoryTests.java similarity index 91% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractBeanFactoryTests.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractBeanFactoryTests.java index 4d660eb6a5b..ce8e664be4d 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractBeanFactoryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractBeanFactoryTests.java @@ -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; /** @@ -327,4 +335,32 @@ 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"); + } + } \ No newline at end of file diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractListableBeanFactoryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractListableBeanFactoryTests.java similarity index 93% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractListableBeanFactoryTests.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractListableBeanFactoryTests.java index 692525d6e92..403b4735bbc 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/AbstractListableBeanFactoryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AbstractListableBeanFactoryTests.java @@ -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; diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java index 4c0bb7900df..f731fb97f31 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java @@ -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; diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/CountingFactory.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CountingFactory.java similarity index 92% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/CountingFactory.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CountingFactory.java index 34b0a130eb3..27ea4461be4 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/CountingFactory.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CountingFactory.java @@ -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; diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/DummyReferencer.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/DummyReferencer.java index bd8caf869c2..d42ab430eb1 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/DummyReferencer.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/DummyReferencer.java @@ -16,8 +16,8 @@ package org.springframework.beans.factory.xml; -import org.springframework.beans.factory.DummyFactory; +import test.beans.DummyFactory; import test.beans.TestBean; /** diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java index 581ab3591a2..be56c3a7da3 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java @@ -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; @@ -441,5 +440,80 @@ public class XmlBeanCollectionTests { return obj; } } + +} + + +/** + * 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; + } } + diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java index 237286610fd..22d4fcb30c2 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java @@ -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; /** diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/collections.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/collections.xml index 9e1f1908471..d4b78b5c356 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/collections.xml +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/collections.xml @@ -109,14 +109,14 @@ - + - + @@ -126,7 +126,7 @@ - + @@ -158,7 +158,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -199,7 +199,7 @@ - + @@ -207,7 +207,7 @@ - + bar @@ -217,7 +217,7 @@ - + @@ -225,7 +225,7 @@ - + bar @@ -234,7 +234,7 @@ - + @@ -243,7 +243,7 @@ - + one @@ -252,7 +252,7 @@ - + java.lang.String @@ -261,7 +261,7 @@ - + 0 diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/DummyFactory.java b/org.springframework.beans/src/test/java/test/beans/DummyFactory.java similarity index 88% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/DummyFactory.java rename to org.springframework.beans/src/test/java/test/beans/DummyFactory.java index d4f5906d839..75b585a498f 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/DummyFactory.java +++ b/org.springframework.beans/src/test/java/test/beans/DummyFactory.java @@ -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, 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; } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/LifecycleBean.java b/org.springframework.beans/src/test/java/test/beans/LifecycleBean.java similarity index 92% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/LifecycleBean.java rename to org.springframework.beans/src/test/java/test/beans/LifecycleBean.java index 19b7da62f8d..145413deefb 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/LifecycleBean.java +++ b/org.springframework.beans/src/test/java/test/beans/LifecycleBean.java @@ -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 { diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/PackageLevelVisibleBean.java b/org.springframework.beans/src/test/java/test/beans/PackageLevelVisibleBean.java similarity index 77% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/PackageLevelVisibleBean.java rename to org.springframework.beans/src/test/java/test/beans/PackageLevelVisibleBean.java index e215600caeb..167211091f5 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/PackageLevelVisibleBean.java +++ b/org.springframework.beans/src/test/java/test/beans/PackageLevelVisibleBean.java @@ -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"; + } diff --git a/org.springframework.beans/src/test/java/test/util/TestResourceUtils.java b/org.springframework.beans/src/test/java/test/util/TestResourceUtils.java new file mode 100644 index 00000000000..410788d2c15 --- /dev/null +++ b/org.springframework.beans/src/test/java/test/util/TestResourceUtils.java @@ -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. + * + * 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 + * + * 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); + } + +} diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml index 3dc2b598750..3f32de8aee3 100644 --- a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml +++ b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml @@ -19,7 +19,7 @@ - + diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-inclusion.xml b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-inclusion.xml index 2b27f28ef4e..e32686f27f7 100644 --- a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-inclusion.xml +++ b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-inclusion.xml @@ -20,7 +20,7 @@ - + diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-selective-inclusion.xml b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-selective-inclusion.xml index 8b823f97278..2883bd2383a 100644 --- a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-selective-inclusion.xml +++ b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-selective-inclusion.xml @@ -26,7 +26,7 @@ - + diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/test.xml b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/test.xml index 6e0ebdac149..9d1d1f7adb8 100644 --- a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/test.xml +++ b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/test.xml @@ -72,9 +72,9 @@ - + - true @@ -85,10 +85,10 @@ - + - + false
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 + * + *
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); + } + +} diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml index 3dc2b598750..3f32de8aee3 100644 --- a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml +++ b/org.springframework.beans/src/test/resources/org/springframework/beans/factory/xml/autowire-with-exclusion.xml @@ -19,7 +19,7 @@