Search in sources :

Example 6 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-security by spring-projects.

the class DefaultSecurityParameterNameDiscovererTests method constructorDiscoverers.

@Test
public void constructorDiscoverers() {
    discoverer = new DefaultSecurityParameterNameDiscoverer(Arrays.asList(new LocalVariableTableParameterNameDiscoverer()));
    List<ParameterNameDiscoverer> discoverers = (List<ParameterNameDiscoverer>) ReflectionTestUtils.getField(discoverer, "parameterNameDiscoverers");
    assertThat(discoverers.size()).isEqualTo(3);
    assertThat(discoverers.get(0)).isInstanceOf(LocalVariableTableParameterNameDiscoverer.class);
    ParameterNameDiscoverer annotationDisc = discoverers.get(1);
    assertThat(annotationDisc).isInstanceOf(AnnotationParameterNameDiscoverer.class);
    Set<String> annotationsToUse = (Set<String>) ReflectionTestUtils.getField(annotationDisc, "annotationClassesToUse");
    assertThat(annotationsToUse).containsOnly(P.class.getName());
    assertThat(discoverers.get(2).getClass()).isEqualTo(DefaultParameterNameDiscoverer.class);
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) P(org.springframework.security.access.method.P) Set(java.util.Set) ParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer) DefaultParameterNameDiscoverer(org.springframework.core.DefaultParameterNameDiscoverer) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) List(java.util.List) Test(org.junit.Test)

Example 7 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer 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 8 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer 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 9 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class PayloadArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator());
    Method payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod("handleMessage", String.class, String.class, Locale.class, String.class, String.class, String.class, String.class);
    this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0);
    this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1);
    this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
    this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
    this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
    this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
    this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Method(java.lang.reflect.Method) Before(org.junit.Before)

Aggregations

LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)9 Method (java.lang.reflect.Method)5 Before (org.junit.Before)3 Test (org.junit.Test)3 MethodParameter (org.springframework.core.MethodParameter)3 Ignore (org.junit.Ignore)2 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)2 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)2 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)2 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)2 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)2 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Set (java.util.Set)1 DefaultParameterNameDiscoverer (org.springframework.core.DefaultParameterNameDiscoverer)1 ParameterNameDiscoverer (org.springframework.core.ParameterNameDiscoverer)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1