Search in sources :

Example 1 with SimpleJndiBeanFactory

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();
}
Also used : NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ExpectedLookupTemplate(cn.taketoday.testfixture.jndi.ExpectedLookupTemplate) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) SimpleJndiBeanFactory(cn.taketoday.jndi.support.SimpleJndiBeanFactory) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleJndiBeanFactory

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();
}
Also used : NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ExpectedLookupTemplate(cn.taketoday.testfixture.jndi.ExpectedLookupTemplate) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) SimpleJndiBeanFactory(cn.taketoday.jndi.support.SimpleJndiBeanFactory) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) Test(org.junit.jupiter.api.Test)

Aggregations

RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)2 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 INestedTestBean (cn.taketoday.beans.testfixture.beans.INestedTestBean)2 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)2 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)2 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 SimpleJndiBeanFactory (cn.taketoday.jndi.support.SimpleJndiBeanFactory)2 ExpectedLookupTemplate (cn.taketoday.testfixture.jndi.ExpectedLookupTemplate)2 Test (org.junit.jupiter.api.Test)2