use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireWithSatisfiedJavaBeanDependency.
@Test
public void testAutowireWithSatisfiedJavaBeanDependency() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
// Depends on age, name and spouse (TestBean)
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertEquals(1, lbf.getBeanDefinitionCount());
DependenciesBean kerry = (DependenciesBean) registered;
TestBean rod = (TestBean) lbf.getBean("rod");
assertSame(rod, kerry.getSpouse());
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByType.
@Test
public void testAutowireExistingBeanByType() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
TestBean test = (TestBean) lbf.getBean("test");
assertEquals(existingBean.getSpouse(), test);
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypeWithTwoMatchesAndPriority.
@Test
public void testAutowireBeanByTypeWithTwoMatchesAndPriority() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(LowPriorityTestBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("test")));
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByNameWithNoDependencyCheck.
@Test
public void testAutowireExistingBeanByNameWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spous", bd);
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
assertNull(existingBean.getSpouse());
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByType.
@Test
public void testAutowireBeanByType() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
TestBean test = (TestBean) lbf.getBean("test");
assertEquals(test, bean.getSpouse());
}
Aggregations