From: Juergen H. <jho...@us...> - 2006-09-20 14:58:30
|
Update of /cvsroot/springframework/spring/test/org/springframework/beans/factory In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv11933/test/org/springframework/beans/factory Modified Files: DefaultListableBeanFactoryTests.java Added Files: CountingFactory.java Log Message: factored out "getTypeForFactoryBean" method to allow for early checking of "getObjectType()" result Index: DefaultListableBeanFactoryTests.java =================================================================== RCS file: /cvsroot/springframework/spring/test/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** DefaultListableBeanFactoryTests.java 7 Sep 2006 16:25:40 -0000 1.32 --- DefaultListableBeanFactoryTests.java 20 Sep 2006 14:58:20 -0000 1.33 *************** *** 34,39 **** import org.springframework.beans.PropertyValue; import org.springframework.beans.TestBean; ! import org.springframework.beans.factory.config.*; ! import org.springframework.beans.factory.support.*; import org.springframework.beans.factory.xml.ConstructorDependenciesBean; import org.springframework.beans.factory.xml.DependenciesBean; --- 34,49 ---- import org.springframework.beans.PropertyValue; import org.springframework.beans.TestBean; ! import org.springframework.beans.factory.config.AutowireCapableBeanFactory; ! import org.springframework.beans.factory.config.BeanPostProcessor; ! import org.springframework.beans.factory.config.ConstructorArgumentValues; ! import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; ! import org.springframework.beans.factory.config.RuntimeBeanReference; ! import org.springframework.beans.factory.support.AbstractBeanDefinition; ! import org.springframework.beans.factory.support.AbstractBeanFactory; ! import org.springframework.beans.factory.support.BeanDefinitionBuilder; ! import org.springframework.beans.factory.support.ChildBeanDefinition; ! import org.springframework.beans.factory.support.DefaultListableBeanFactory; ! import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; ! import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ConstructorDependenciesBean; import org.springframework.beans.factory.xml.DependenciesBean; *************** *** 782,785 **** --- 792,805 ---- } + public void testCircularReferenceThroughFactoryBeanTypeCheck() { + DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); + lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); + try { + lbf.getBeansOfType(String.class); + } + catch (UnsatisfiedDependencyException expected) { + } + } + public void testAvoidCircularReferenceThroughAutowiring() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); --- NEW FILE: CountingFactory.java --- /* * Copyright 2002-2006 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 org.springframework.beans.TestBean; /** * @author Juergen Hoeller */ public class CountingFactory implements FactoryBean { private static int factoryBeanInstanceCount = 0; /** * Clear static state. */ public static void reset() { factoryBeanInstanceCount = 0; } public static int getFactoryBeanInstanceCount() { return factoryBeanInstanceCount; } public CountingFactory() { factoryBeanInstanceCount++; } public void setTestBean(TestBean tb) { if (tb.getSpouse() == null) { throw new IllegalStateException("TestBean needs to have spouse"); } } public Object getObject() { return "myString"; } public Class getObjectType() { return String.class; } public boolean isSingleton() { return true; } } |