use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class AutowireWithExclusionTests method byTypeAutowireWithPrimaryOverridingParentFactory.
@Test
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
CountingFactory.reset();
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
propsDef.getPropertyValues().add("properties", "name=props3");
propsDef.setPrimary(true);
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class AutowireWithExclusionTests method byTypeAutowireWithPrimaryInParentAndChild.
@Test
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
CountingFactory.reset();
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
propsDef.getPropertyValues().add("properties", "name=props3");
propsDef.setPrimary(true);
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class AutowireWithExclusionTests method byTypeAutowireWithPrimaryInParentFactory.
@Test
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
CountingFactory.reset();
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
propsDef.getPropertyValues().add("properties", "name=props3");
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class AutowireWithExclusionTests method constructorAutowireWithExclusion.
@Test
public void constructorAutowireWithExclusion() throws Exception {
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class CollectionMergingTests method mergeMapWithInnerBeanAsMapEntryValueInConstructor.
@Test
public void mergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor");
Map map = bean.getSomeMap();
assertNotNull(map);
assertEquals(2, map.size());
assertNotNull(map.get("Rob"));
assertTrue(map.get("Rob") instanceof TestBean);
assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
}
Aggregations