use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPropertiesWithDotsInKey.
@Test
public void testPropertiesWithDotsInKey() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("tb.(class)", TestBean.class.getName());
p.setProperty("tb.someMap[my.key]", "my.value");
int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertTrue("1 beans registered, not " + count, count == 1);
assertEquals(1, lbf.getBeanDefinitionCount());
TestBean tb = lbf.getBean("tb", TestBean.class);
assertEquals("my.value", tb.getSomeMap().get("my.key"));
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testSingleTestBean.
private void testSingleTestBean(ListableBeanFactory lbf) {
assertTrue("1 beans defined", lbf.getBeanDefinitionCount() == 1);
String[] names = lbf.getBeanDefinitionNames();
assertTrue(names != lbf.getBeanDefinitionNames());
assertTrue("Array length == 1", names.length == 1);
assertTrue("0th element == test", names[0].equals("test"));
TestBean tb = (TestBean) lbf.getBean("test");
assertTrue("Test is non null", tb != null);
assertTrue("Test bean name is Tony", "Tony".equals(tb.getName()));
assertTrue("Test bean age is 48", tb.getAge() == 48);
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByName.
@Test
public void testAutowireBeanByName() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertEquals(spouse, bean.getSpouse());
assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testGetBeanByTypeFiltersOutNonAutowireCandidates.
@Test
public void testGetBeanByTypeFiltersOutNonAutowireCandidates() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
RootBeanDefinition na1 = new RootBeanDefinition(TestBean.class);
na1.setAutowireCandidate(false);
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("na1", na1);
// na1 was filtered
TestBean actual = lbf.getBean(TestBean.class);
assertSame(lbf.getBean("bd1", TestBean.class), actual);
lbf.registerBeanDefinition("bd2", bd2);
try {
lbf.getBean(TestBean.class);
fail("Should have thrown NoSuchBeanDefinitionException");
} catch (NoSuchBeanDefinitionException ex) {
// expected
}
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testConfigureBeanWithAutowiring.
@Test
public void testConfigureBeanWithAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME);
lbf.registerBeanDefinition("test", tbd);
TestBean tb = new TestBean();
lbf.configureBean(tb, "test");
assertSame(lbf, tb.getBeanFactory());
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertEquals(spouse, tb.getSpouse());
}
Aggregations