Sync with 3.1.x
* 3.1.x: (61 commits) Compensate for changes in JDK 7 Introspector Avoid 'type mismatch' errors in ExtendedBeanInfo Polish ExtendedBeanInfo and tests Infer AnnotationAttributes method return types Minor fix in MVC reference doc chapter Hibernate 4.1 etc TypeDescriptor equals implementation accepts annotations in any order "setBasenames" uses varargs now (for programmatic setup; SPR-9106) @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992 polishing clarified Resource's "getFilename" method to consistently return null substituteNamedParameters detects and unwraps SqlParameterValue object Replace spaces with tabs Consider security in ClassUtils#getMostSpecificMethod Adding null check for username being null. Improvements for registering custom SQL exception translators in app c SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera Minor polish in WebMvcConfigurationSupport Detect overridden boolean getters in ExtendedBeanInfo Polish ExtendedBeanInfoTests ...
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.context;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -116,7 +117,7 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextLoaderListenerWithRegisteredContextConfigurer() {
|
||||
public void testContextLoaderListenerWithRegisteredContextInitializer() {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
||||
"org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
|
||||
@@ -132,7 +133,20 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextLoaderListenerWithUnkownContextConfigurer() {
|
||||
public void testRegisteredContextInitializerCanAccessServletContextParamsViaEnvironment() {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
// config file doesn't matter. just a placeholder
|
||||
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
||||
"/org/springframework/web/context/WEB-INF/empty-context.xml");
|
||||
|
||||
sc.addInitParameter("someProperty", "someValue");
|
||||
sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, EnvApplicationContextInitializer.class.getName());
|
||||
ContextLoaderListener listener = new ContextLoaderListener();
|
||||
listener.contextInitialized(new ServletContextEvent(sc));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextLoaderListenerWithUnkownContextInitializer() {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
// config file doesn't matter. just a placeholder
|
||||
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
||||
@@ -324,6 +338,15 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class EnvApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
|
||||
public void initialize(ConfigurableWebApplicationContext applicationContext) {
|
||||
// test that ApplicationContextInitializers can access ServletContext properties
|
||||
// via the environment (SPR-8991)
|
||||
String value = applicationContext.getEnvironment().getRequiredProperty("someProperty");
|
||||
assertThat(value, is("someValue"));
|
||||
}
|
||||
}
|
||||
|
||||
private static interface UnknownApplicationContext extends ConfigurableApplicationContext {
|
||||
void unheardOf();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -227,12 +227,22 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test(expected=MultipartException.class)
|
||||
public void notMultipartRequest() throws Exception {
|
||||
public void isMultipartRequest() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
resolver.resolveArgument(paramMultipartFile, new ModelAndViewContainer(), new ServletWebRequest(request), null);
|
||||
fail("Expected exception");
|
||||
}
|
||||
|
||||
// SPR-9079
|
||||
|
||||
@Test
|
||||
public void isMultipartRequestPut() throws Exception {
|
||||
this.multipartRequest.setMethod("PUT");
|
||||
Object actual = resolver.resolveArgument(paramMultipartFile, null, webRequest, null);
|
||||
assertNotNull(actual);
|
||||
assertSame(multipartFile1, actual);
|
||||
}
|
||||
|
||||
private void testResolveArgument(SimpleBean argValue, MethodParameter parameter) throws IOException, Exception {
|
||||
MediaType contentType = MediaType.TEXT_PLAIN;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -60,7 +59,7 @@ public class AbstractFlashMapManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestByPath() {
|
||||
public void retrieveAndUpdateMatchByPath() {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
flashMap.setTargetRequestPath("/path");
|
||||
@@ -68,16 +67,15 @@ public class AbstractFlashMapManagerTests {
|
||||
this.flashMapManager.setFlashMaps(flashMap);
|
||||
|
||||
this.request.setRequestURI("/path");
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMap, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
// SPR-8779
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestByOriginatingPath() {
|
||||
public void retrieveAndUpdateMatchByOriginatingPath() {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
flashMap.setTargetRequestPath("/accounts");
|
||||
@@ -86,14 +84,14 @@ public class AbstractFlashMapManagerTests {
|
||||
|
||||
this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts");
|
||||
this.request.setRequestURI("/mvc/accounts");
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMap, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestByPathWithTrailingSlash() {
|
||||
public void retrieveAndUpdateMatchWithTrailingSlash() {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
flashMap.setTargetRequestPath("/path");
|
||||
@@ -101,14 +99,14 @@ public class AbstractFlashMapManagerTests {
|
||||
this.flashMapManager.setFlashMaps(flashMap);
|
||||
|
||||
this.request.setRequestURI("/path/");
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMap, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestWithParams() {
|
||||
public void retrieveAndUpdateMatchByParams() {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
flashMap.addTargetRequestParam("number", "one");
|
||||
@@ -116,19 +114,19 @@ public class AbstractFlashMapManagerTests {
|
||||
this.flashMapManager.setFlashMaps(flashMap);
|
||||
|
||||
this.request.setParameter("number", (String) null);
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertNull(inputFlashMap);
|
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());
|
||||
|
||||
this.request.setParameter("number", "two");
|
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertNull(inputFlashMap);
|
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());
|
||||
|
||||
this.request.setParameter("number", "one");
|
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMap, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
|
||||
@@ -137,7 +135,7 @@ public class AbstractFlashMapManagerTests {
|
||||
// SPR-8798
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestWithMultiValueParam() {
|
||||
public void retrieveAndUpdateMatchWithMultiValueParam() {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("name", "value");
|
||||
flashMap.addTargetRequestParam("id", "1");
|
||||
@@ -146,20 +144,20 @@ public class AbstractFlashMapManagerTests {
|
||||
this.flashMapManager.setFlashMaps(flashMap);
|
||||
|
||||
this.request.setParameter("id", "1");
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertNull(inputFlashMap);
|
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());
|
||||
|
||||
this.request.addParameter("id", "2");
|
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMap, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFlashMapForRequestSortOrder() {
|
||||
public void retrieveAndUpdateSortMultipleMatches() {
|
||||
FlashMap emptyFlashMap = new FlashMap();
|
||||
|
||||
FlashMap flashMapOne = new FlashMap();
|
||||
@@ -174,28 +172,44 @@ public class AbstractFlashMapManagerTests {
|
||||
this.flashMapManager.setFlashMaps(emptyFlashMap, flashMapOne, flashMapTwo);
|
||||
|
||||
this.request.setRequestURI("/one/two");
|
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request);
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals(flashMapTwo, inputFlashMap);
|
||||
assertEquals("Input FlashMap should have been removed", 2, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFlashMapEmpty() throws InterruptedException {
|
||||
public void retrieveAndUpdateRemoveExpired() throws InterruptedException {
|
||||
List<FlashMap> flashMaps = new ArrayList<FlashMap>();
|
||||
for (int i=0; i < 5; i++) {
|
||||
FlashMap expiredFlashMap = new FlashMap();
|
||||
expiredFlashMap.startExpirationPeriod(-1);
|
||||
flashMaps.add(expiredFlashMap);
|
||||
}
|
||||
this.flashMapManager.setFlashMaps(flashMaps);
|
||||
this.flashMapManager.retrieveAndUpdate(this.request, this.response);
|
||||
|
||||
assertEquals("Expired instances should be removed even if the saved FlashMap is empty",
|
||||
0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveOutputFlashMapEmpty() throws InterruptedException {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
List<FlashMap> allMaps = this.flashMapManager.getFlashMaps();
|
||||
|
||||
assertNull(allMaps);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFlashMap() throws InterruptedException {
|
||||
public void saveOutputFlashMap() throws InterruptedException {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("name", "value");
|
||||
|
||||
this.flashMapManager.setFlashMapTimeout(-1); // expire immediately so we can check expiration started
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
List<FlashMap> allMaps = this.flashMapManager.getFlashMaps();
|
||||
|
||||
assertNotNull(allMaps);
|
||||
@@ -204,67 +218,52 @@ public class AbstractFlashMapManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFlashMapDecodeTargetPath() throws InterruptedException {
|
||||
public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
|
||||
flashMap.setTargetRequestPath("/once%20upon%20a%20time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once upon a time", flashMap.getTargetRequestPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFlashMapNormalizeTargetPath() throws InterruptedException {
|
||||
public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.put("key", "value");
|
||||
|
||||
flashMap.setTargetRequestPath(".");
|
||||
this.request.setRequestURI("/once/upon/a/time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once/upon/a", flashMap.getTargetRequestPath());
|
||||
|
||||
flashMap.setTargetRequestPath("./");
|
||||
this.request.setRequestURI("/once/upon/a/time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once/upon/a/", flashMap.getTargetRequestPath());
|
||||
|
||||
flashMap.setTargetRequestPath("..");
|
||||
this.request.setRequestURI("/once/upon/a/time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once/upon", flashMap.getTargetRequestPath());
|
||||
|
||||
flashMap.setTargetRequestPath("../");
|
||||
this.request.setRequestURI("/once/upon/a/time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once/upon/", flashMap.getTargetRequestPath());
|
||||
|
||||
flashMap.setTargetRequestPath("../../only");
|
||||
this.request.setRequestURI("/once/upon/a/time");
|
||||
this.flashMapManager.save(flashMap, this.request, this.response);
|
||||
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
|
||||
|
||||
assertEquals("/once/only", flashMap.getTargetRequestPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFlashMapAndRemoveExpired() throws InterruptedException {
|
||||
List<FlashMap> flashMaps = new ArrayList<FlashMap>();
|
||||
for (int i=0; i < 5; i++) {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.startExpirationPeriod(-1);
|
||||
flashMaps.add(flashMap);
|
||||
}
|
||||
this.flashMapManager.setFlashMaps(flashMaps);
|
||||
this.flashMapManager.save(new FlashMap(), request, response);
|
||||
|
||||
assertEquals("Expired instances should be removed even if the saved FlashMap is empty",
|
||||
0, this.flashMapManager.getFlashMaps().size());
|
||||
}
|
||||
|
||||
|
||||
private static class TestFlashMapManager extends AbstractFlashMapManager {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -44,7 +44,6 @@ public class ServletUriComponentsBuilderTests {
|
||||
public void fromRequest() {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
request.setQueryString("foo=123");
|
||||
|
||||
String result = ServletUriComponentsBuilder.fromRequest(request).build().toUriString();
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase/data/param?foo=123", result);
|
||||
@@ -52,11 +51,10 @@ public class ServletUriComponentsBuilderTests {
|
||||
|
||||
@Test
|
||||
public void fromRequestEncodedPath() {
|
||||
request.setRequestURI("/mvc-showcase/data/foo%20bar;jsessionid=123");
|
||||
|
||||
request.setRequestURI("/mvc-showcase/data/foo%20bar");
|
||||
String result = ServletUriComponentsBuilder.fromRequest(request).build().toUriString();
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase/data/foo bar", result);
|
||||
assertEquals("http://localhost/mvc-showcase/data/foo%20bar", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,17 +69,24 @@ public class ServletUriComponentsBuilderTests {
|
||||
public void fromRequestAtypicalHttpsPort() {
|
||||
request.setScheme("https");
|
||||
request.setServerPort(9043);
|
||||
|
||||
String result = ServletUriComponentsBuilder.fromRequest(request).build().toUriString();
|
||||
|
||||
assertEquals("https://localhost:9043", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromRequestUri() {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
request.setQueryString("foo=123");
|
||||
String result = ServletUriComponentsBuilder.fromRequestUri(request).build().toUriString();
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase/data/param", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromContextPath() {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
request.setQueryString("foo=123");
|
||||
|
||||
String result = ServletUriComponentsBuilder.fromContextPath(request).build().toUriString();
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase", result);
|
||||
@@ -92,7 +97,6 @@ public class ServletUriComponentsBuilderTests {
|
||||
request.setRequestURI("/mvc-showcase/app/simple");
|
||||
request.setServletPath("/app");
|
||||
request.setQueryString("foo=123");
|
||||
|
||||
String result = ServletUriComponentsBuilder.fromServletMapping(request).build().toUriString();
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase/app", result);
|
||||
@@ -103,7 +107,6 @@ public class ServletUriComponentsBuilderTests {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
request.setQueryString("foo=123");
|
||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
|
||||
|
||||
try {
|
||||
String result = ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user