Split between basic MethodParameter and SynthesizingMethodParameter
This split avoids a package tangle (between core and core.annotation) and also allows for selective use of raw annotation exposure versus synthesized annotations, with the latter primarily applicable to web and message handler processing at this point. Issue: SPR-13153
This commit is contained in:
@@ -23,6 +23,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.web.bind.ServletRequestBindingException;
|
||||
@@ -52,19 +53,21 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new TestCookieValueMethodArgumentResolver();
|
||||
|
||||
Method method = getClass().getMethod("params", Cookie.class, String.class, String.class);
|
||||
paramNamedCookie = new MethodParameter(method, 0);
|
||||
paramNamedDefaultValueString = new MethodParameter(method, 1);
|
||||
paramString = new MethodParameter(method, 2);
|
||||
paramNamedCookie = new SynthesizingMethodParameter(method, 0);
|
||||
paramNamedDefaultValueString = new SynthesizingMethodParameter(method, 1);
|
||||
paramString = new SynthesizingMethodParameter(method, 2);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue("Cookie parameter not supported", resolver.supportsParameter(paramNamedCookie));
|
||||
@@ -98,9 +101,10 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void params(@CookieValue("name") Cookie param1,
|
||||
@CookieValue(name = "name", defaultValue = "bar") String param2,
|
||||
String param3) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
@@ -57,20 +58,22 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new RequestHeaderMapMethodArgumentResolver();
|
||||
|
||||
Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, HttpHeaders.class, Map.class);
|
||||
paramMap = new MethodParameter(method, 0);
|
||||
paramMultiValueMap = new MethodParameter(method, 1);
|
||||
paramHttpHeaders = new MethodParameter(method, 2);
|
||||
paramUnsupported = new MethodParameter(method, 3);
|
||||
paramMap = new SynthesizingMethodParameter(method, 0);
|
||||
paramMultiValueMap = new SynthesizingMethodParameter(method, 1);
|
||||
paramHttpHeaders = new SynthesizingMethodParameter(method, 2);
|
||||
paramUnsupported = new SynthesizingMethodParameter(method, 3);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue("Map parameter not supported", resolver.supportsParameter(paramMap));
|
||||
@@ -130,10 +133,11 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||
assertEquals("Invalid result", expected, result);
|
||||
}
|
||||
|
||||
|
||||
public void params(@RequestHeader Map<?, ?> param1,
|
||||
@RequestHeader MultiValueMap<?, ?> param2,
|
||||
@RequestHeader HttpHeaders param3,
|
||||
Map<?,?> unsupported) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.web.bind.ServletRequestBindingException;
|
||||
@@ -55,6 +56,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
|
||||
private NativeWebRequest webRequest;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
GenericWebApplicationContext context = new GenericWebApplicationContext();
|
||||
@@ -62,11 +64,11 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory());
|
||||
|
||||
Method method = getClass().getMethod("params", String.class, String[].class, String.class, String.class, Map.class);
|
||||
paramNamedDefaultValueStringHeader = new MethodParameter(method, 0);
|
||||
paramNamedValueStringArray = new MethodParameter(method, 1);
|
||||
paramSystemProperty = new MethodParameter(method, 2);
|
||||
paramContextPath = new MethodParameter(method, 3);
|
||||
paramNamedValueMap = new MethodParameter(method, 4);
|
||||
paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
|
||||
paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
|
||||
paramSystemProperty = new SynthesizingMethodParameter(method, 2);
|
||||
paramContextPath = new SynthesizingMethodParameter(method, 3);
|
||||
paramNamedValueMap = new SynthesizingMethodParameter(method, 4);
|
||||
|
||||
servletRequest = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
|
||||
@@ -80,6 +82,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue("String parameter not supported", resolver.supportsParameter(paramNamedDefaultValueStringHeader));
|
||||
@@ -141,6 +144,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
resolver.resolveArgument(paramNamedValueStringArray, null, webRequest, null);
|
||||
}
|
||||
|
||||
|
||||
public void params(@RequestHeader(name = "name", defaultValue = "bar") String param1,
|
||||
@RequestHeader("name") String[] param2,
|
||||
@RequestHeader(name = "name", defaultValue="#{systemProperties.systemProperty}") String param3,
|
||||
@@ -148,4 +152,4 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
@RequestHeader("name") Map<?, ?> unsupported) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -56,20 +57,22 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new RequestParamMapMethodArgumentResolver();
|
||||
|
||||
Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, Map.class, Map.class);
|
||||
paramMap = new MethodParameter(method, 0);
|
||||
paramMultiValueMap = new MethodParameter(method, 1);
|
||||
paramNamedMap = new MethodParameter(method, 2);
|
||||
paramMapWithoutAnnot = new MethodParameter(method, 3);
|
||||
paramMap = new SynthesizingMethodParameter(method, 0);
|
||||
paramMultiValueMap = new SynthesizingMethodParameter(method, 1);
|
||||
paramNamedMap = new SynthesizingMethodParameter(method, 2);
|
||||
paramMapWithoutAnnot = new SynthesizingMethodParameter(method, 3);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue("Map parameter not supported", resolver.supportsParameter(paramMap));
|
||||
@@ -108,10 +111,11 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||
assertEquals("Invalid result", expected, result);
|
||||
}
|
||||
|
||||
|
||||
public void params(@RequestParam Map<?, ?> param1,
|
||||
@RequestParam MultiValueMap<?, ?> param2,
|
||||
@RequestParam("name") Map<?, ?> param3,
|
||||
Map<?, ?> param4) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
@@ -99,28 +99,28 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
String.class, MultipartFile.class, List.class, Part.class,
|
||||
MultipartFile.class, String.class, String.class, Optional.class);
|
||||
|
||||
paramNamedDefaultValueString = new MethodParameter(method, 0);
|
||||
paramNamedStringArray = new MethodParameter(method, 1);
|
||||
paramNamedMap = new MethodParameter(method, 2);
|
||||
paramMultipartFile = new MethodParameter(method, 3);
|
||||
paramMultipartFileList = new MethodParameter(method, 4);
|
||||
paramMultipartFileArray = new MethodParameter(method, 5);
|
||||
paramPart = new MethodParameter(method, 6);
|
||||
paramPartList = new MethodParameter(method, 7);
|
||||
paramPartArray = new MethodParameter(method, 8);
|
||||
paramMap = new MethodParameter(method, 9);
|
||||
paramStringNotAnnot = new MethodParameter(method, 10);
|
||||
paramNamedDefaultValueString = new SynthesizingMethodParameter(method, 0);
|
||||
paramNamedStringArray = new SynthesizingMethodParameter(method, 1);
|
||||
paramNamedMap = new SynthesizingMethodParameter(method, 2);
|
||||
paramMultipartFile = new SynthesizingMethodParameter(method, 3);
|
||||
paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
|
||||
paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
|
||||
paramPart = new SynthesizingMethodParameter(method, 6);
|
||||
paramPartList = new SynthesizingMethodParameter(method, 7);
|
||||
paramPartArray = new SynthesizingMethodParameter(method, 8);
|
||||
paramMap = new SynthesizingMethodParameter(method, 9);
|
||||
paramStringNotAnnot = new SynthesizingMethodParameter(method, 10);
|
||||
paramStringNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
|
||||
paramMultipartFileNotAnnot = new MethodParameter(method, 11);
|
||||
paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 11);
|
||||
paramMultipartFileNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
|
||||
paramMultipartFileListNotAnnot = new MethodParameter(method, 12);
|
||||
paramMultipartFileListNotAnnot = new SynthesizingMethodParameter(method, 12);
|
||||
paramMultipartFileListNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
|
||||
paramPartNotAnnot = new MethodParameter(method, 13);
|
||||
paramPartNotAnnot = new SynthesizingMethodParameter(method, 13);
|
||||
paramPartNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
|
||||
paramRequestPartAnnot = new MethodParameter(method, 14);
|
||||
paramRequired = new MethodParameter(method, 15);
|
||||
paramNotRequired = new MethodParameter(method, 16);
|
||||
paramOptional = new MethodParameter(method, 17);
|
||||
paramRequestPartAnnot = new SynthesizingMethodParameter(method, 14);
|
||||
paramRequired = new SynthesizingMethodParameter(method, 15);
|
||||
paramNotRequired = new SynthesizingMethodParameter(method, 16);
|
||||
paramOptional = new SynthesizingMethodParameter(method, 17);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
|
||||
Reference in New Issue
Block a user