use of cn.taketoday.jndi.support.SimpleJndiBeanFactory in project today-infrastructure by TAKETODAY.
the class CommonAnnotationBeanPostProcessorTests method testResourceInjectionFromJndi.
@Test
public void testResourceInjectionFromJndi() {
StandardBeanFactory bf = new StandardBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
TestBean tb = new TestBean();
jndiTemplate.addObject("java:comp/env/testBean", tb);
TestBean tb2 = new TestBean();
jndiTemplate.addObject("java:comp/env/testBean2", tb2);
resourceFactory.setJndiTemplate(jndiTemplate);
bpp.setResourceFactory(resourceFactory);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
use of cn.taketoday.jndi.support.SimpleJndiBeanFactory in project today-framework by TAKETODAY.
the class CommonAnnotationBeanPostProcessorTests method testResourceInjectionFromJndi.
@Test
public void testResourceInjectionFromJndi() {
StandardBeanFactory bf = new StandardBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
TestBean tb = new TestBean();
jndiTemplate.addObject("java:comp/env/testBean", tb);
TestBean tb2 = new TestBean();
jndiTemplate.addObject("java:comp/env/testBean2", tb2);
resourceFactory.setJndiTemplate(jndiTemplate);
bpp.setResourceFactory(resourceFactory);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
Aggregations