restored original GenericConversionService behavior with respect to empty collections/maps; restored original FormattingConversionService behavior with respect to the use of subtypes; fixed collection element resolution when using a ConversionService with a DataBinder

This commit is contained in:
Juergen Hoeller
2011-06-13 23:40:22 +00:00
parent 6cb6bd751e
commit 43f8eca91b
4 changed files with 109 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -50,7 +50,6 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
@@ -134,6 +133,8 @@ import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMap
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.util.NestedServletException;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @author Sam Brannen
@@ -1156,6 +1157,7 @@ public class ServletAnnotationControllerTests {
MockHttpServletResponse response = new MockHttpServletResponse();
try {
servlet.service(request, response);
fail("Didn't fail with due to ambiguous method mapping");
}
catch (NestedServletException ex) {
assertTrue(ex.getCause() instanceof IllegalStateException);
@@ -1815,7 +1817,7 @@ public class ServletAnnotationControllerTests {
}
@Test
public void parameterCsvAsStringArray() throws Exception {
public void parameterCsvAsIntegerArray() throws Exception {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
@@ -1842,6 +1844,34 @@ public class ServletAnnotationControllerTests {
assertEquals("1-2", response.getContentAsString());
}
@Test
public void parameterCsvAsIntegerSet() throws Exception {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(CsvController.class));
RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
wbiDef.getPropertyValues().add("conversionService", csDef);
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/integerSet");
request.setMethod("POST");
request.addParameter("content", "1,2");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("1-2", response.getContentAsString());
}
/*
* Controllers
@@ -3102,6 +3132,12 @@ public class ServletAnnotationControllerTests {
public void processCsv(@RequestParam("content") Integer[] content, HttpServletResponse response) throws IOException {
response.getWriter().write(StringUtils.arrayToDelimitedString(content, "-"));
}
@RequestMapping("/integerSet")
public void processCsv(@RequestParam("content") Set<Integer> content, HttpServletResponse response) throws IOException {
assertTrue(content.iterator().next() instanceof Integer);
response.getWriter().write(StringUtils.collectionToDelimitedString(content, "-"));
}
}
}