use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithMultipleOrderedCandidates.
@Test
public void testConstructorResourceInjectionWithMultipleOrderedCandidates() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
bf.registerSingleton("nestedTestBean1", ntb1);
FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
bf.registerSingleton("nestedTestBean2", ntb2);
ConstructorsResourceInjectionBean bean = (ConstructorsResourceInjectionBean) bf.getBean("annotatedBean");
assertNull(bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertEquals(2, bean.getNestedTestBeans().length);
assertSame(ntb2, bean.getNestedTestBeans()[0]);
assertSame(ntb1, bean.getNestedTestBeans()[1]);
bf.destroySingletons();
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyPlaceholderConfigurerWithSystemPropertyFallback.
@Test
public void testPropertyPlaceholderConfigurerWithSystemPropertyFallback() {
factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).addPropertyValue("country", "${os.name}").getBeanDefinition());
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals(System.getProperty("os.name"), tb.getCountry());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyPlaceholderConfigurerWithSystemPropertyNotUsed.
@Test
public void testPropertyPlaceholderConfigurerWithSystemPropertyNotUsed() {
factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).addPropertyValue("country", "${os.name}").getBeanDefinition());
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.setProperty("os.name", "myos");
ppc.setProperties(props);
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myos", tb.getCountry());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyPlaceholderConfigurerWithOverridingSystemProperty.
@Test
public void testPropertyPlaceholderConfigurerWithOverridingSystemProperty() {
factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).addPropertyValue("country", "${os.name}").getBeanDefinition());
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.put("os.name", "myos");
ppc.setProperties(props);
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals(System.getProperty("os.name"), tb.getCountry());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class MailSession method testFactoryMethodsSingletonOnTargetClass.
@Test
public void testFactoryMethodsSingletonOnTargetClass() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass()));
TestBean tb = (TestBean) xbf.getBean("defaultTestBean");
assertEquals("defaultInstance", tb.getName());
assertEquals(1, tb.getAge());
FactoryMethods fm = (FactoryMethods) xbf.getBean("default");
assertEquals(0, fm.getNum());
assertEquals("default", fm.getName());
assertEquals("defaultInstance", fm.getTestBean().getName());
assertEquals("setterString", fm.getStringValue());
fm = (FactoryMethods) xbf.getBean("testBeanOnly");
assertEquals(0, fm.getNum());
assertEquals("default", fm.getName());
// This comes from the test bean
assertEquals("Juergen", fm.getTestBean().getName());
fm = (FactoryMethods) xbf.getBean("full");
assertEquals(27, fm.getNum());
assertEquals("gotcha", fm.getName());
assertEquals("Juergen", fm.getTestBean().getName());
FactoryMethods fm2 = (FactoryMethods) xbf.getBean("full");
assertSame(fm, fm2);
xbf.destroySingletons();
assertTrue(tb.wasDestroyed());
}
Aggregations