Search in sources :

Example 16 with NestedTestBean

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

the class InjectAnnotationBeanPostProcessorTests 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 17 with NestedTestBean

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

the class InjectAnnotationBeanPostProcessorTests 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 : 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 18 with NestedTestBean

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

the class DelegatingIntroductionInterceptorTests method testDelegateReturnsThisIsMassagedToReturnProxy.

@Test
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
    NestedTestBean target = new NestedTestBean();
    String company = "Interface21";
    target.setCompany(company);
    TestBean delegate = new TestBean() {

        @Override
        public ITestBean getSpouse() {
            return this;
        }
    };
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new DelegatingIntroductionInterceptor(delegate));
    INestedTestBean proxy = (INestedTestBean) pf.getProxy();
    assertThat(proxy.getCompany()).isEqualTo(company);
    ITestBean introduction = (ITestBean) proxy;
    assertThat(introduction.getSpouse()).as("Introduced method returning delegate returns proxy").isSameAs(introduction);
    assertThat(AopUtils.isAopProxy(introduction.getSpouse())).as("Introduced method returning delegate returns proxy").isTrue();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) INestedTestBean(org.springframework.beans.testfixture.beans.INestedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) INestedTestBean(org.springframework.beans.testfixture.beans.INestedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) INestedTestBean(org.springframework.beans.testfixture.beans.INestedTestBean) Test(org.junit.jupiter.api.Test)

Example 19 with NestedTestBean

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

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

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

the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithNullFromFactoryMethod.

@Test
public void testConstructorResourceInjectionWithNullFromFactoryMethod() {
    RootBeanDefinition bd = new RootBeanDefinition(ConstructorResourceInjectionBean.class);
    bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", bd);
    RootBeanDefinition tb = new RootBeanDefinition(NullFactoryMethods.class);
    tb.setFactoryMethodName("createTestBean");
    bf.registerBeanDefinition("testBean", tb);
    RootBeanDefinition ntb = new RootBeanDefinition(NullFactoryMethods.class);
    ntb.setFactoryMethodName("createNestedTestBean");
    bf.registerBeanDefinition("nestedTestBean", ntb);
    bf.registerSingleton("nestedTestBean2", new NestedTestBean());
    ConstructorResourceInjectionBean bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isNull();
    assertThat(bean.getTestBean2()).isNull();
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isNull();
    assertThat(bean.getNestedTestBean()).isNull();
    assertThat(bean.getBeanFactory()).isSameAs(bf);
    bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean.getTestBean()).isNull();
    assertThat(bean.getTestBean2()).isNull();
    assertThat(bean.getTestBean3()).isNull();
    assertThat(bean.getTestBean4()).isNull();
    assertThat(bean.getNestedTestBean()).isNull();
    assertThat(bean.getBeanFactory()).isSameAs(bf);
}
Also used : 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