use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testEmptyPropertiesPopulation.
@Test
public void testEmptyPropertiesPopulation() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertTrue("No beans defined after ignorable invalid", lbf.getBeanDefinitionCount() == 0);
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPropertiesPopulationWithNullPrefix.
@Test
public void testPropertiesPopulationWithNullPrefix() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("test.(class)", TestBean.class.getName());
p.setProperty("test.name", "Tony");
p.setProperty("test.age", "48");
int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertTrue("1 beans registered, not " + count, count == 1);
testSingleTestBean(lbf);
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPrototypeExtendsPrototype.
@Test
public void testPrototypeExtendsPrototype() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("wife.(class)", TestBean.class.getName());
p.setProperty("wife.name", "kerry");
p.setProperty("kerry.(parent)", "wife");
p.setProperty("kerry.age", "35");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
TestBean kerry1 = (TestBean) lbf.getBean("kerry");
TestBean kerry2 = (TestBean) lbf.getBean("kerry");
assertEquals("kerry", kerry1.getName());
assertNotNull("Non null", kerry1);
assertTrue("Singletons equal", kerry1 == kerry2);
lbf = new DefaultListableBeanFactory();
p = new Properties();
p.setProperty("wife.(class)", TestBean.class.getName());
p.setProperty("wife.name", "kerry");
p.setProperty("wife.(singleton)", "false");
p.setProperty("kerry.(parent)", "wife");
p.setProperty("kerry.(singleton)", "false");
p.setProperty("kerry.age", "35");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertFalse(lbf.isSingleton("kerry"));
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertTrue("Non null", kerry1 != null);
assertTrue("Prototypes NOT equal", kerry1 != kerry2);
lbf = new DefaultListableBeanFactory();
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.(singleton)", "true");
p.setProperty("kerry.age", "35");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertTrue("Non null", kerry1 != null);
assertTrue("Specified singletons equal", kerry1 == kerry2);
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testRegisterExistingSingletonWithNameOverriding.
@Test
public void testRegisterExistingSingletonWithNameOverriding() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("test.(class)", TestBean.class.getName());
p.setProperty("test.name", "Tony");
p.setProperty("test.age", "48");
p.setProperty("test.spouse(ref)", "singletonObject");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
lbf.registerBeanDefinition("singletonObject", new RootBeanDefinition(PropertiesFactoryBean.class));
Object singletonObject = new TestBean();
lbf.registerSingleton("singletonObject", singletonObject);
lbf.preInstantiateSingletons();
assertTrue(lbf.isSingleton("singletonObject"));
assertEquals(TestBean.class, lbf.getType("singletonObject"));
TestBean test = (TestBean) lbf.getBean("test");
assertEquals(singletonObject, lbf.getBean("singletonObject"));
assertEquals(singletonObject, test.getSpouse());
Map<?, ?> beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
assertEquals(2, beansOfType.size());
assertTrue(beansOfType.containsValue(test));
assertTrue(beansOfType.containsValue(singletonObject));
beansOfType = lbf.getBeansOfType(null, false, true);
Iterator<String> beanNames = lbf.getBeanNamesIterator();
assertEquals("test", beanNames.next());
assertEquals("singletonObject", beanNames.next());
assertFalse(beanNames.hasNext());
assertEquals(2, beansOfType.size());
assertTrue(lbf.containsSingleton("test"));
assertTrue(lbf.containsSingleton("singletonObject"));
assertTrue(lbf.containsBeanDefinition("test"));
assertTrue(lbf.containsBeanDefinition("singletonObject"));
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPrototypeCircleLeadsToException.
@Test
public void testPrototypeCircleLeadsToException() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.(singleton)", "false");
p.setProperty("kerry.age", "35");
p.setProperty("kerry.spouse", "*rod");
p.setProperty("rod.(class)", TestBean.class.getName());
p.setProperty("rod.(singleton)", "false");
p.setProperty("rod.age", "34");
p.setProperty("rod.spouse", "*kerry");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
try {
lbf.getBean("kerry");
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
// expected
assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
}
}
Aggregations