moving unit tests from .testsuite -> .beans
This commit is contained in:
parent
8977ad4032
commit
6cb71bbb71
|
|
@ -14,17 +14,23 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory.annotation;
|
||||
package org.springframework.beans.annotation;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.AnnotationBeanWiringInfoResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.beans.factory.wiring.BeanWiringInfo;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationBeanWiringInfoResolverTests extends TestCase {
|
||||
public class AnnotationBeanWiringInfoResolverTests {
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfo() throws Exception {
|
||||
try {
|
||||
new AnnotationBeanWiringInfoResolver().resolveWiringInfo(null);
|
||||
|
|
@ -34,18 +40,21 @@ public class AnnotationBeanWiringInfoResolverTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
|
||||
assertNull("Must be returning null for a non-@Configurable class instance", info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
|
||||
assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
|
||||
|
|
@ -54,6 +63,7 @@ public class AnnotationBeanWiringInfoResolverTests extends TestCase {
|
|||
assertEquals(WirelessSoap.class.getName(), info.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
|
||||
|
|
@ -16,12 +16,16 @@
|
|||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.cglib.proxy.NoOp;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
|
@ -30,20 +34,21 @@ import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
|||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.servlet.HandlerAdapter;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 04.07.2003
|
||||
*/
|
||||
public class BeanFactoryUtilsTests extends TestCase {
|
||||
public class BeanFactoryUtilsTests {
|
||||
|
||||
private ConfigurableListableBeanFactory listableBeanFactory;
|
||||
|
||||
private ConfigurableListableBeanFactory dependentBeansBF;
|
||||
|
||||
protected void setUp() {
|
||||
@Before
|
||||
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()));
|
||||
|
|
@ -54,6 +59,7 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
this.listableBeanFactory = child;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
lbf.addBean("t1", new TestBean());
|
||||
|
|
@ -64,6 +70,7 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
/**
|
||||
* Check that override doesn't count as two separate beans.
|
||||
*/
|
||||
@Test
|
||||
public void testHierarchicalCountBeansWithOverride() throws Exception {
|
||||
// Leaf count
|
||||
assertTrue(this.listableBeanFactory.getBeanDefinitionCount() == 1);
|
||||
|
|
@ -73,14 +80,16 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalNamesWithNoMatch() throws Exception {
|
||||
List names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
HandlerAdapter.class));
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
NoOp.class));
|
||||
assertEquals(0, names.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalNamesWithMatchOnlyInRoot() throws Exception {
|
||||
List names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
IndexedTestBean.class));
|
||||
assertEquals(1, names.size());
|
||||
assertTrue(names.contains("indexedBean"));
|
||||
|
|
@ -88,8 +97,9 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
assertTrue(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class).length == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBeanNamesForTypeWithOverride() throws Exception {
|
||||
List names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
ITestBean.class));
|
||||
// includes 2 TestBeans from FactoryBeans (DummyFactory definitions)
|
||||
assertEquals(4, names.size());
|
||||
|
|
@ -99,13 +109,15 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
assertTrue(names.contains("testFactory2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoBeansOfType() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
lbf.addBean("foo", new Object());
|
||||
Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
assertTrue(beans.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindsBeansOfTypeWithStaticFactory() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
TestBean t1 = new TestBean();
|
||||
|
|
@ -118,7 +130,7 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
lbf.addBean("t3", t3);
|
||||
lbf.addBean("t4", t4);
|
||||
|
||||
Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
|
|
@ -147,6 +159,7 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
assertEquals(t4, beans.get("&t4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindsBeansOfTypeWithDefaultFactory() {
|
||||
Object test3 = this.listableBeanFactory.getBean("test3");
|
||||
Object test = this.listableBeanFactory.getBean("test");
|
||||
|
|
@ -161,7 +174,7 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
this.listableBeanFactory.registerSingleton("t3", t3);
|
||||
this.listableBeanFactory.registerSingleton("t4", t4);
|
||||
|
||||
Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
false);
|
||||
assertEquals(6, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
|
|
@ -212,11 +225,12 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
assertEquals(t4, beans.get("&t4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalResolutionWithOverride() throws Exception {
|
||||
Object test3 = this.listableBeanFactory.getBean("test3");
|
||||
Object test = this.listableBeanFactory.getBean("test");
|
||||
|
||||
Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
false);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
|
|
@ -250,21 +264,25 @@ public class BeanFactoryUtilsTests extends TestCase {
|
|||
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testADependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("a");
|
||||
assertTrue(ObjectUtils.isEmpty(deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("b");
|
||||
assertTrue(Arrays.equals(new String[] { "c" }, deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("c");
|
||||
assertTrue(Arrays.equals(new String[] { "int", "long" }, deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("int");
|
||||
assertTrue(Arrays.equals(new String[] { "buffer" }, deps));
|
||||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.security.AccessController;
|
||||
|
|
@ -33,23 +35,21 @@ import java.util.Set;
|
|||
|
||||
import javax.security.auth.Subject;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.interceptor.SideEffectBean;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.NestedTestBean;
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
import org.springframework.beans.PropertyEditorRegistrar;
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.TypeConverter;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.PropertyEditorRegistrar;
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
|
@ -67,11 +67,11 @@ 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;
|
||||
import org.springframework.beans.factory.xml.SideEffectBean;
|
||||
import org.springframework.beans.propertyeditors.CustomNumberEditor;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.test.AssertThrows;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
|
|
@ -81,12 +81,14 @@ import org.springframework.util.StopWatch;
|
|||
* @author Juergen Hoeller
|
||||
* @author Rick Evans
|
||||
* @author Sam Brannen
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class DefaultListableBeanFactoryTests extends TestCase {
|
||||
public class DefaultListableBeanFactoryTests {
|
||||
|
||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void testUnreferencedSingletonWasInstantiated() {
|
||||
KnowsIfInstantiated.clearInstantiationRecord();
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -98,6 +100,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyInitialization() {
|
||||
KnowsIfInstantiated.clearInstantiationRecord();
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -114,6 +117,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanDidNotCreatePrototype() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -135,6 +139,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -163,6 +168,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -191,6 +197,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -218,6 +225,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializedFactoryBeanFoundByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -276,6 +284,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("&x1", lbf.getAliases("&x2")[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticFactoryMethodFoundByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(TestBeanFactory.class);
|
||||
|
|
@ -300,6 +309,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertFalse(TestBeanFactory.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(TestBeanFactory.class);
|
||||
|
|
@ -325,6 +335,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertFalse(TestBeanFactory.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticFactoryMethodFoundByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition factoryBd = new RootBeanDefinition(TestBeanFactory.class);
|
||||
|
|
@ -352,6 +363,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertFalse(TestBeanFactory.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition factoryBd = new RootBeanDefinition(TestBeanFactory.class);
|
||||
|
|
@ -408,6 +420,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("&x1", lbf.getAliases("&x2")[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
ListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
assertTrue("No beans defined --> array != null", lbf.getBeanDefinitionNames() != null);
|
||||
|
|
@ -415,6 +428,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("No beans defined after no arg constructor", lbf.getBeanDefinitionCount() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyPropertiesPopulation() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -422,6 +436,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("No beans defined after ignorable invalid", lbf.getBeanDefinitionCount() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHarmlessIgnorableRubbish() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -431,6 +446,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("No beans defined after harmless ignorable rubbish", lbf.getBeanDefinitionCount() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesPopulationWithNullPrefix() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -442,6 +458,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
testSingleTestBean(lbf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesPopulationWithPrefix() {
|
||||
String PREFIX = "beans.";
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -454,6 +471,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
testSingleTestBean(lbf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleReference() {
|
||||
String PREFIX = "beans.";
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -477,6 +495,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Kerry spouse name is Rod", "Rod".equals(spouse.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesWithDotsInKey() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -492,6 +511,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("my.value", tb.getSomeMap().get("my.key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnresolvedReference() {
|
||||
String PREFIX = "beans.";
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -513,6 +533,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelfReference() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -522,6 +543,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(self, self.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPossibleMatches() {
|
||||
try {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -541,6 +563,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototype() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -575,6 +598,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Specified singletons equal", kerry1 == kerry2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCircleLeadsToException() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -598,6 +622,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeExtendsPrototype() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -640,6 +665,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Specified singletons equal", kerry1 == kerry2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanReferenceParentBeanFromChildViaAlias() {
|
||||
final String EXPECTED_NAME = "Juergen";
|
||||
final int EXPECTED_AGE = 41;
|
||||
|
|
@ -664,6 +690,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameAlreadyBound() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -690,6 +717,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Test bean age is 48", tb.getAge() == 48);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionOverriding() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
|
||||
|
|
@ -700,6 +728,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(lbf.getBean("test2") instanceof NestedTestBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionRemoval() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.setAllowBeanDefinitionOverriding(false);
|
||||
|
|
@ -714,6 +743,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(lbf.getBean("test2") instanceof NestedTestBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionOverridingNotAllowed() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.setAllowBeanDefinitionOverriding(false);
|
||||
|
|
@ -728,6 +758,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionOverridingWithAlias() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
|
||||
|
|
@ -738,6 +769,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(lbf.getBean("testAlias") instanceof NestedTestBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasChaining() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
|
||||
|
|
@ -750,6 +782,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertSame(bean, lbf.getBean("testAlias3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanReferenceWithNewSyntax() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -764,6 +797,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(k.getSpouse() == r);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanEscapeBeanReferenceSyntax() {
|
||||
String name = "*name";
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
|
|
@ -775,6 +809,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(r.getName().equals(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditor() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
|
|
@ -790,6 +825,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorWithBeanReference() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
|
|
@ -806,6 +842,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomTypeConverter() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
||||
|
|
@ -822,6 +859,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomTypeConverterWithBeanReference() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
||||
|
|
@ -839,6 +877,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterExistingSingletonWithReference() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -856,7 +895,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(singletonObject, lbf.getBean("singletonObject"));
|
||||
assertEquals(singletonObject, test.getSpouse());
|
||||
|
||||
Map beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
|
||||
Map<?, ?> beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
|
||||
assertEquals(2, beansOfType.size());
|
||||
assertTrue(beansOfType.containsValue(test));
|
||||
assertTrue(beansOfType.containsValue(singletonObject));
|
||||
|
|
@ -865,6 +904,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(2, beansOfType.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterExistingSingletonWithNameOverriding() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Properties p = new Properties();
|
||||
|
|
@ -884,7 +924,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(singletonObject, lbf.getBean("singletonObject"));
|
||||
assertEquals(singletonObject, test.getSpouse());
|
||||
|
||||
Map beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
|
||||
Map<?, ?> beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
|
||||
assertEquals(2, beansOfType.size());
|
||||
assertTrue(beansOfType.containsValue(test));
|
||||
assertTrue(beansOfType.containsValue(singletonObject));
|
||||
|
|
@ -893,6 +933,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(2, beansOfType.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterExistingSingletonWithAutowire() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -914,6 +955,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(singletonObject, test.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterExistingSingletonWithAlreadyBound() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
Object singletonObject = new TestBean();
|
||||
|
|
@ -927,6 +969,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReregisterBeanDefinition() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
|
||||
|
|
@ -939,6 +982,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(lbf.getBean("testBean") instanceof NestedTestBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayPropertyWithAutowiring() throws MalformedURLException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
|
||||
|
|
@ -952,6 +996,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(new UrlResource("http://localhost:9090"), ab.getResourceArray()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayPropertyWithOptionalAutowiring() throws MalformedURLException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
|
|
@ -962,6 +1007,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(ab.getResourceArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayConstructorWithAutowiring() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("integer1", new Integer(4));
|
||||
|
|
@ -975,6 +1021,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(new Integer(5), ab.getIntegerArray()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayConstructorWithOptionalAutowiring() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
|
|
@ -985,6 +1032,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(ab.getIntegerArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleArrayConstructorWithAutowiring() throws MalformedURLException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("integer1", new Integer(4));
|
||||
|
|
@ -1002,6 +1050,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(new UrlResource("http://localhost:9090"), ab.getResourceArray()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleArrayConstructorWithOptionalAutowiring() throws MalformedURLException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
|
||||
|
|
@ -1015,6 +1064,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(ab.getResourceArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireWithNoDependencies() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1025,6 +1075,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(registered instanceof NoDependencies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireWithSatisfiedJavaBeanDependency() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1040,6 +1091,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertSame(rod, kerry.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireWithSatisfiedConstructorDependency() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1054,6 +1106,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertSame(rod, kerry.spouse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireWithTwoMatchesForConstructorDependency() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||
|
|
@ -1071,6 +1124,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireWithUnsatisfiedConstructorDependency() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1087,6 +1141,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireConstructor() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1098,6 +1153,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByName() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1109,6 +1165,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByNameWithDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1122,6 +1179,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByNameWithNoDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1131,6 +1189,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(bean.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByType() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1147,6 +1206,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
|
||||
* target="_blank">SPR-4040</a>.
|
||||
*/
|
||||
@Test
|
||||
public void testAutowireBeanWithFactoryBeanByType() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(LazyInitFactory.class, new MutablePropertyValues());
|
||||
|
|
@ -1165,9 +1225,8 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
* Java method names. In other words, you can't name a method
|
||||
* <code>set&FactoryBean(...)</code>.
|
||||
*/
|
||||
@Test(expected=TypeMismatchException.class)
|
||||
public void testAutowireBeanWithFactoryBeanByName() {
|
||||
new AssertThrows(TypeMismatchException.class) {
|
||||
public void test() throws Exception {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(LazyInitFactory.class, new MutablePropertyValues());
|
||||
lbf.registerBeanDefinition("factoryBean", bd);
|
||||
|
|
@ -1175,9 +1234,8 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNotNull("The FactoryBean should have been registered.", factoryBean);
|
||||
lbf.autowire(FactoryBeanDependentBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByTypeWithTwoMatches() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1195,6 +1253,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByTypeWithDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
try {
|
||||
|
|
@ -1206,6 +1265,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireBeanByTypeWithNoDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
DependenciesBean bean = (DependenciesBean)
|
||||
|
|
@ -1213,6 +1273,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(bean.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByName() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1224,6 +1285,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertSame(spouse, BeanFactoryUtils.beanOfType(lbf, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByNameWithDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1238,6 +1300,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByNameWithNoDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1247,6 +1310,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(existingBean.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByType() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1257,6 +1321,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(existingBean.getSpouse(), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByTypeWithDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
DependenciesBean existingBean = new DependenciesBean();
|
||||
|
|
@ -1268,6 +1333,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireExistingBeanByTypeWithNoDependencyCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
DependenciesBean existingBean = new DependenciesBean();
|
||||
|
|
@ -1275,6 +1341,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(existingBean.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAutowireMode() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
try {
|
||||
|
|
@ -1285,6 +1352,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyBeanPropertyValues() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1296,6 +1364,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(99, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyBeanPropertyValuesWithIncompleteDefinition() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1309,6 +1378,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(tb.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureBean() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
|
@ -1322,6 +1392,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertNull(tb.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureBeanWithAutowiring() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
|
||||
|
|
@ -1336,6 +1407,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(spouse, tb.getSpouse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensiveCircularReference() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
|
@ -1352,6 +1424,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCircularReferenceThroughAutowiring() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
|
||||
|
|
@ -1363,6 +1436,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCircularReferenceThroughFactoryBeanAutowiring() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
|
||||
|
|
@ -1374,6 +1448,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCircularReferenceThroughFactoryBeanTypeCheck() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
|
||||
|
|
@ -1385,6 +1460,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAvoidCircularReferenceThroughAutowiring() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
|
||||
|
|
@ -1393,6 +1469,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
lbf.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionWithInterface() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(ITestBean.class));
|
||||
|
|
@ -1406,6 +1483,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionWithAbstractClass() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class));
|
||||
|
|
@ -1419,12 +1497,14 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeFactoryBeanNotEagerlyCalled() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class));
|
||||
lbf.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyInitFactory() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(LazyInitFactory.class));
|
||||
|
|
@ -1433,6 +1513,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertFalse(factory.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSmartInitFactory() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test", new RootBeanDefinition(EagerInitFactory.class));
|
||||
|
|
@ -1441,6 +1522,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue(factory.initialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeFactoryBeanNotEagerlyCalledInCaseOfBeanClassName() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
lbf.registerBeanDefinition("test",
|
||||
|
|
@ -1448,9 +1530,10 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
lbf.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeWithArrayConversionForConstructor() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
List list = new ManagedList();
|
||||
List<String> list = new ManagedList<String>();
|
||||
list.add("myName");
|
||||
list.add("myBeanName");
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
|
||||
|
|
@ -1466,9 +1549,10 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("myBeanName", tb2.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeWithArrayConversionForFactoryMethod() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
List list = new ManagedList();
|
||||
List<String> list = new ManagedList<String>();
|
||||
list.add("myName");
|
||||
list.add("myBeanName");
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
|
||||
|
|
@ -1485,6 +1569,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("myBeanName", tb2.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1504,6 +1589,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1526,6 +1612,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @Test
|
||||
* public void testPrototypeCreationIsFastEnough2() throws Exception {
|
||||
* if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
* // Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1547,6 +1634,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
* }
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1571,6 +1659,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @Test
|
||||
* public void testPrototypeCreationWithConstructorArgumentsIsFastEnough2() throws Exception {
|
||||
* if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
* // Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1595,6 +1684,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
* }
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1618,6 +1708,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithPropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1666,7 +1757,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
* assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 750);
|
||||
* }
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
@ -1690,6 +1781,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanPostProcessorWithWrappedObjectAndDisposableBean() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDisposableBean.class);
|
||||
|
|
@ -1709,6 +1801,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Destroy method invoked", BeanWithDisposableBean.closed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanPostProcessorWithWrappedObjectAndDestroyMethod() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class);
|
||||
|
|
@ -1729,10 +1822,12 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Destroy method invoked", BeanWithDestroyMethod.closed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindTypeOfSingletonFactoryMethodOnBeanInstance() {
|
||||
findTypeOfPrototypeFactoryMethodOnBeanInstance(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindTypeOfPrototypeFactoryMethodOnBeanInstance() {
|
||||
findTypeOfPrototypeFactoryMethodOnBeanInstance(false);
|
||||
}
|
||||
|
|
@ -1783,7 +1878,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
lbf.registerBeanDefinition("fmWithArgs", factoryMethodDefinitionWithArgs);
|
||||
|
||||
assertEquals(4, lbf.getBeanDefinitionCount());
|
||||
List tbNames = Arrays.asList(lbf.getBeanNamesForType(TestBean.class));
|
||||
List<String> tbNames = Arrays.asList(lbf.getBeanNamesForType(TestBean.class));
|
||||
assertTrue(tbNames.contains("fmWithProperties"));
|
||||
assertTrue(tbNames.contains("fmWithArgs"));
|
||||
assertEquals(2, tbNames.size());
|
||||
|
|
@ -1819,6 +1914,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals(expectedNameFromArgs, tb2.getName());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testScopingBeanToUnregisteredScopeResultsInAnException() throws Exception {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||
AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
|
|
@ -1826,13 +1922,10 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
|
||||
final DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
factory.registerBeanDefinition("testBean", beanDefinition);
|
||||
new AssertThrows(IllegalStateException.class) {
|
||||
public void test() throws Exception {
|
||||
factory.getBean("testBean");
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitScopeInheritanceForChildBeanDefinitions() throws Exception {
|
||||
String theChildScope = "bonanza!";
|
||||
|
||||
|
|
@ -1852,6 +1945,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitScopeInheritanceForChildBeanDefinitions() throws Exception {
|
||||
RootBeanDefinition parent = new RootBeanDefinition();
|
||||
parent.setScope("bonanza!");
|
||||
|
|
@ -1867,14 +1961,17 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
assertTrue("Child 'scope' not overriding parent scope (it must).", def.isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldSettingWithInstantiationAwarePostProcessorNoShortCircuit() {
|
||||
doTestFieldSettingWithInstantiationAwarePostProcessor(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldSettingWithInstantiationAwarePostProcessorWithShortCircuit() {
|
||||
doTestFieldSettingWithInstantiationAwarePostProcessor(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void doTestFieldSettingWithInstantiationAwarePostProcessor(final boolean skipPropertyPopulation) {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||
|
|
@ -1909,6 +2006,8 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInitSecurityAwarePrototypeBean() {
|
||||
final DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestSecuredBean.class);
|
||||
|
|
@ -1963,7 +2062,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class ConstructorDependencyFactoryBean implements FactoryBean {
|
||||
public static class ConstructorDependencyFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
public ConstructorDependencyFactoryBean(String dependency) {
|
||||
}
|
||||
|
|
@ -1972,7 +2071,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
return "test";
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
|
@ -2028,13 +2127,13 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class FactoryBeanThatShouldntBeCalled implements FactoryBean {
|
||||
public static class FactoryBeanThatShouldntBeCalled implements FactoryBean<Object> {
|
||||
|
||||
public Object getObject() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -2044,7 +2143,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class LazyInitFactory implements FactoryBean {
|
||||
public static class LazyInitFactory implements FactoryBean<Object> {
|
||||
|
||||
public boolean initialized = false;
|
||||
|
||||
|
|
@ -2053,7 +2152,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
return "";
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
|
@ -2063,7 +2162,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class EagerInitFactory implements SmartFactoryBean {
|
||||
public static class EagerInitFactory implements SmartFactoryBean<Object> {
|
||||
|
||||
public boolean initialized = false;
|
||||
|
||||
|
|
@ -2072,7 +2171,7 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
return "";
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
|
@ -2145,14 +2244,14 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
*/
|
||||
private static class FactoryBeanDependentBean {
|
||||
|
||||
private FactoryBean factoryBean;
|
||||
private FactoryBean<?> factoryBean;
|
||||
|
||||
|
||||
public final FactoryBean getFactoryBean() {
|
||||
public final FactoryBean<?> getFactoryBean() {
|
||||
return this.factoryBean;
|
||||
}
|
||||
|
||||
public final void setFactoryBean(final FactoryBean factoryBean) {
|
||||
public final void setFactoryBean(final FactoryBean<?> factoryBean) {
|
||||
this.factoryBean = factoryBean;
|
||||
}
|
||||
}
|
||||
|
|
@ -2166,10 +2265,12 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
this.numberFormat = numberFormat;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertIfNecessary(Object value, Class requiredType) {
|
||||
return convertIfNecessary(value, requiredType, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertIfNecessary(Object value, Class requiredType, MethodParameter methodParam) {
|
||||
if (value instanceof String && Float.class.isAssignableFrom(requiredType)) {
|
||||
try {
|
||||
|
|
@ -2230,12 +2331,12 @@ public class DefaultListableBeanFactoryTests extends TestCase {
|
|||
setNameFromPrincipal(subject.getPrincipals());
|
||||
}
|
||||
|
||||
private void setNameFromPrincipal(Set principals) {
|
||||
private void setNameFromPrincipal(Set<Principal> principals) {
|
||||
if (principals == null) {
|
||||
return;
|
||||
}
|
||||
for (Iterator it = principals.iterator(); it.hasNext();) {
|
||||
Principal p = (Principal) it.next();
|
||||
for (Iterator<Principal> it = principals.iterator(); it.hasNext();) {
|
||||
Principal p = it.next();
|
||||
this.userName = p.getName();
|
||||
return;
|
||||
}
|
||||
|
|
@ -16,28 +16,36 @@
|
|||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class FactoryBeanTests extends TestCase {
|
||||
public class FactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanReturnsNull() throws Exception {
|
||||
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("factoryBeanReturnsNull.xml", getClass()));
|
||||
Object result = factory.getBean("factoryBean");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeansWithAutowiring() throws Exception {
|
||||
ClassPathXmlApplicationContext factory =
|
||||
new ClassPathXmlApplicationContext("factoryBeansWithAutowiring.xml", getClass());
|
||||
XmlBeanFactory factory =
|
||||
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
|
||||
|
||||
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
|
||||
ppc.postProcessBeanFactory(factory);
|
||||
|
||||
Alpha alpha = (Alpha) factory.getBean("alpha");
|
||||
Beta beta = (Beta) factory.getBean("beta");
|
||||
Gamma gamma = (Gamma) factory.getBean("gamma");
|
||||
|
|
@ -48,9 +56,14 @@ public class FactoryBeanTests extends TestCase {
|
|||
assertEquals("yourName", beta.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
|
||||
ClassPathXmlApplicationContext factory =
|
||||
new ClassPathXmlApplicationContext("factoryBeansWithAutowiring.xml", getClass());
|
||||
XmlBeanFactory factory =
|
||||
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
|
||||
|
||||
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
|
||||
ppc.postProcessBeanFactory(factory);
|
||||
|
||||
Beta beta = (Beta) factory.getBean("beta");
|
||||
Alpha alpha = (Alpha) factory.getBean("alpha");
|
||||
Gamma gamma = (Gamma) factory.getBean("gamma");
|
||||
|
|
@ -59,13 +72,13 @@ public class FactoryBeanTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class NullReturningFactoryBean implements FactoryBean {
|
||||
public static class NullReturningFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
public Object getObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +138,7 @@ public class FactoryBeanTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public static class BetaFactoryBean implements FactoryBean {
|
||||
public static class BetaFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
private Beta beta;
|
||||
|
||||
|
|
@ -137,7 +150,7 @@ public class FactoryBeanTests extends TestCase {
|
|||
return this.beta;
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<?> getObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -3,24 +3,11 @@
|
|||
|
||||
<beans default-lazy-init="true">
|
||||
|
||||
<bean id="abstractBeta" class="org.springframework.aop.framework.ProxyFactoryBean"
|
||||
abstract="true"/>
|
||||
|
||||
<bean name="beta" parent="abstractBeta">
|
||||
<property name="target">
|
||||
<bean class="org.springframework.beans.factory.FactoryBeanTests$Beta" autowire="byType">
|
||||
<bean name="beta" class="org.springframework.beans.factory.FactoryBeanTests$Beta" autowire="byType">
|
||||
<property name="name" value="${myName}"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="proxyTargetClass" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="alpha" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="target">
|
||||
<bean class="org.springframework.beans.factory.FactoryBeanTests$Alpha" autowire="byType"/>
|
||||
</property>
|
||||
<property name="proxyTargetClass" value="true"/>
|
||||
</bean>
|
||||
<bean id="alpha" class="org.springframework.beans.factory.FactoryBeanTests$Alpha" autowire="byType"/>
|
||||
|
||||
<bean id="gamma" class="org.springframework.beans.factory.FactoryBeanTests$Gamma"/>
|
||||
|
||||
|
|
@ -30,7 +17,7 @@
|
|||
|
||||
<bean id="gammaFactory" factory-bean="betaFactory" factory-method="getGamma"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="myName">yourName</prop>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<!--
|
||||
Just included for the count: not to mean anything in particular
|
||||
-->
|
||||
<bean id="something" class="org.springframework.aop.support.DefaultPointcutAdvisor"/>
|
||||
<bean id="something" class="org.springframework.beans.GenericIntegerBean"/>
|
||||
|
||||
<bean id="indexedBean" class="org.springframework.beans.IndexedTestBean"/>
|
||||
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
public class ConstructorDependenciesBean implements Serializable {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse1;
|
||||
|
||||
private TestBean spouse2;
|
||||
|
||||
private IndexedTestBean other;
|
||||
|
||||
public ConstructorDependenciesBean(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1) {
|
||||
this.spouse1 = spouse1;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, int age) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TestBean getSpouse1() {
|
||||
return spouse1;
|
||||
}
|
||||
|
||||
public TestBean getSpouse2() {
|
||||
return spouse2;
|
||||
}
|
||||
|
||||
public IndexedTestBean getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
|
||||
/**
|
||||
* Simple bean used to test dependency checking.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 04.09.2003
|
||||
*/
|
||||
public class DependenciesBean implements BeanFactoryAware {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setSpouse(TestBean spouse) {
|
||||
this.spouse = spouse;
|
||||
}
|
||||
|
||||
public TestBean getSpouse() {
|
||||
return spouse;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.springframework.beans.factory.xml;
|
||||
/**
|
||||
* Bean that changes state on a business invocation, so that
|
||||
* we can check whether it's been invoked
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class SideEffectBean {
|
||||
|
||||
private int count;
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void doWork() {
|
||||
++count;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Used in the tests for the FieldRetrievingFactoryBean class
|
||||
* (c.f. FieldRetrievingFactoryBeanTests)
|
||||
*
|
||||
* @author Rick Evans
|
||||
*/
|
||||
class PackageLevelVisibleBean {
|
||||
|
||||
public static final String CONSTANT = "Wuby";
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
|
||||
default-autowire-candidates="">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" autowire-candidate="true"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="true">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
|
||||
default-autowire-candidates="props*,*ly">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="someProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=someProps</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Loading…
Reference in New Issue