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");
}
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();
}
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");
}
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();
}
Aggregations