use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method doTestAutowire.
private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception {
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
TestBean kerry = (TestBean) xbf.getBean("spouse");
// should have been autowired
assertEquals(kerry, rod1.getSpouse());
DependenciesBean rod1a = (DependenciesBean) xbf.getBean("rod1a");
// should have been autowired
assertEquals(kerry, rod1a.getSpouse());
DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
// should have been autowired
assertEquals(kerry, rod2.getSpouse());
DependenciesBean rod2a = (DependenciesBean) xbf.getBean("rod2a");
// should have been set explicitly
assertEquals(kerry, rod2a.getSpouse());
ConstructorDependenciesBean rod3 = (ConstructorDependenciesBean) xbf.getBean("rod3");
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
// should have been autowired
assertEquals(kerry, rod3.getSpouse1());
assertEquals(kerry, rod3.getSpouse2());
assertEquals(other, rod3.getOther());
ConstructorDependenciesBean rod3a = (ConstructorDependenciesBean) xbf.getBean("rod3a");
// should have been autowired
assertEquals(kerry, rod3a.getSpouse1());
assertEquals(kerry, rod3a.getSpouse2());
assertEquals(other, rod3a.getOther());
try {
xbf.getBean("rod4", ConstructorDependenciesBean.class);
fail("Must have thrown a FatalBeanException");
} catch (FatalBeanException expected) {
// expected
}
DependenciesBean rod5 = (DependenciesBean) xbf.getBean("rod5");
// Should not have been autowired
assertNull(rod5.getSpouse());
BeanFactory appCtx = (BeanFactory) xbf.getBean("childAppCtx");
assertTrue(appCtx.containsBean("rod1"));
assertTrue(appCtx.containsBean("jenny"));
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testAutowireWithDefault.
@Test
public void testAutowireWithDefault() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT);
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
// should have been autowired
assertNotNull(rod1.getSpouse());
assertTrue(rod1.getSpouse().getName().equals("Kerry"));
DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
// should have been autowired
assertNotNull(rod2.getSpouse());
assertTrue(rod2.getSpouse().getName().equals("Kerry"));
}
Aggregations