Search in sources :

Example 1 with NestedTestBean

use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithCollectionAndNullFromFactoryBean.

@Test
public void testConstructorResourceInjectionWithCollectionAndNullFromFactoryBean() {
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsCollectionResourceInjectionBean.class));
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    bf.registerBeanDefinition("nestedTestBean1", new RootBeanDefinition(NullNestedTestBeanFactoryBean.class));
    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(1);
    assertThat(bean.getNestedTestBeans().get(0)).isSameAs(ntb2);
    Map<String, NestedTestBean> map = bf.getBeansOfType(NestedTestBean.class);
    assertThat(map.get("nestedTestBean1")).isNull();
    assertThat(map.get("nestedTestBean2")).isSameAs(ntb2);
}
Also used : NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with NestedTestBean

use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.

the class AutowiredAnnotationBeanPostProcessorTests 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(org.springframework.beans.testfixture.beans.IndexedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with NestedTestBean

use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.

the class AutowiredAnnotationBeanPostProcessorTests method testExtendedResourceInjectionWithSkippedOverriddenMethods.

@Test
public void testExtendedResourceInjectionWithSkippedOverriddenMethods() {
    RootBeanDefinition annotatedBd = new RootBeanDefinition(OverriddenExtendedResourceInjectionBean.class);
    bf.registerBeanDefinition("annotatedBean", annotatedBd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb = new NestedTestBean();
    bf.registerSingleton("nestedTestBean", ntb);
    OverriddenExtendedResourceInjectionBean bean = (OverriddenExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isSameAs(tb);
    assertThat(bean.getTestBean2()).isNull();
    assertThat(bean.getTestBean3()).isSameAs(tb);
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBean()).isSameAs(ntb);
    assertThat(bean.getBeanFactory()).isNull();
    assertThat(bean.baseInjected).isTrue();
    assertThat(bean.subInjected).isTrue();
}
Also used : NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with NestedTestBean

use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjection.

@Test
public void testConstructorResourceInjection() {
    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);
    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 : NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with NestedTestBean

use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithBeanDefinitionRemoval.

@Test
public void testConstructorResourceInjectionWithBeanDefinitionRemoval() {
    RootBeanDefinition bd = new RootBeanDefinition(ConstructorResourceInjectionBean.class);
    bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", bd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    bf.registerBeanDefinition("nestedTestBean", new RootBeanDefinition(NestedTestBean.class));
    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(bf.getBean("nestedTestBean"));
    assertThat(bean.getBeanFactory()).isSameAs(bf);
    bf.removeBeanDefinition("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.registerBeanDefinition("nestedTestBean", new RootBeanDefinition(NestedTestBean.class));
    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(bf.getBean("nestedTestBean"));
    assertThat(bean.getBeanFactory()).isSameAs(bf);
}
Also used : NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)29 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)29 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)27 TestBean (org.springframework.beans.testfixture.beans.TestBean)27 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)26 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)22 INestedTestBean (org.springframework.beans.testfixture.beans.INestedTestBean)6 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 Properties (java.util.Properties)3 PageContext (jakarta.servlet.jsp.PageContext)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 BindStatus (org.springframework.web.servlet.support.BindStatus)1