Search in sources :

Example 1 with INestedTestBean

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

the class CommonAnnotationBeanPostProcessorTests method testResourceInjectionWithResolvableDependencyType.

@Test
public void testResourceInjectionWithResolvableDependencyType() {
    StandardBeanFactory bf = new StandardBeanFactory();
    CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    BeanDefinition abd = new RootBeanDefinition(ExtendedResourceInjectionBean.class);
    abd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", abd);
    BeanDefinition tbd = new RootBeanDefinition(TestBean.class);
    tbd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("testBean4", tbd);
    bf.registerDependency(BeanFactory.class, bf);
    bf.registerDependency(INestedTestBean.class, (Supplier<NestedTestBean>) NestedTestBean::new);
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Properties props = new Properties();
    props.setProperty("tb", "testBean4");
    ppc.setProperties(props);
    ppc.postProcessBeanFactory(bf);
    ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    INestedTestBean tb = bean.getTestBean6();
    assertThat(tb).isNotNull();
    ExtendedResourceInjectionBean anotherBean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean).isNotSameAs(anotherBean);
    assertThat(tb).isNotSameAs(anotherBean.getTestBean6());
    String[] depBeans = bf.getDependenciesForBean("annotatedBean");
    assertThat(depBeans.length).isEqualTo(1);
    assertThat(depBeans[0]).isEqualTo("testBean4");
}
Also used : PropertyPlaceholderConfigurer(cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 2 with INestedTestBean

use of cn.taketoday.beans.testfixture.beans.INestedTestBean in project today-framework by TAKETODAY.

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);
    Assertions.assertThat(AopUtils.isAopProxy(introduction.getSpouse())).as("Introduced method returning delegate returns proxy").isTrue();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) Test(org.junit.jupiter.api.Test)

Example 3 with INestedTestBean

use of cn.taketoday.beans.testfixture.beans.INestedTestBean in project today-framework by TAKETODAY.

the class CommonAnnotationBeanPostProcessorTests method testResourceInjectionWithResolvableDependencyType.

@Test
public void testResourceInjectionWithResolvableDependencyType() {
    StandardBeanFactory bf = new StandardBeanFactory();
    CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    BeanDefinition abd = new RootBeanDefinition(ExtendedResourceInjectionBean.class);
    abd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", abd);
    BeanDefinition tbd = new RootBeanDefinition(TestBean.class);
    tbd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("testBean4", tbd);
    bf.registerDependency(BeanFactory.class, bf);
    bf.registerDependency(INestedTestBean.class, (Supplier<NestedTestBean>) NestedTestBean::new);
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Properties props = new Properties();
    props.setProperty("tb", "testBean4");
    ppc.setProperties(props);
    ppc.postProcessBeanFactory(bf);
    ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    INestedTestBean tb = bean.getTestBean6();
    assertThat(tb).isNotNull();
    ExtendedResourceInjectionBean anotherBean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    assertThat(bean).isNotSameAs(anotherBean);
    assertThat(tb).isNotSameAs(anotherBean.getTestBean6());
    String[] depBeans = bf.getDependenciesForBean("annotatedBean");
    assertThat(depBeans.length).isEqualTo(1);
    assertThat(depBeans[0]).isEqualTo("testBean4");
}
Also used : PropertyPlaceholderConfigurer(cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 4 with INestedTestBean

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

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);
    Assertions.assertThat(AopUtils.isAopProxy(introduction.getSpouse())).as("Introduced method returning delegate returns proxy").isTrue();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) Test(org.junit.jupiter.api.Test)

Aggregations

INestedTestBean (cn.taketoday.beans.testfixture.beans.INestedTestBean)4 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)4 Test (org.junit.jupiter.api.Test)4 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)2 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 PropertyPlaceholderConfigurer (cn.taketoday.beans.factory.config.PropertyPlaceholderConfigurer)2 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)2 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)2 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 Properties (java.util.Properties)2