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:
Chris Beams
2012-02-13 15:17:30 +01:00
134 changed files with 3552 additions and 1471 deletions

View File

@@ -1,11 +1,11 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,6 +17,7 @@
package org.springframework.http.server;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.List;
import org.junit.Before;
@@ -24,6 +25,7 @@ import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.util.FileCopyUtils;
@@ -67,6 +69,8 @@ public class ServletServerHttpRequestTests {
mockRequest.addHeader(headerName, headerValue1);
String headerValue2 = "value2";
mockRequest.addHeader(headerName, headerValue2);
mockRequest.setContentType("text/plain");
mockRequest.setCharacterEncoding("UTF-8");
HttpHeaders headers = request.getHeaders();
assertNotNull("No HttpHeaders returned", headers);
@@ -75,6 +79,8 @@ public class ServletServerHttpRequestTests {
assertEquals("Invalid header values returned", 2, headerValues.size());
assertTrue("Invalid header values returned", headerValues.contains(headerValue1));
assertTrue("Invalid header values returned", headerValues.contains(headerValue2));
assertEquals("Invalid Content-Type", new MediaType("text", "plain", Charset.forName("UTF-8")),
headers.getContentType());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 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.
@@ -16,16 +16,19 @@
package org.springframework.http.server;
import java.nio.charset.Charset;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
@@ -56,12 +59,16 @@ public class ServletServerHttpResponseTests {
headers.add(headerName, headerValue1);
String headerValue2 = "value2";
headers.add(headerName, headerValue2);
headers.setContentType(new MediaType("text", "plain", Charset.forName("UTF-8")));
response.close();
assertTrue("Header not set", mockResponse.getHeaderNames().contains(headerName));
List headerValues = mockResponse.getHeaders(headerName);
assertTrue("Header not set", headerValues.contains(headerValue1));
assertTrue("Header not set", headerValues.contains(headerValue2));
assertEquals("Invalid Content-Type", "text/plain;charset=UTF-8", mockResponse.getHeader("Content-Type"));
assertEquals("Invalid Content-Type", "text/plain;charset=UTF-8", mockResponse.getContentType());
assertEquals("Invalid Content-Type", "UTF-8", mockResponse.getCharacterEncoding());
}
@Test

View File

@@ -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.
@@ -45,7 +45,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartFile;
@@ -183,11 +182,27 @@ public class RequestParamMethodArgumentResolverTests {
}
@Test(expected = MultipartException.class)
public void notMultipartRequest() throws Exception {
public void isMultipartRequest() throws Exception {
resolver.resolveArgument(paramMultiPartFile, null, webRequest, null);
fail("Expected exception: request is not a multipart request");
}
// SPR-9079
@Test
public void isMultipartRequestHttpPut() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes());
request.addFile(expected);
request.setMethod("PUT");
webRequest = new ServletWebRequest(request);
Object actual = resolver.resolveArgument(paramMultipartFileList, null, webRequest, null);
assertTrue(actual instanceof List);
assertEquals(expected, ((List<?>) actual).get(0));
}
@Test(expected = IllegalArgumentException.class)
public void missingMultipartFile() throws Exception {
request.setMethod("POST");

View File

@@ -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.
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
@@ -39,17 +38,17 @@ import org.springframework.web.context.request.ServletWebRequest;
/**
* Test fixture with {@link SessionAttributesHandler}.
*
*
* @author Rossen Stoyanchev
*/
public class SessionAttributesHandlerTests {
private Class<?> handlerType = SessionAttributeHandler.class;
private SessionAttributesHandler sessionAttributesHandler;
private SessionAttributeStore sessionAttributeStore;
private NativeWebRequest request;
@Before
@@ -58,7 +57,7 @@ public class SessionAttributesHandlerTests {
this.sessionAttributesHandler = new SessionAttributesHandler(handlerType, sessionAttributeStore);
this.request = new ServletWebRequest(new MockHttpServletRequest());
}
@Test
public void isSessionAttribute() throws Exception {
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", null));
@@ -72,14 +71,18 @@ public class SessionAttributesHandlerTests {
sessionAttributeStore.storeAttribute(request, "attr1", "value1");
sessionAttributeStore.storeAttribute(request, "attr2", "value2");
sessionAttributeStore.storeAttribute(request, "attr3", new TestBean());
sessionAttributeStore.storeAttribute(request, "attr4", new TestBean());
// Resolve successfully handler session attributes once
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class));
assertEquals("Named attributes (attr1, attr2) should be 'known' right away",
new HashSet<String>(asList("attr1", "attr2")),
sessionAttributesHandler.retrieveAttributes(request).keySet());
Map<String, ?> attributes = sessionAttributesHandler.retrieveAttributes(request);
// Resolve 'attr3' by type
sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class);
assertEquals(new HashSet<String>(asList("attr1", "attr3")), attributes.keySet());
assertEquals("Named attributes (attr1, attr2) and resolved attribute (att3) should be 'known'",
new HashSet<String>(asList("attr1", "attr2", "attr3")),
sessionAttributesHandler.retrieveAttributes(request).keySet());
}
@Test
@@ -88,14 +91,16 @@ public class SessionAttributesHandlerTests {
sessionAttributeStore.storeAttribute(request, "attr2", "value2");
sessionAttributeStore.storeAttribute(request, "attr3", new TestBean());
// Resolve successfully handler session attributes once
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class));
sessionAttributesHandler.cleanupAttributes(request);
assertNull(sessionAttributeStore.retrieveAttribute(request, "attr1"));
assertNotNull(sessionAttributeStore.retrieveAttribute(request, "attr2"));
assertNull(sessionAttributeStore.retrieveAttribute(request, "attr2"));
assertNotNull(sessionAttributeStore.retrieveAttribute(request, "attr3"));
// Resolve 'attr3' by type
sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class);
sessionAttributesHandler.cleanupAttributes(request);
assertNull(sessionAttributeStore.retrieveAttribute(request, "attr3"));
}
@@ -105,19 +110,14 @@ public class SessionAttributesHandlerTests {
model.put("attr1", "value1");
model.put("attr2", "value2");
model.put("attr3", new TestBean());
// Resolve successfully handler session attributes once
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr2", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class));
sessionAttributesHandler.storeAttributes(request, model);
assertEquals("value1", sessionAttributeStore.retrieveAttribute(request, "attr1"));
assertEquals("value2", sessionAttributeStore.retrieveAttribute(request, "attr2"));
assertTrue(sessionAttributeStore.retrieveAttribute(request, "attr3") instanceof TestBean);
}
@SessionAttributes(value = { "attr1", "attr2" }, types = { TestBean.class })
private static class SessionAttributeHandler {
}

View File

@@ -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.
@@ -45,7 +45,7 @@ public class UriComponentsBuilderTests {
URI expected = new URI("http://example.com/foo?bar#baz");
assertEquals("Invalid result URI", expected, result.toUri());
}
@Test
public void fromPath() throws URISyntaxException {
UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build();
@@ -176,6 +176,15 @@ public class UriComponentsBuilderTests {
assertEquals(Arrays.asList("foo"), result.getPathSegments());
}
@Test
public void pathSegmentsSomeEmpty() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("", "foo", "", "bar");
UriComponents result = builder.build();
assertEquals("/foo/bar", result.getPath());
assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments());
}
@Test
public void replacePath() {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://www.ietf.org/rfc/rfc2396.txt");
@@ -183,26 +192,26 @@ public class UriComponentsBuilderTests {
UriComponents result = builder.build();
assertEquals("http://www.ietf.org/rfc/rfc3986.txt", result.toUriString());
builder = UriComponentsBuilder.fromUriString("http://www.ietf.org/rfc/rfc2396.txt");
builder.replacePath(null);
result = builder.build();
assertEquals("http://www.ietf.org", result.toUriString());
}
@Test
public void replaceQuery() {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.com/foo?foo=bar&baz=qux");
builder.replaceQuery("baz=42");
UriComponents result = builder.build();
assertEquals("http://example.com/foo?baz=42", result.toUriString());
builder = UriComponentsBuilder.fromUriString("http://example.com/foo?foo=bar&baz=qux");
builder.replaceQuery(null);
result = builder.build();
assertEquals("http://example.com/foo", result.toUriString());
}
@@ -234,13 +243,13 @@ public class UriComponentsBuilderTests {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42);
builder.replaceQueryParam("baz", "xuq", 24);
UriComponents result = builder.build();
assertEquals("baz=xuq&baz=24", result.getQuery());
builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42);
builder.replaceQueryParam("baz");
result = builder.build();
assertNull("Query param should have been deleted", result.getQuery());
}

View File

@@ -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.
@@ -69,4 +69,10 @@ public class UriComponentsTests {
UriComponentsBuilder.fromPath("/fo%2o").build(true);
}
@Test
public void normalize() {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo/../bar").build();
assertEquals("http://example.com/bar", uriComponents.normalize().toString());
}
}

View File

@@ -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.
@@ -89,6 +89,15 @@ public class UriTemplateTests {
assertEquals("Invalid expanded template", new URI("http://example.com/hotel%20list/Z%C3%BCrich"), result);
}
@Test(expected = IllegalArgumentException.class)
public void expandMapUnboundVariables() throws Exception {
Map<String, String> uriVariables = new HashMap<String, String>(2);
uriVariables.put("booking", "42");
uriVariables.put("bar", "1");
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
template.expand(uriVariables);
}
@Test
public void expandEncoded() throws Exception {
UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}");