Package org.springframework.beans.factory.support

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()


  public void testAutowireWithNoDependencies() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("rod", bd);
    assertEquals(1, lbf.getBeanDefinitionCount());
    Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
    assertEquals(1, lbf.getBeanDefinitionCount());
    assertTrue(registered instanceof NoDependencies);
  }

  public void testAutowireWithSatisfiedJavaBeanDependency() {
View Full Code Here


    pvs.addPropertyValue("name", "Rod");
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
    lbf.registerBeanDefinition("rod", bd);
    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

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("name", "Rod");
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
    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

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("rod", bd);
    RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("rod2", bd2);
    try {
      lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
      assertTrue(ex.getMessage().indexOf("rod") != -1);
View Full Code Here

    pvs.addPropertyValue(new PropertyValue("name", "Rod"));
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
    lbf.registerBeanDefinition("rod", bd);
    assertEquals(1, lbf.getBeanDefinitionCount());
    try {
      lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
      fail("Should have unsatisfied constructor dependency on SideEffectBean");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
    }
View Full Code Here

  public void testAutowireConstructor() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    ConstructorDependenciesBean bean = (ConstructorDependenciesBean)
        lbf.autowire(ConstructorDependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
    Object spouse = lbf.getBean("spouse");
    assertTrue(bean.getSpouse1() == spouse);
    assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
  }
View Full Code Here

  public void testAutowireBeanByName() {
    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

  public void testAutowireBeanByNameWithDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spous", bd);
    try {
      lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
    }
View Full Code Here

  public void testAutowireBeanByNameWithNoDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spous", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    assertNull(bean.getSpouse());
  }

  public void testAutowireBeanByType() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
View Full Code Here

  public void testAutowireBeanByType() {
    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
Copyright © 2018 www.massapi.com. 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.