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:
@@ -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.
|
||||
@@ -26,6 +26,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;
|
||||
@@ -66,11 +67,11 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
Method method = getClass().getMethod("handle", String.class,
|
||||
Map.class, MultiValueMap.class, MultiValueMap.class, Map.class);
|
||||
|
||||
this.paramString = new MethodParameter(method, 0);
|
||||
this.paramMap = new MethodParameter(method, 1);
|
||||
this.paramMultivalueMap = new MethodParameter(method, 2);
|
||||
this.paramMapForPathVar = new MethodParameter(method, 3);
|
||||
this.paramMapWithName = new MethodParameter(method, 4);
|
||||
this.paramString = new SynthesizingMethodParameter(method, 0);
|
||||
this.paramMap = new SynthesizingMethodParameter(method, 1);
|
||||
this.paramMultivalueMap = new SynthesizingMethodParameter(method, 2);
|
||||
this.paramMapForPathVar = new SynthesizingMethodParameter(method, 3);
|
||||
this.paramMapWithName = new SynthesizingMethodParameter(method, 4);
|
||||
|
||||
this.mavContainer = new ModelAndViewContainer();
|
||||
this.request = new MockHttpServletRequest();
|
||||
@@ -91,7 +92,6 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveArgument() throws Exception {
|
||||
|
||||
MultiValueMap<String, String> params = getMatrixVariables("cars");
|
||||
params.add("colors", "red");
|
||||
params.add("colors", "green");
|
||||
@@ -113,7 +113,6 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveArgumentPathVariable() throws Exception {
|
||||
|
||||
MultiValueMap<String, String> params1 = getMatrixVariables("cars");
|
||||
params1.add("colors", "red");
|
||||
params1.add("colors", "purple");
|
||||
@@ -137,7 +136,6 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNoParams() throws Exception {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = (Map<String, String>) this.resolver.resolveArgument(
|
||||
this.paramMap, this.mavContainer, this.webRequest, null);
|
||||
@@ -147,7 +145,6 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveArgumentNoMatch() throws Exception {
|
||||
|
||||
MultiValueMap<String, String> params2 = getMatrixVariables("planes");
|
||||
params2.add("colors", "yellow");
|
||||
params2.add("colors", "orange");
|
||||
@@ -162,7 +159,6 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MultiValueMap<String, String> getMatrixVariables(String pathVarName) {
|
||||
|
||||
Map<String, MultiValueMap<String, String>> matrixVariables =
|
||||
(Map<String, MultiValueMap<String, String>>) this.request.getAttribute(
|
||||
HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
|
||||
@@ -182,4 +178,4 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
|
||||
@MatrixVariable("name") Map<String, String> mapWithName) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.Part;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -36,6 +32,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
@@ -58,6 +55,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.support.MissingServletRequestPartException;
|
||||
import org.springframework.web.multipart.support.RequestPartServletServerHttpRequest;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestPartMethodArgumentResolver} and mock {@link HttpMessageConverter}.
|
||||
*
|
||||
@@ -102,26 +102,26 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
Integer.TYPE, MultipartFile.class, Part.class, List.class, Part[].class,
|
||||
MultipartFile.class, Optional.class, Optional.class, Optional.class);
|
||||
|
||||
paramRequestPart = new MethodParameter(method, 0);
|
||||
paramRequestPart = new SynthesizingMethodParameter(method, 0);
|
||||
paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
paramNamedRequestPart = new MethodParameter(method, 1);
|
||||
paramValidRequestPart = new MethodParameter(method, 2);
|
||||
paramMultipartFile = new MethodParameter(method, 3);
|
||||
paramMultipartFileList = new MethodParameter(method, 4);
|
||||
paramMultipartFileArray = new MethodParameter(method, 5);
|
||||
paramInt = new MethodParameter(method, 6);
|
||||
paramMultipartFileNotAnnot = new MethodParameter(method, 7);
|
||||
paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
|
||||
paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
|
||||
paramMultipartFile = new SynthesizingMethodParameter(method, 3);
|
||||
paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
|
||||
paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
|
||||
paramInt = new SynthesizingMethodParameter(method, 6);
|
||||
paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
|
||||
paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
paramPart = new MethodParameter(method, 8);
|
||||
paramPart = new SynthesizingMethodParameter(method, 8);
|
||||
paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
paramPartList = new MethodParameter(method, 9);
|
||||
paramPartArray = new MethodParameter(method, 10);
|
||||
paramRequestParamAnnot = new MethodParameter(method, 11);
|
||||
optionalMultipartFile = new MethodParameter(method, 12);
|
||||
paramPartList = new SynthesizingMethodParameter(method, 9);
|
||||
paramPartArray = new SynthesizingMethodParameter(method, 10);
|
||||
paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
|
||||
optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
|
||||
optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
optionalPart = new MethodParameter(method, 13);
|
||||
optionalPart = new SynthesizingMethodParameter(method, 13);
|
||||
optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
optionalRequestPart = new MethodParameter(method, 14);
|
||||
optionalRequestPart = new SynthesizingMethodParameter(method, 14);
|
||||
|
||||
messageConverter = mock(HttpMessageConverter.class);
|
||||
given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
|
||||
|
||||
@@ -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.
|
||||
@@ -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.annotation.CookieValue;
|
||||
@@ -48,18 +49,20 @@ public class ServletCookieValueMethodArgumentResolverTests {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new ServletCookieValueMethodArgumentResolver(null);
|
||||
|
||||
Method method = getClass().getMethod("params", Cookie.class, String.class);
|
||||
cookieParameter = new MethodParameter(method, 0);
|
||||
cookieStringParameter = new MethodParameter(method, 1);
|
||||
cookieParameter = new SynthesizingMethodParameter(method, 0);
|
||||
cookieStringParameter = new SynthesizingMethodParameter(method, 1);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveCookieArgument() throws Exception {
|
||||
Cookie expected = new Cookie("name", "foo");
|
||||
@@ -78,8 +81,9 @@ public class ServletCookieValueMethodArgumentResolverTests {
|
||||
assertEquals("Invalid result", cookie.getValue(), result);
|
||||
}
|
||||
|
||||
|
||||
public void params(@CookieValue("name") Cookie cookie,
|
||||
@CookieValue(name = "name", defaultValue = "bar") String cookieString) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user