Search in sources :

Example 1 with NestedTestBean

use of cn.taketoday.beans.testfixture.beans.NestedTestBean in project today-infrastructure by TAKETODAY.

the class StandardDependenciesBeanPostProcessorTests method testOptionalResourceInjectionWithSingletonRemoval.

@Test
public void testOptionalResourceInjectionWithSingletonRemoval() {
    RootBeanDefinition rbd = new RootBeanDefinition(OptionalResourceInjectionBean.class);
    rbd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", rbd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    IndexedTestBean itb = new IndexedTestBean();
    bf.registerSingleton("indexedTestBean", itb);
    NestedTestBean ntb1 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean1", ntb1);
    NestedTestBean ntb2 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean2", ntb2);
    OptionalResourceInjectionBean bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
    bf.destroySingleton("testBean");
    bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isNull();
    assertThat(bean.getTestBean2()).isNull();
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isNull();
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
    bf.registerSingleton("testBean", tb);
    bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with NestedTestBean

use of cn.taketoday.beans.testfixture.beans.NestedTestBean in project today-infrastructure by TAKETODAY.

the class AutowiredAnnotationBeanPostProcessorTests method testExtendedResourceInjectionWithOverriding.

@Test
public void testExtendedResourceInjectionWithOverriding() {
    RootBeanDefinition annotatedBd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.class);
    TestBean tb2 = new TestBean();
    annotatedBd.getPropertyValues().add("testBean2", tb2);
    bf.registerBeanDefinition("annotatedBean", annotatedBd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb = new NestedTestBean();
    bf.registerSingleton("nestedTestBean", ntb);
    TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb2);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBean()).isSameAs(ntb);
    assertThat(bean.getBeanFactory()).isSameAs(bf);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with NestedTestBean

use of cn.taketoday.beans.testfixture.beans.NestedTestBean in project today-infrastructure by TAKETODAY.

the class AutowiredAnnotationBeanPostProcessorTests method testOptionalResourceInjectionWithSingletonRemoval.

@Test
public void testOptionalResourceInjectionWithSingletonRemoval() {
    RootBeanDefinition rbd = new RootBeanDefinition(OptionalResourceInjectionBean.class);
    rbd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", rbd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    IndexedTestBean itb = new IndexedTestBean();
    bf.registerSingleton("indexedTestBean", itb);
    NestedTestBean ntb1 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean1", ntb1);
    NestedTestBean ntb2 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean2", ntb2);
    OptionalResourceInjectionBean bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
    bf.destroySingleton("testBean");
    bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isNull();
    assertThat(bean.getTestBean2()).isNull();
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isNull();
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
    bf.registerSingleton("testBean", tb);
    bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getIndexedTestBean()).isSameAs(itb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb2);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with NestedTestBean

use of cn.taketoday.beans.testfixture.beans.NestedTestBean in project today-infrastructure by TAKETODAY.

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithMultipleCandidatesAsCollection.

@Test
public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() {
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsCollectionResourceInjectionBean.class));
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb1 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean1", ntb1);
    NestedTestBean ntb2 = new NestedTestBean();
    bf.registerSingleton("nestedTestBean2", ntb2);
    ConstructorsCollectionResourceInjectionBean bean = (ConstructorsCollectionResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBeans().size()).isEqualTo(2);
    assertThat(bean.getNestedTestBeans().get(0)).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans().get(1)).isSameAs(ntb2);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with NestedTestBean

use of cn.taketoday.beans.testfixture.beans.NestedTestBean in project today-infrastructure by TAKETODAY.

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithSingletonRemoval.

@Test
public void testConstructorResourceInjectionWithSingletonRemoval() {
    RootBeanDefinition bd = new RootBeanDefinition(ConstructorResourceInjectionBean.class);
    bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", bd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb = new NestedTestBean();
    bf.registerSingleton("nestedTestBean", ntb);
    ConstructorResourceInjectionBean bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBean()).isSameAs(ntb);
    assertThat(bean.getBeanFactory()).isSameAs(bf);
    bf.destroySingleton("nestedTestBean");
    bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBean()).isNull();
    assertThat(bean.getBeanFactory()).isSameAs(bf);
    bf.registerSingleton("nestedTestBean", ntb);
    bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isSameAs(tb);
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBean()).isSameAs(ntb);
    assertThat(bean.getBeanFactory()).isSameAs(bf);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)92 Test (org.junit.jupiter.api.Test)92 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)90 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)86 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)86 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)76 INestedTestBean (cn.taketoday.beans.testfixture.beans.INestedTestBean)12 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)10 PropertyPlaceholderConfigurer (cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer)6 Properties (java.util.Properties)6 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)4 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)2 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)2 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)2