Support for Servlet 4.0 (PushBuilder argument, MockServletContext)

Issue: SPR-12674
This commit is contained in:
Juergen Hoeller
2017-02-13 15:06:59 +01:00
parent d44325ec91
commit 199aa776c9
32 changed files with 237 additions and 272 deletions

View File

@@ -75,11 +75,9 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void servletRequest() throws Exception {
MethodParameter servletRequestParameter = new MethodParameter(method, 0);
assertTrue("ServletRequest not supported", resolver.supportsParameter(servletRequestParameter));
boolean isSupported = resolver.supportsParameter(servletRequestParameter);
Object result = resolver.resolveArgument(servletRequestParameter, mavContainer, webRequest, null);
assertTrue("ServletRequest not supported", isSupported);
assertSame("Invalid result", servletRequest, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
}
@@ -88,12 +86,11 @@ public class ServletRequestMethodArgumentResolverTests {
public void session() throws Exception {
MockHttpSession session = new MockHttpSession();
servletRequest.setSession(session);
MethodParameter sessionParameter = new MethodParameter(method, 2);
assertTrue("Session not supported", resolver.supportsParameter(sessionParameter));
boolean isSupported = resolver.supportsParameter(sessionParameter);
Object result = resolver.resolveArgument(sessionParameter, mavContainer, webRequest, null);
assertTrue("Session not supported", isSupported);
assertSame("Invalid result", session, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
}
@@ -107,8 +104,8 @@ public class ServletRequestMethodArgumentResolverTests {
}
};
servletRequest.setUserPrincipal(principal);
MethodParameter principalParameter = new MethodParameter(method, 3);
MethodParameter principalParameter = new MethodParameter(method, 3);
assertTrue("Principal not supported", resolver.supportsParameter(principalParameter));
Object result = resolver.resolveArgument(principalParameter, null, webRequest, null);
@@ -119,8 +116,8 @@ public class ServletRequestMethodArgumentResolverTests {
public void locale() throws Exception {
Locale locale = Locale.ENGLISH;
servletRequest.addPreferredLocale(locale);
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@@ -132,8 +129,8 @@ public class ServletRequestMethodArgumentResolverTests {
Locale locale = Locale.ENGLISH;
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(locale));
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@@ -143,7 +140,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void timeZone() throws Exception {
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@@ -155,8 +151,8 @@ public class ServletRequestMethodArgumentResolverTests {
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(Locale.US, timeZone));
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@@ -166,7 +162,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void zoneId() throws Exception {
MethodParameter zoneIdParameter = new MethodParameter(method, 9);
assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter));
Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null);
@@ -189,7 +184,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void inputStream() throws Exception {
MethodParameter inputStreamParameter = new MethodParameter(method, 5);
assertTrue("InputStream not supported", resolver.supportsParameter(inputStreamParameter));
Object result = resolver.resolveArgument(inputStreamParameter, null, webRequest, null);
@@ -199,7 +193,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void reader() throws Exception {
MethodParameter readerParameter = new MethodParameter(method, 6);
assertTrue("Reader not supported", resolver.supportsParameter(readerParameter));
Object result = resolver.resolveArgument(readerParameter, null, webRequest, null);
@@ -209,7 +202,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void webRequest() throws Exception {
MethodParameter webRequestParameter = new MethodParameter(method, 7);
assertTrue("WebRequest not supported", resolver.supportsParameter(webRequestParameter));
Object result = resolver.resolveArgument(webRequestParameter, null, webRequest, null);
@@ -219,7 +211,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void httpMethod() throws Exception {
MethodParameter httpMethodParameter = new MethodParameter(method, 10);
assertTrue("HttpMethod not supported", resolver.supportsParameter(httpMethodParameter));
Object result = resolver.resolveArgument(httpMethodParameter, null, webRequest, null);
@@ -241,4 +232,4 @@ public class ServletRequestMethodArgumentResolverTests {
HttpMethod p10) {
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -33,7 +33,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import static org.junit.Assert.*;
/**
* Test fixture with {@link org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver}.
* Test fixture with {@link ServletResponseMethodArgumentResolver}.
*
* @author Arjen Poutsma
*/
@@ -49,6 +49,7 @@ public class ServletResponseMethodArgumentResolverTests {
private MockHttpServletResponse servletResponse;
@Before
public void setUp() throws Exception {
resolver = new ServletResponseMethodArgumentResolver();
@@ -58,10 +59,10 @@ public class ServletResponseMethodArgumentResolverTests {
webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse);
}
@Test
public void servletResponse() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null);
@@ -69,8 +70,7 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled());
}
// SPR-8983
@Test // SPR-8983
public void servletResponseNoMavContainer() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
@@ -82,7 +82,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test
public void outputStream() throws Exception {
MethodParameter outputStreamParameter = new MethodParameter(method, 1);
assertTrue("OutputStream not supported", resolver.supportsParameter(outputStreamParameter));
Object result = resolver.resolveArgument(outputStreamParameter, mavContainer, webRequest, null);
@@ -93,7 +92,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test
public void writer() throws Exception {
MethodParameter writerParameter = new MethodParameter(method, 2);
assertTrue("Writer not supported", resolver.supportsParameter(writerParameter));
Object result = resolver.resolveArgument(writerParameter, mavContainer, webRequest, null);
@@ -101,7 +99,9 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled());
}
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
@SuppressWarnings("unused")
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
}
}
}