Search in sources :

Example 1 with DependenciesBean

use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireExistingBeanByType.

@Test
void autowireExistingBeanByType() {
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("test", bd);
    DependenciesBean existingBean = new DependenciesBean();
    lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    TestBean test = (TestBean) lbf.getBean("test");
    assertThat(test).isEqualTo(existingBean.getSpouse());
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.beans.testfixture.beans.DependenciesBean) Test(org.junit.jupiter.api.Test)

Example 2 with DependenciesBean

use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireBeanByName.

@Test
void autowireBeanByName() {
    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");
    assertThat(bean.getSpouse()).isEqualTo(spouse);
    assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse).isTrue();
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.beans.testfixture.beans.DependenciesBean) Test(org.junit.jupiter.api.Test)

Example 3 with DependenciesBean

use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireBeanByTypeWithNoDependencyCheck.

@Test
void autowireBeanByTypeWithNoDependencyCheck() {
    DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    assertThat(bean.getSpouse()).isNull();
}
Also used : ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.beans.testfixture.beans.DependenciesBean) Test(org.junit.jupiter.api.Test)

Example 4 with DependenciesBean

use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireBeanByType.

@Test
void autowireBeanByType() {
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("test", bd);
    DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    TestBean test = (TestBean) lbf.getBean("test");
    assertThat(bean.getSpouse()).isEqualTo(test);
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.beans.testfixture.beans.DependenciesBean) Test(org.junit.jupiter.api.Test)

Example 5 with DependenciesBean

use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireBeanByTypeWithTwoMatchesAndOnePrimary.

@Test
void autowireBeanByTypeWithTwoMatchesAndOnePrimary() {
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    bd.setPrimary(true);
    RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("test", bd);
    lbf.registerBeanDefinition("spouse", bd2);
    DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    assertThat(bean.getSpouse()).isEqualTo(lbf.getBean("test"));
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.beans.testfixture.beans.DependenciesBean) Test(org.junit.jupiter.api.Test)

Aggregations

DependenciesBean (org.springframework.beans.testfixture.beans.DependenciesBean)17 Test (org.junit.jupiter.api.Test)16 ConstructorDependenciesBean (org.springframework.beans.factory.xml.ConstructorDependenciesBean)15 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)7 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)7 TestBean (org.springframework.beans.testfixture.beans.TestBean)7 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)6 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 FatalBeanException (org.springframework.beans.FatalBeanException)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)1 ResourceTestBean (org.springframework.tests.sample.beans.ResourceTestBean)1