Search in sources :

Example 86 with TestBean

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());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Test(org.junit.Test)

Example 87 with TestBean

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());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Test(org.junit.Test)

Example 88 with TestBean

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());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Test(org.junit.Test)

Example 89 with TestBean

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"));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 90 with TestBean

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());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TestBean (org.springframework.tests.sample.beans.TestBean)788 Test (org.junit.Test)740 ITestBean (org.springframework.tests.sample.beans.ITestBean)456 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)248 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)225 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)164 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)160 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)144 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)86 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)44 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)40 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)40 Properties (java.util.Properties)35 Errors (org.springframework.validation.Errors)34 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)33 PropertyEditorSupport (java.beans.PropertyEditorSupport)31 HashMap (java.util.HashMap)30 List (java.util.List)27 Map (java.util.Map)27 PageContext (javax.servlet.jsp.PageContext)27