|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -123,16 +123,16 @@ public class XmlBeanFactoryTests { |
|
|
|
return new ClassPathResource(CLASSNAME + suffix, CLASS); |
|
|
|
return new ClassPathResource(CLASSNAME + suffix, CLASS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* SPR-2368 */ |
|
|
|
|
|
|
|
@Test |
|
|
|
@Test // SPR-2368
|
|
|
|
public void testCollectionsReferredToAsRefLocals() throws Exception { |
|
|
|
public void testCollectionsReferredToAsRefLocals() { |
|
|
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(COLLECTIONS_XSD_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(COLLECTIONS_XSD_CONTEXT); |
|
|
|
factory.preInstantiateSingletons(); |
|
|
|
factory.preInstantiateSingletons(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRefToSeparatePrototypeInstances() throws Exception { |
|
|
|
public void testRefToSeparatePrototypeInstances() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); |
|
|
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); |
|
|
|
@ -151,7 +151,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRefToSingleton() throws Exception { |
|
|
|
public void testRefToSingleton() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); |
|
|
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); |
|
|
|
@ -307,7 +307,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInheritanceFromParentFactoryPrototype() throws Exception { |
|
|
|
public void testInheritanceFromParentFactoryPrototype() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -323,7 +323,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInheritanceWithDifferentClass() throws Exception { |
|
|
|
public void testInheritanceWithDifferentClass() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -338,7 +338,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInheritanceWithClass() throws Exception { |
|
|
|
public void testInheritanceWithClass() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -353,7 +353,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception { |
|
|
|
public void testPrototypeInheritanceFromParentFactoryPrototype() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -373,7 +373,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPrototypeInheritanceFromParentFactorySingleton() throws Exception { |
|
|
|
public void testPrototypeInheritanceFromParentFactorySingleton() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -433,7 +433,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDependenciesMaterializeThis() throws Exception { |
|
|
|
public void testDependenciesMaterializeThis() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEP_MATERIALIZE_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEP_MATERIALIZE_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
@ -452,7 +452,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testChildOverridesParentBean() throws Exception { |
|
|
|
public void testChildOverridesParentBean() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -471,7 +471,7 @@ public class XmlBeanFactoryTests { |
|
|
|
* If a singleton does this the factory will fail to load. |
|
|
|
* If a singleton does this the factory will fail to load. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBogusParentageFromParentFactory() throws Exception { |
|
|
|
public void testBogusParentageFromParentFactory() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -482,7 +482,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (BeanDefinitionStoreException ex) { |
|
|
|
catch (BeanDefinitionStoreException ex) { |
|
|
|
// check exception message contains the name
|
|
|
|
// check exception message contains the name
|
|
|
|
assertTrue(ex.getMessage().indexOf("bogusParent") != -1); |
|
|
|
assertTrue(ex.getMessage().contains("bogusParent")); |
|
|
|
assertTrue(ex.getCause() instanceof NoSuchBeanDefinitionException); |
|
|
|
assertTrue(ex.getCause() instanceof NoSuchBeanDefinitionException); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -493,7 +493,7 @@ public class XmlBeanFactoryTests { |
|
|
|
* instances even if derived from a prototype |
|
|
|
* instances even if derived from a prototype |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSingletonInheritsFromParentFactoryPrototype() throws Exception { |
|
|
|
public void testSingletonInheritsFromParentFactoryPrototype() { |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); |
|
|
|
@ -658,7 +658,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInitMethodIsInvoked() throws Exception { |
|
|
|
public void testInitMethodIsInvoked() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1"); |
|
|
|
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1"); |
|
|
|
@ -678,14 +678,14 @@ public class XmlBeanFactoryTests { |
|
|
|
fail(); |
|
|
|
fail(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
assertTrue(ex.getResourceDescription().indexOf("initializers.xml") != -1); |
|
|
|
assertTrue(ex.getResourceDescription().contains("initializers.xml")); |
|
|
|
assertEquals("init-method2", ex.getBeanName()); |
|
|
|
assertEquals("init-method2", ex.getBeanName()); |
|
|
|
assertTrue(ex.getCause() instanceof IOException); |
|
|
|
assertTrue(ex.getCause() instanceof IOException); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNoSuchInitMethod() throws Exception { |
|
|
|
public void testNoSuchInitMethod() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -694,9 +694,9 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (FatalBeanException ex) { |
|
|
|
catch (FatalBeanException ex) { |
|
|
|
// check message is helpful
|
|
|
|
// check message is helpful
|
|
|
|
assertTrue(ex.getMessage().indexOf("initializers.xml") != -1); |
|
|
|
assertTrue(ex.getMessage().contains("initializers.xml")); |
|
|
|
assertTrue(ex.getMessage().indexOf("init-method3") != -1); |
|
|
|
assertTrue(ex.getMessage().contains("init-method3")); |
|
|
|
assertTrue(ex.getMessage().indexOf("init") != -1); |
|
|
|
assertTrue(ex.getMessage().contains("init")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -704,7 +704,7 @@ public class XmlBeanFactoryTests { |
|
|
|
* Check that InitializingBean method is called first. |
|
|
|
* Check that InitializingBean method is called first. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInitializingBeanAndInitMethod() throws Exception { |
|
|
|
public void testInitializingBeanAndInitMethod() { |
|
|
|
InitAndIB.constructed = false; |
|
|
|
InitAndIB.constructed = false; |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
@ -725,7 +725,7 @@ public class XmlBeanFactoryTests { |
|
|
|
* Check that InitializingBean method is not called twice. |
|
|
|
* Check that InitializingBean method is not called twice. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInitializingBeanAndSameInitMethod() throws Exception { |
|
|
|
public void testInitializingBeanAndSameInitMethod() { |
|
|
|
InitAndIB.constructed = false; |
|
|
|
InitAndIB.constructed = false; |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); |
|
|
|
@ -743,7 +743,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDefaultLazyInit() throws Exception { |
|
|
|
public void testDefaultLazyInit() { |
|
|
|
InitAndIB.constructed = false; |
|
|
|
InitAndIB.constructed = false; |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT); |
|
|
|
@ -759,19 +759,19 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = BeanDefinitionStoreException.class) |
|
|
|
@Test(expected = BeanDefinitionStoreException.class) |
|
|
|
public void noSuchXmlFile() throws Exception { |
|
|
|
public void noSuchXmlFile() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(MISSING_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(MISSING_CONTEXT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = BeanDefinitionStoreException.class) |
|
|
|
@Test(expected = BeanDefinitionStoreException.class) |
|
|
|
public void invalidXmlFile() throws Exception { |
|
|
|
public void invalidXmlFile() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INVALID_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INVALID_CONTEXT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutowire() throws Exception { |
|
|
|
public void testAutowire() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT); |
|
|
|
TestBean spouse = new TestBean("kerry", 0); |
|
|
|
TestBean spouse = new TestBean("kerry", 0); |
|
|
|
@ -780,7 +780,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutowireWithParent() throws Exception { |
|
|
|
public void testAutowireWithParent() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT); |
|
|
|
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); |
|
|
|
@ -793,7 +793,7 @@ public class XmlBeanFactoryTests { |
|
|
|
doTestAutowire(xbf); |
|
|
|
doTestAutowire(xbf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception { |
|
|
|
private void doTestAutowire(DefaultListableBeanFactory xbf) { |
|
|
|
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1"); |
|
|
|
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1"); |
|
|
|
TestBean kerry = (TestBean) xbf.getBean("spouse"); |
|
|
|
TestBean kerry = (TestBean) xbf.getBean("spouse"); |
|
|
|
// should have been autowired
|
|
|
|
// should have been autowired
|
|
|
|
@ -842,7 +842,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutowireWithDefault() throws Exception { |
|
|
|
public void testAutowireWithDefault() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
@ -858,7 +858,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutowireByConstructor() throws Exception { |
|
|
|
public void testAutowireByConstructor() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1"); |
|
|
|
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1"); |
|
|
|
@ -896,7 +896,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutowireByConstructorWithSimpleValues() throws Exception { |
|
|
|
public void testAutowireByConstructorWithSimpleValues() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
@ -934,7 +934,7 @@ public class XmlBeanFactoryTests { |
|
|
|
xbf.getBean("rod2Accessor"); |
|
|
|
xbf.getBean("rod2Accessor"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
assertTrue(ex.toString().indexOf("touchy") != -1); |
|
|
|
assertTrue(ex.toString().contains("touchy")); |
|
|
|
ex.printStackTrace(); |
|
|
|
ex.printStackTrace(); |
|
|
|
assertNull(ex.getRelatedCauses()); |
|
|
|
assertNull(ex.getRelatedCauses()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1014,14 +1014,14 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = BeanCreationException.class) |
|
|
|
@Test(expected = BeanCreationException.class) |
|
|
|
public void throwsExceptionOnTooManyArguments() throws Exception { |
|
|
|
public void throwsExceptionOnTooManyArguments() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
xbf.getBean("rod7", ConstructorDependenciesBean.class); |
|
|
|
xbf.getBean("rod7", ConstructorDependenciesBean.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = UnsatisfiedDependencyException.class) |
|
|
|
@Test(expected = UnsatisfiedDependencyException.class) |
|
|
|
public void throwsExceptionOnAmbiguousResolution() throws Exception { |
|
|
|
public void throwsExceptionOnAmbiguousResolution() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); |
|
|
|
xbf.getBean("rod8", ConstructorDependenciesBean.class); |
|
|
|
xbf.getBean("rod8", ConstructorDependenciesBean.class); |
|
|
|
@ -1115,7 +1115,7 @@ public class XmlBeanFactoryTests { |
|
|
|
fail("Must have thrown a CannotLoadBeanClassException"); |
|
|
|
fail("Must have thrown a CannotLoadBeanClassException"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (CannotLoadBeanClassException ex) { |
|
|
|
catch (CannotLoadBeanClassException ex) { |
|
|
|
assertTrue(ex.getResourceDescription().indexOf("classNotFound.xml") != -1); |
|
|
|
assertTrue(ex.getResourceDescription().contains("classNotFound.xml")); |
|
|
|
assertTrue(ex.getCause() instanceof ClassNotFoundException); |
|
|
|
assertTrue(ex.getCause() instanceof ClassNotFoundException); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1367,12 +1367,12 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (BeanDefinitionStoreException ex) { |
|
|
|
catch (BeanDefinitionStoreException ex) { |
|
|
|
// Check that the bogus method name was included in the error message
|
|
|
|
// Check that the bogus method name was included in the error message
|
|
|
|
assertTrue("Bogus method name correctly reported", ex.getMessage().indexOf("bogusMethod") != -1); |
|
|
|
assertTrue("Bogus method name correctly reported", ex.getMessage().contains("bogusMethod")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void serializableMethodReplacerAndSuperclass() throws Exception { |
|
|
|
public void serializableMethodReplacerAndSuperclass() throws IOException { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); |
|
|
|
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT); |
|
|
|
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT); |
|
|
|
@ -1571,7 +1571,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithDuplicateName() throws Exception { |
|
|
|
public void testWithDuplicateName() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAMES_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAMES_CONTEXT); |
|
|
|
@ -1583,7 +1583,7 @@ public class XmlBeanFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithDuplicateNameInAlias() throws Exception { |
|
|
|
public void testWithDuplicateNameInAlias() { |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT); |
|
|
|
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT); |
|
|
|
|