Examples of DependenciesBean


Examples of org.springframework.beans.factory.xml.DependenciesBean

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

  public void testAutowireExistingBeanByTypeWithDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    DependenciesBean existingBean = new DependenciesBean();
    try {
      lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException expected) {
View Full Code Here

Examples of org.springframework.beans.factory.xml.DependenciesBean

    }
  }

  public void testAutowireExistingBeanByTypeWithNoDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    DependenciesBean existingBean = new DependenciesBean();
    lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    assertNull(existingBean.getSpouse());
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

  @Test
  public void testSatisfiedObjectDependencyCheck() throws Exception {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_OBJECT_DEP_CONTEXT);
    DependenciesBean a = (DependenciesBean) xbf.getBean("a");
    assertNotNull(a.getSpouse());
    assertEquals(xbf, a.getBeanFactory());
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

  @Test
  public void testSatisfiedSimpleDependencyCheck() throws Exception {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_SIMPLE_DEP_CONTEXT);
    DependenciesBean a = (DependenciesBean) xbf.getBean("a");
    assertEquals(a.getAge(), 33);
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

  @Test
  public void testSatisfiedAllDependencyCheck() throws Exception {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_ALL_DEP_CONTEXT);
    DependenciesBean a = (DependenciesBean) xbf.getBean("a");
    assertEquals(a.getAge(), 33);
    assertNotNull(a.getName());
    assertNotNull(a.getSpouse());
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

    xbf.setParentBeanFactory(lbf);
    doTestAutowire(xbf);
  }

  private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception {
    DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
    TestBean kerry = (TestBean) xbf.getBean("spouse");
    // should have been autowired
    assertEquals(kerry, rod1.getSpouse());

    DependenciesBean rod1a = (DependenciesBean) xbf.getBean("rod1a");
    // should have been autowired
    assertEquals(kerry, rod1a.getSpouse());

    DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
    // should have been autowired
    assertEquals(kerry, rod2.getSpouse());

    DependenciesBean rod2a = (DependenciesBean) xbf.getBean("rod2a");
    // should have been set explicitly
    assertEquals(kerry, rod2a.getSpouse());

    ConstructorDependenciesBean rod3 = (ConstructorDependenciesBean) xbf.getBean("rod3");
    IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
    // should have been autowired
    assertEquals(kerry, rod3.getSpouse1());
    assertEquals(kerry, rod3.getSpouse2());
    assertEquals(other, rod3.getOther());

    ConstructorDependenciesBean rod3a = (ConstructorDependenciesBean) xbf.getBean("rod3a");
    // should have been autowired
    assertEquals(kerry, rod3a.getSpouse1());
    assertEquals(kerry, rod3a.getSpouse2());
    assertEquals(other, rod3a.getOther());

    try {
      xbf.getBean("rod4", ConstructorDependenciesBean.class);
      fail("Must have thrown a FatalBeanException");
    }
    catch (FatalBeanException expected) {
      // expected
    }

    DependenciesBean rod5 = (DependenciesBean) xbf.getBean("rod5");
    // Should not have been autowired
    assertNull(rod5.getSpouse());

    BeanFactory appCtx = (BeanFactory) xbf.getBean("childAppCtx");
    assertTrue(appCtx.containsBean("rod1"));
    assertTrue(appCtx.containsBean("jenny"));
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

  @Test
  public void testAutowireWithDefault() throws Exception {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT);

    DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
    // should have been autowired
    assertNotNull(rod1.getSpouse());
    assertTrue(rod1.getSpouse().getName().equals("Kerry"));

    DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
    // should have been autowired
    assertNotNull(rod2.getSpouse());
    assertTrue(rod2.getSpouse().getName().equals("Kerry"));

    try {
      xbf.getBean("rod3", DependenciesBean.class);
      fail("Must have thrown UnsatisfiedDependencyException");
    }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

    assertTrue(lbf.containsBean("singletonObject"));
    assertTrue(lbf.isSingleton("singletonObject"));
    assertEquals(TestBean.class, lbf.getType("singletonObject"));
    assertEquals(0, lbf.getAliases("singletonObject").length);
    DependenciesBean test = (DependenciesBean) lbf.getBean("test");
    assertEquals(singletonObject, lbf.getBean("singletonObject"));
    assertEquals(singletonObject, test.getSpouse());
  }
View Full Code Here

Examples of org.springframework.tests.sample.beans.DependenciesBean

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

Examples of org.springframework.tests.sample.beans.DependenciesBean

  @Test
  public void testAutowireBeanByName() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    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
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.