use of cn.taketoday.beans.testfixture.beans.factory.DummyFactory in project today-infrastructure by TAKETODAY.
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 cn.taketoday.beans.testfixture.beans.factory.DummyFactory in project today-infrastructure by TAKETODAY.
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 cn.taketoday.beans.testfixture.beans.factory.DummyFactory in project today-infrastructure by TAKETODAY.
the class BeanFactoryUtilsTests method testFindsBeansOfTypeWithStaticFactory.
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
StandardBeanFactory lbf = new StandardBeanFactory();
TestBean t1 = new TestBean();
TestBean t2 = new TestBean();
DummyFactory t3 = new DummyFactory();
DummyFactory t4 = new DummyFactory();
t4.setSingleton(false);
lbf.registerSingleton("t1", t1);
lbf.registerSingleton("t2", t2);
lbf.registerSingleton("t3", t3);
lbf.registerSingleton("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 cn.taketoday.beans.testfixture.beans.factory.DummyFactory in project today-infrastructure by TAKETODAY.
the class BeanFactoryUtilsTests method isSingletonAndIsPrototypeWithStaticFactory.
@Test
public void isSingletonAndIsPrototypeWithStaticFactory() {
StandardBeanFactory lbf = new StandardBeanFactory();
TestBean bean = new TestBean();
DummyFactory fb1 = new DummyFactory();
DummyFactory fb2 = new DummyFactory();
fb2.setSingleton(false);
TestBeanSmartFactoryBean sfb1 = new TestBeanSmartFactoryBean(true, true);
TestBeanSmartFactoryBean sfb2 = new TestBeanSmartFactoryBean(true, false);
TestBeanSmartFactoryBean sfb3 = new TestBeanSmartFactoryBean(false, true);
TestBeanSmartFactoryBean sfb4 = new TestBeanSmartFactoryBean(false, false);
lbf.registerBeanDefinition("bean", new RootBeanDefinition(TestBean.class, () -> bean));
lbf.registerBeanDefinition("fb1", new RootBeanDefinition(DummyFactory.class, () -> fb1));
lbf.registerBeanDefinition("fb2", new RootBeanDefinition(DummyFactory.class, () -> fb2));
lbf.registerBeanDefinition("sfb1", new RootBeanDefinition(TestBeanSmartFactoryBean.class, () -> sfb1));
lbf.registerBeanDefinition("sfb2", new RootBeanDefinition(TestBeanSmartFactoryBean.class, () -> sfb2));
lbf.registerBeanDefinition("sfb3", new RootBeanDefinition(TestBeanSmartFactoryBean.class, () -> sfb3));
lbf.registerBeanDefinition("sfb4", new RootBeanDefinition(TestBeanSmartFactoryBean.class, () -> sfb4));
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
assertThat(beans.get("bean")).isSameAs(bean);
assertThat(beans.get("fb1")).isSameAs(fb1.getObject());
assertThat(beans.get("fb2")).isInstanceOf(TestBean.class);
assertThat(beans.get("sfb1")).isInstanceOf(TestBean.class);
assertThat(beans.get("sfb2")).isInstanceOf(TestBean.class);
assertThat(beans.get("sfb3")).isInstanceOf(TestBean.class);
assertThat(beans.get("sfb4")).isInstanceOf(TestBean.class);
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(7);
assertThat(lbf.getBean("bean")).isInstanceOf(TestBean.class);
assertThat(lbf.getBean("&fb1")).isInstanceOf(FactoryBean.class);
assertThat(lbf.getBean("&fb2")).isInstanceOf(FactoryBean.class);
assertThat(lbf.getBean("&sfb1")).isInstanceOf(SmartFactoryBean.class);
assertThat(lbf.getBean("&sfb2")).isInstanceOf(SmartFactoryBean.class);
assertThat(lbf.getBean("&sfb3")).isInstanceOf(SmartFactoryBean.class);
assertThat(lbf.getBean("&sfb4")).isInstanceOf(SmartFactoryBean.class);
assertThat(lbf.isSingleton("bean")).isTrue();
assertThat(lbf.isSingleton("fb1")).isTrue();
assertThat(lbf.isSingleton("fb2")).isFalse();
assertThat(lbf.isSingleton("sfb1")).isTrue();
assertThat(lbf.isSingleton("sfb2")).isTrue();
assertThat(lbf.isSingleton("sfb3")).isFalse();
assertThat(lbf.isSingleton("sfb4")).isFalse();
assertThat(lbf.isSingleton("&fb1")).isTrue();
assertThat(lbf.isSingleton("&fb2")).isTrue();
assertThat(lbf.isSingleton("&sfb1")).isTrue();
assertThat(lbf.isSingleton("&sfb2")).isTrue();
assertThat(lbf.isSingleton("&sfb3")).isTrue();
assertThat(lbf.isSingleton("&sfb4")).isTrue();
assertThat(lbf.isPrototype("bean")).isFalse();
assertThat(lbf.isPrototype("fb1")).isFalse();
assertThat(lbf.isPrototype("fb2")).isTrue();
assertThat(lbf.isPrototype("sfb1")).isTrue();
assertThat(lbf.isPrototype("sfb2")).isFalse();
assertThat(lbf.isPrototype("sfb3")).isTrue();
assertThat(lbf.isPrototype("sfb4")).isTrue();
assertThat(lbf.isPrototype("&fb1")).isFalse();
assertThat(lbf.isPrototype("&fb2")).isFalse();
assertThat(lbf.isPrototype("&sfb1")).isFalse();
assertThat(lbf.isPrototype("&sfb2")).isFalse();
assertThat(lbf.isPrototype("&sfb3")).isFalse();
assertThat(lbf.isPrototype("&sfb4")).isFalse();
}
use of cn.taketoday.beans.testfixture.beans.factory.DummyFactory in project today-infrastructure by TAKETODAY.
the class XmlBeanFactoryTests method factoryReferenceCircle.
@Test
void factoryReferenceCircle() {
StandardBeanFactory xbf = new StandardBeanFactory();
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