use of org.springframework.tests.sample.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class XmlListableBeanFactoryTests method setUp.
@Before
public void setUp() {
parent = new DefaultListableBeanFactory();
Map m = new HashMap();
m.put("name", "Albert");
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("father", bd1);
m = new HashMap();
m.put("name", "Roderick");
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("rod", bd2);
this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(new ClassPathResource("test.xml", getClass()));
this.factory.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof TestBean) {
((TestBean) bean).setPostProcessed(true);
}
if (bean instanceof DummyFactory) {
((DummyFactory) bean).setPostProcessed(true);
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}
});
this.factory.addBeanPostProcessor(new LifecycleBean.PostProcessor());
this.factory.addBeanPostProcessor(new ProtectedLifecycleBean.PostProcessor());
//this.factory.preInstantiateSingletons();
}
use of org.springframework.tests.sample.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class AbstractBeanFactoryTests method factorySingleton.
@Test
public void factorySingleton() throws Exception {
assertTrue(getBeanFactory().isSingleton("&singletonFactory"));
assertTrue(getBeanFactory().isSingleton("singletonFactory"));
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
assertTrue("Singleton from factory has correct name, not " + tb.getName(), tb.getName().equals(DummyFactory.SINGLETON_NAME));
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
TestBean tb2 = (TestBean) getBeanFactory().getBean("singletonFactory");
assertTrue("Singleton references ==", tb == tb2);
assertTrue("FactoryBean is BeanFactoryAware", factory.getBeanFactory() != null);
}
use of org.springframework.tests.sample.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class AbstractBeanFactoryTests method factoryIsInitialized.
/**
* Check that afterPropertiesSet gets called on factory
* @throws Exception
*/
@Test
public void factoryIsInitialized() throws Exception {
TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
assertNotNull(tb);
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
assertTrue("Factory was initialized because it implemented InitializingBean", factory.wasInitialized());
}
use of org.springframework.tests.sample.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testFactoryReferenceCircle.
@Test
public void testFactoryReferenceCircle() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(FACTORY_CIRCLE_CONTEXT);
TestBean tb = (TestBean) xbf.getBean("singletonFactory");
DummyFactory db = (DummyFactory) xbf.getBean("&singletonFactory");
assertTrue(tb == db.getOtherTestBean());
}
Aggregations