use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testBeanReferenceWithNewSyntax.
@Test
public void testBeanReferenceWithNewSyntax() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("r.(class)", TestBean.class.getName());
p.setProperty("r.name", "rod");
p.setProperty("k.(class)", TestBean.class.getName());
p.setProperty("k.name", "kerry");
p.setProperty("k.spouse", "*r");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
TestBean k = (TestBean) lbf.getBean("k");
TestBean r = (TestBean) lbf.getBean("r");
assertTrue(k.getSpouse() == r);
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPropertiesPopulationWithPrefix.
@Test
public void testPropertiesPopulationWithPrefix() {
String PREFIX = "beans.";
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty(PREFIX + "test.(class)", TestBean.class.getName());
p.setProperty(PREFIX + "test.name", "Tony");
p.setProperty(PREFIX + "test.age", "0x30");
int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, PREFIX);
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 testPrototype.
@Test
public void testPrototype() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.age", "35");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
TestBean kerry1 = (TestBean) lbf.getBean("kerry");
TestBean kerry2 = (TestBean) lbf.getBean("kerry");
assertTrue("Non null", kerry1 != null);
assertTrue("Singletons equal", kerry1 == kerry2);
lbf = new DefaultListableBeanFactory();
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.(scope)", "prototype");
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("Prototypes NOT equal", kerry1 != kerry2);
lbf = new DefaultListableBeanFactory();
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.(scope)", "singleton");
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 testFactoryBeanDidNotCreatePrototype.
@Test
public void testFactoryBeanDidNotCreatePrototype() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("x1.(class)", DummyFactory.class.getName());
// Reset static state
DummyFactory.reset();
p.setProperty("x1.singleton", "false");
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
assertEquals(TestBean.class, lbf.getType("x1"));
lbf.preInstantiateSingletons();
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
lbf.getBean("x1");
assertEquals(TestBean.class, lbf.getType("x1"));
assertTrue(lbf.containsBean("x1"));
assertTrue(lbf.containsBean("&x1"));
assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testHarmlessIgnorableRubbish.
@Test
public void testHarmlessIgnorableRubbish() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("foo", "bar");
p.setProperty("qwert", "er");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, "test");
assertTrue("No beans defined after harmless ignorable rubbish", lbf.getBeanDefinitionCount() == 0);
}
Aggregations