use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class RequiredAnnotationBeanPostProcessorTests method testWithFactoryBean.
@Test
public void testWithFactoryBean() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
RootBeanDefinition beanDef = new RootBeanDefinition(RequiredTestBean.class);
beanDef.setFactoryBeanName("testBeanFactory");
beanDef.setFactoryMethodName("create");
factory.registerBeanDefinition("testBean", beanDef);
factory.registerBeanDefinition("testBeanFactory", new RootBeanDefinition(RequiredTestBeanFactory.class));
RequiredAnnotationBeanPostProcessor bpp = new RequiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(factory);
factory.addBeanPostProcessor(bpp);
factory.preInstantiateSingletons();
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class RequiredAnnotationBeanPostProcessorTests method testWithCustomAnnotation.
@Test
public void testWithCustomAnnotation() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder.genericBeanDefinition(RequiredTestBean.class).getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
RequiredAnnotationBeanPostProcessor rabpp = new RequiredAnnotationBeanPostProcessor();
rabpp.setRequiredAnnotationType(MyRequired.class);
factory.addBeanPostProcessor(rabpp);
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Property"));
assertTrue(message.contains("name"));
assertTrue(message.contains("testBean"));
}
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class RequiredAnnotationBeanPostProcessorTests method testWithAllRequiredPropertiesSpecified.
@Test
public void testWithAllRequiredPropertiesSpecified() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder.genericBeanDefinition(RequiredTestBean.class).addPropertyValue("age", "24").addPropertyValue("favouriteColour", "Blue").addPropertyValue("jobTitle", "Grand Poobah").getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
RequiredTestBean bean = (RequiredTestBean) factory.getBean("testBean");
assertEquals(24, bean.getAge());
assertEquals("Blue", bean.getFavouriteColour());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class RequiredAnnotationBeanPostProcessorTests method testWithStaticFactoryMethodAndRequiredPropertiesSpecified.
@Test
public void testWithStaticFactoryMethodAndRequiredPropertiesSpecified() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder.genericBeanDefinition(RequiredTestBean.class).setFactoryMethod("create").addPropertyValue("age", "24").addPropertyValue("favouriteColour", "Blue").addPropertyValue("jobTitle", "Grand Poobah").getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
RequiredTestBean bean = (RequiredTestBean) factory.getBean("testBean");
assertEquals(24, bean.getAge());
assertEquals("Blue", bean.getFavouriteColour());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DeprecatedBeanWarnerTests method postProcess.
@Test
@SuppressWarnings("deprecation")
public void postProcess() {
beanFactory = new DefaultListableBeanFactory();
BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class);
String beanName = "deprecated";
beanFactory.registerBeanDefinition(beanName, def);
warner = new MyDeprecatedBeanWarner();
warner.postProcessBeanFactory(beanFactory);
assertEquals(beanName, this.beanName);
assertEquals(def, this.beanDefinition);
}
Aggregations