use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByTypeWithDependencyCheck.
@Test
public void testAutowireExistingBeanByTypeWithDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
DependenciesBean existingBean = new DependenciesBean();
try {
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
fail("Should have thrown UnsatisfiedDependencyException");
} catch (UnsatisfiedDependencyException expected) {
}
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testRegisterExistingSingletonWithAutowire.
@Test
public void testRegisterExistingSingletonWithAutowire() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Tony");
pvs.add("age", "48");
RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class);
bd.setPropertyValues(pvs);
bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
lbf.registerBeanDefinition("test", bd);
Object singletonObject = new TestBean();
lbf.registerSingleton("singletonObject", singletonObject);
assertTrue(lbf.containsBean("singletonObject"));
assertTrue(lbf.isSingleton("singletonObject"));
assertEquals(TestBean.class, lbf.getType("singletonObject"));
assertEquals(0, lbf.getAliases("singletonObject").length);
DependenciesBean test = (DependenciesBean) lbf.getBean("test");
assertEquals(singletonObject, lbf.getBean("singletonObject"));
assertEquals(singletonObject, test.getSpouse());
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByName.
@Test
public void testAutowireExistingBeanByName() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertEquals(existingBean.getSpouse(), spouse);
assertSame(spouse, BeanFactoryUtils.beanOfType(lbf, TestBean.class));
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByNameWithDependencyCheck.
@Test
public void testAutowireExistingBeanByNameWithDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spous", bd);
DependenciesBean existingBean = new DependenciesBean();
try {
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
fail("Should have thrown UnsatisfiedDependencyException");
} catch (UnsatisfiedDependencyException ex) {
// expected
}
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireExistingBeanByTypeWithNoDependencyCheck.
@Test
public void testAutowireExistingBeanByTypeWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertNull(existingBean.getSpouse());
}
Aggregations