Search in sources :

Example 21 with NestedTestBean

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

the class AutowiredAnnotationBeanPostProcessorTests method testExtendedResourceInjectionWithDefaultMethod.

@Test
public void testExtendedResourceInjectionWithDefaultMethod() {
    RootBeanDefinition annotatedBd = new RootBeanDefinition(DefaultMethodResourceInjectionBean.class);
    bf.registerBeanDefinition("annotatedBean", annotatedBd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb = new NestedTestBean();
    bf.registerSingleton("nestedTestBean", ntb);
    DefaultMethodResourceInjectionBean bean = (DefaultMethodResourceInjectionBean) 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 22 with NestedTestBean

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

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 : 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 23 with NestedTestBean

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

the class AutowiredAnnotationBeanPostProcessorTests method testExtendedResourceInjection.

@Test
public void testExtendedResourceInjection() {
    RootBeanDefinition bd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.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);
    TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) 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 = (TypedExtendedResourceInjectionBean) 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);
    String[] depBeans = bf.getDependenciesForBean("annotatedBean");
    assertThat(depBeans.length).isEqualTo(2);
    assertThat(depBeans[0]).isEqualTo("testBean");
    assertThat(depBeans[1]).isEqualTo("nestedTestBean");
}
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 24 with NestedTestBean

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

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithMultipleCandidates.

@Test
public void testConstructorResourceInjectionWithMultipleCandidates() {
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsResourceInjectionBean.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);
    ConstructorsResourceInjectionBean bean = (ConstructorsResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isSameAs(tb);
    assertThat(bean.getNestedTestBeans().length).isEqualTo(2);
    assertThat(bean.getNestedTestBeans()[0]).isSameAs(ntb1);
    assertThat(bean.getNestedTestBeans()[1]).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 25 with NestedTestBean

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

the class CommonAnnotationBeanPostProcessorTests method testResourceInjectionWithDefaultMethod.

@Test
public void testResourceInjectionWithDefaultMethod() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(DefaultMethodResourceInjectionBean.class));
    TestBean tb2 = new TestBean();
    bf.registerSingleton("testBean2", tb2);
    NestedTestBean tb7 = new NestedTestBean();
    bf.registerSingleton("testBean7", tb7);
    DefaultMethodResourceInjectionBean bean = (DefaultMethodResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean2()).isSameAs(tb2);
    assertThat(bean.counter).isSameAs(2);
    bf.destroySingletons();
    assertThat(bean.counter).isSameAs(3);
}
Also used : NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) INestedTestBean(org.springframework.beans.testfixture.beans.INestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) INestedTestBean(org.springframework.beans.testfixture.beans.INestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) 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