Search in sources :

Example 6 with NestedTestBean

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

the class AutowiredAnnotationBeanPostProcessorTests method testExtendedResourceInjectionWithAtRequired.

@Test
public void testExtendedResourceInjectionWithAtRequired() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerResolvableDependency(BeanFactory.class, bf);
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
    RootBeanDefinition bd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.class);
    bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", bd);
    TestBean tb = new TestBean();
    bf.registerSingleton("testBean", tb);
    NestedTestBean ntb = new NestedTestBean();
    bf.registerSingleton("nestedTestBean", ntb);
    TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
    assertSame(tb, bean.getTestBean());
    assertSame(tb, bean.getTestBean2());
    assertSame(tb, bean.getTestBean3());
    assertSame(tb, bean.getTestBean4());
    assertSame(ntb, bean.getNestedTestBean());
    assertSame(bf, bean.getBeanFactory());
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 7 with NestedTestBean

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

the class DefaultListableBeanFactoryTests method testBeanDefinitionRemoval.

@Test
public void testBeanDefinitionRemoval() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.setAllowBeanDefinitionOverriding(false);
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
    lbf.registerAlias("test", "test2");
    lbf.preInstantiateSingletons();
    lbf.removeBeanDefinition("test");
    lbf.removeAlias("test2");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
    lbf.registerAlias("test", "test2");
    assertTrue(lbf.getBean("test") instanceof NestedTestBean);
    assertTrue(lbf.getBean("test2") instanceof NestedTestBean);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 ITestBean (org.springframework.tests.sample.beans.ITestBean)7 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)7 TestBean (org.springframework.tests.sample.beans.TestBean)7 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)4 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)3