Search in sources :

Example 6 with DependencyDescriptor

use of org.springframework.beans.factory.config.DependencyDescriptor in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateWithConstructorDescriptor.

@Ignore
@Test
public void testAutowireCandidateWithConstructorDescriptor() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    lbf.registerBeanDefinition(JUERGEN, person1);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    lbf.registerBeanDefinition(MARK, person2);
    MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
    DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
    param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    assertEquals("tpb", param.getParameterName());
    assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
    assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) MethodParameter(org.springframework.core.MethodParameter) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with DependencyDescriptor

use of org.springframework.beans.factory.config.DependencyDescriptor in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateDefaultWithIrrelevantDescriptor.

@Test
public void testAutowireCandidateDefaultWithIrrelevantDescriptor() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition rbd = new RootBeanDefinition(Person.class, cavs, null);
    lbf.registerBeanDefinition(JUERGEN, rbd);
    assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, new DependencyDescriptor(Person.class.getDeclaredField("name"), false)));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, new DependencyDescriptor(Person.class.getDeclaredField("name"), true)));
}
Also used : DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Example 8 with DependencyDescriptor

use of org.springframework.beans.factory.config.DependencyDescriptor in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateExplicitlyFalseWithIrrelevantDescriptor.

@Test
public void testAutowireCandidateExplicitlyFalseWithIrrelevantDescriptor() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition rbd = new RootBeanDefinition(Person.class, cavs, null);
    rbd.setAutowireCandidate(false);
    lbf.registerBeanDefinition(JUERGEN, rbd);
    assertFalse(lbf.isAutowireCandidate(JUERGEN, null));
    assertFalse(lbf.isAutowireCandidate(JUERGEN, new DependencyDescriptor(Person.class.getDeclaredField("name"), false)));
    assertFalse(lbf.isAutowireCandidate(JUERGEN, new DependencyDescriptor(Person.class.getDeclaredField("name"), true)));
}
Also used : DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Example 9 with DependencyDescriptor

use of org.springframework.beans.factory.config.DependencyDescriptor in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateWithMethodDescriptor.

@Ignore
@Test
public void testAutowireCandidateWithMethodDescriptor() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
    cavs1.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
    person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
    lbf.registerBeanDefinition(JUERGEN, person1);
    ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
    cavs2.addGenericArgumentValue(MARK);
    RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
    lbf.registerBeanDefinition(MARK, person2);
    MethodParameter qualifiedParam = new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireQualified", Person.class), 0);
    MethodParameter nonqualifiedParam = new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireNonqualified", Person.class), 0);
    DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(qualifiedParam, false);
    DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(nonqualifiedParam, false);
    qualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    assertEquals("tpb", qualifiedParam.getParameterName());
    nonqualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    assertEquals("tpb", nonqualifiedParam.getParameterName());
    assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
    assertTrue(lbf.isAutowireCandidate(MARK, null));
    assertTrue(lbf.isAutowireCandidate(MARK, nonqualifiedDescriptor));
    assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) MethodParameter(org.springframework.core.MethodParameter) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with DependencyDescriptor

use of org.springframework.beans.factory.config.DependencyDescriptor in project spring-framework by spring-projects.

the class QualifierAnnotationAutowireBeanFactoryTests method testAutowireCandidateWithShortClassName.

@Test
public void testAutowireCandidateWithShortClassName() throws Exception {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addGenericArgumentValue(JUERGEN);
    RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
    person.addQualifier(new AutowireCandidateQualifier(ClassUtils.getShortName(TestQualifier.class)));
    lbf.registerBeanDefinition(JUERGEN, person);
    DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(QualifiedTestBean.class.getDeclaredField("qualified"), false);
    DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(QualifiedTestBean.class.getDeclaredField("nonqualified"), false);
    assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
    assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
}
Also used : DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.Test)

Aggregations

DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)12 Test (org.junit.Test)8 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)8 MethodParameter (org.springframework.core.MethodParameter)5 Ignore (org.junit.Ignore)3 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)2 PropertyDescriptor (java.beans.PropertyDescriptor)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 BeansException (org.springframework.beans.BeansException)1 TypeConverter (org.springframework.beans.TypeConverter)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)1 PriorityOrdered (org.springframework.core.PriorityOrdered)1 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)1