Package org.springframework.beans

Examples of org.springframework.beans.TestBean


    p.setProperty("test.(class)", "org.springframework.beans.TestBean");
    p.setProperty("test.name", "Tony");
    p.setProperty("test.age", "48");
    p.setProperty("test.spouse(ref)", "singletonObject");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    Object singletonObject = new TestBean();
    lbf.registerSingleton("singletonObject", singletonObject);

    assertTrue(lbf.isSingleton("singletonObject"));
    assertEquals(TestBean.class, lbf.getType("singletonObject"));
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(singletonObject, lbf.getBean("singletonObject"));
    assertEquals(singletonObject, test.getSpouse());

    Map beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
    assertEquals(2, beansOfType.size());
    assertTrue(beansOfType.containsValue(test));
    assertTrue(beansOfType.containsValue(singletonObject));
View Full Code Here


    p.setProperty("test.name", "Tony");
    p.setProperty("test.age", "48");
    p.setProperty("test.spouse(ref)", "singletonObject");
    p.setProperty("singletonObject.(class)", "org.springframework.beans.factory.config.PropertiesFactoryBean");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    Object singletonObject = new TestBean();
    lbf.registerSingleton("singletonObject", singletonObject);
    lbf.preInstantiateSingletons();

    assertTrue(lbf.isSingleton("singletonObject"));
    assertEquals(TestBean.class, lbf.getType("singletonObject"));
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(singletonObject, lbf.getBean("singletonObject"));
    assertEquals(singletonObject, test.getSpouse());

    Map beansOfType = lbf.getBeansOfType(TestBean.class, false, true);
    assertEquals(2, beansOfType.size());
    assertTrue(beansOfType.containsValue(test));
    assertTrue(beansOfType.containsValue(singletonObject));
View Full Code Here

* @author Rod Johnson
*/
public class TestBeanCreator {
 
  public static TestBean createTestBean(String name, int age) {
    TestBean tb = new TestBean();
    tb.setName(name);
    tb.setAge(age);
    return tb;
  }
View Full Code Here

    pvs.addPropertyValue("age", "48");
    RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class, pvs);
    bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
    bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
    lbf.registerBeanDefinition("test", bd);
    Object singletonObject = new TestBean();
    lbf.registerSingleton("singletonObject", singletonObject);

    assertTrue(lbf.containsBean("singletonObject"));
    assertTrue(lbf.isSingleton("singletonObject"));
    assertEquals(TestBean.class, lbf.getType("singletonObject"));
View Full Code Here

    tb.setAge(age);
    return tb;
  }
 
  public static TestBean createTestBean() {
    TestBean tb = new TestBean();
    tb.setName("Tristan");
    tb.setAge(2);
    return tb;
  }
View Full Code Here

    assertEquals(singletonObject, test.getSpouse());
  }

  public void testRegisterExistingSingletonWithAlreadyBound() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Object singletonObject = new TestBean();
    lbf.registerSingleton("singletonObject", singletonObject);
    try {
      lbf.registerSingleton("singletonObject", singletonObject);
      fail("Should have thrown IllegalStateException");
    }
View Full Code Here

    assertEquals(1, lbf.getBeanDefinitionCount());
    // Depends on age, name and spouse (TestBean)
    Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
    assertEquals(1, lbf.getBeanDefinitionCount());
    DependenciesBean kerry = (DependenciesBean) registered;
    TestBean rod = (TestBean) lbf.getBean("rod");
    assertSame(rod, kerry.getSpouse());
  }
View Full Code Here

    lbf.registerBeanDefinition("rod", bd);
    assertEquals(1, lbf.getBeanDefinitionCount());
    Object registered = lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
    assertEquals(1, lbf.getBeanDefinitionCount());
    ConstructorDependency kerry = (ConstructorDependency) registered;
    TestBean rod = (TestBean) lbf.getBean("rod");
    assertSame(rod, kerry.spouse);
  }
View Full Code Here

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    assertEquals(spouse, bean.getSpouse());
    assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
  }
View Full Code Here

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("test", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(test, bean.getSpouse());
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.TestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.