use of org.springframework.beans.testfixture.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class XmlListableBeanFactoryTests method beanPostProcessor.
@Test
public void beanPostProcessor() {
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
TestBean factoryCreated = (TestBean) getBeanFactory().getBean("singletonFactory");
assertThat(kerry.isPostProcessed()).isTrue();
assertThat(kathy.isPostProcessed()).isTrue();
assertThat(factory.isPostProcessed()).isTrue();
assertThat(factoryCreated.isPostProcessed()).isTrue();
}
use of org.springframework.beans.testfixture.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class XmlListableBeanFactoryTests method factoryReferences.
@Test
public void factoryReferences() {
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
assertThat(ref.getTestBean1() == ref.getTestBean2()).isTrue();
assertThat(ref.getDummyFactory() == factory).isTrue();
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("factoryReferencerWithConstructor");
assertThat(ref2.getTestBean1() == ref2.getTestBean2()).isTrue();
assertThat(ref2.getDummyFactory() == factory).isTrue();
}
use of org.springframework.beans.testfixture.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class BeanFactoryUtilsTests method testFindsBeansOfTypeWithStaticFactory.
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
TestBean t1 = new TestBean();
TestBean t2 = new TestBean();
DummyFactory t3 = new DummyFactory();
DummyFactory t4 = new DummyFactory();
t4.setSingleton(false);
lbf.addBean("t1", t1);
lbf.addBean("t2", t2);
lbf.addBean("t3", t3);
lbf.addBean("t4", t4);
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean;
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
}
use of org.springframework.beans.testfixture.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class BeanFactoryUtilsTests method testFindsBeansOfTypeWithDefaultFactory.
@Test
public void testFindsBeansOfTypeWithDefaultFactory() {
Object test3 = this.listableBeanFactory.getBean("test3");
Object test = this.listableBeanFactory.getBean("test");
TestBean t1 = new TestBean();
TestBean t2 = new TestBean();
DummyFactory t3 = new DummyFactory();
DummyFactory t4 = new DummyFactory();
t4.setSingleton(false);
this.listableBeanFactory.registerSingleton("t1", t1);
this.listableBeanFactory.registerSingleton("t2", t2);
this.listableBeanFactory.registerSingleton("t3", t3);
this.listableBeanFactory.registerSingleton("t4", t4);
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, false);
assertThat(beans.size()).isEqualTo(6);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition2 = beans.get("t4") instanceof TestBean;
assertThat(condition2).isTrue();
// t3 and t4 are found here as of Spring 2.0, since they are pre-registered
// singleton instances, while testFactory1 and testFactory are *not* found
// because they are FactoryBean definitions that haven't been initialized yet.
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, true);
Object testFactory1 = this.listableBeanFactory.getBean("testFactory1");
assertThat(beans.size()).isEqualTo(5);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, true);
assertThat(beans.size()).isEqualTo(8);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
boolean condition1 = beans.get("testFactory2") instanceof TestBean;
assertThat(condition1).isTrue();
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean;
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, FactoryBean.class, true, true);
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
}
use of org.springframework.beans.testfixture.beans.factory.DummyFactory in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method factoryReferenceCircle.
@Test
void factoryReferenceCircle() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(FACTORY_CIRCLE_CONTEXT);
TestBean tb = (TestBean) xbf.getBean("singletonFactory");
DummyFactory db = (DummyFactory) xbf.getBean("&singletonFactory");
assertThat(tb == db.getOtherTestBean()).isTrue();
}
Aggregations