Search in sources :

Example 1 with IndexedTestBean

use of cn.taketoday.beans.testfixture.beans.IndexedTestBean 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 IndexedTestBean

use of cn.taketoday.beans.testfixture.beans.IndexedTestBean 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 3 with IndexedTestBean

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

the class StandardDependenciesBeanPostProcessorTests method testAnnotationOrderedResourceInjection.

@Test
public void testAnnotationOrderedResourceInjection() {
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalResourceInjectionBean.class));
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    IndexedTestBean itb = new IndexedTestBean();
    bf.registerSingleton("indexedTestBean", itb);
    FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
    bf.registerSingleton("nestedTestBean1", ntb1);
    FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
    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(ntb2);
    assertThat(bean.getNestedTestBeans()[1]).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField.length).isEqualTo(2);
    assertThat(bean.nestedTestBeansField[0]).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField[1]).isSameAs(ntb1);
}
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) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with IndexedTestBean

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

the class StandardDependenciesBeanPostProcessorTests method testOptionalCollectionResourceInjectionWithSingleElement.

@Test
public void testOptionalCollectionResourceInjectionWithSingleElement() {
    RootBeanDefinition rbd = new RootBeanDefinition(OptionalCollectionResourceInjectionBean.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);
    // Two calls to verify that caching doesn't break re-creation.
    OptionalCollectionResourceInjectionBean bean = (OptionalCollectionResourceInjectionBean) bf.getBean("annotatedBean");
    bean = (OptionalCollectionResourceInjectionBean) 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().size()).isEqualTo(1);
    assertThat(bean.getNestedTestBeans().get(0)).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansSetter.size()).isEqualTo(1);
    assertThat(bean.nestedTestBeansSetter.get(0)).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField.size()).isEqualTo(1);
    assertThat(bean.nestedTestBeansField.get(0)).isSameAs(ntb1);
}
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 5 with IndexedTestBean

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

the class StandardDependenciesBeanPostProcessorTests method testOptionalCollectionResourceInjection.

@Test
public void testOptionalCollectionResourceInjection() {
    RootBeanDefinition rbd = new RootBeanDefinition(OptionalCollectionResourceInjectionBean.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);
    // Two calls to verify that caching doesn't break re-creation.
    OptionalCollectionResourceInjectionBean bean = (OptionalCollectionResourceInjectionBean) bf.getBean("annotatedBean");
    bean = (OptionalCollectionResourceInjectionBean) 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().size()).isEqualTo(2);
    assertThat(bean.getNestedTestBeans().get(0)).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans().get(1)).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansSetter.size()).isEqualTo(2);
    assertThat(bean.nestedTestBeansSetter.get(0)).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansSetter.get(1)).isSameAs(ntb2);
    assertThat(bean.nestedTestBeansField.size()).isEqualTo(2);
    assertThat(bean.nestedTestBeansField.get(0)).isSameAs(ntb1);
    assertThat(bean.nestedTestBeansField.get(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)

Aggregations

IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)155 Test (org.junit.jupiter.api.Test)153 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)102 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)84 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)57 PropertyEditorSupport (java.beans.PropertyEditorSupport)51 PropertyValues (cn.taketoday.beans.PropertyValues)44 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)36 DerivedTestBean (cn.taketoday.beans.testfixture.beans.DerivedTestBean)30 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)24 BeanDefinitionBuilder.genericBeanDefinition (cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition)21 ChildBeanDefinition (cn.taketoday.beans.factory.support.ChildBeanDefinition)21 BeanWrapper (cn.taketoday.beans.BeanWrapper)20 BeanWrapperImpl (cn.taketoday.beans.BeanWrapperImpl)20 BooleanTestBean (cn.taketoday.beans.BooleanTestBean)20 NumberTestBean (cn.taketoday.beans.NumberTestBean)20 ArrayList (java.util.ArrayList)14 DataBinder (cn.taketoday.validation.DataBinder)12 HashSet (java.util.HashSet)12 Properties (java.util.Properties)12