|
|
|
@ -2,11 +2,13 @@ package org.springframework.web.servlet.mvc.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Ignore; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
import org.springframework.core.convert.converter.Converter; |
|
|
|
import org.springframework.core.convert.support.ConversionServiceFactory; |
|
|
|
import org.springframework.core.convert.support.ConversionServiceFactory; |
|
|
|
import org.springframework.core.convert.support.GenericConversionService; |
|
|
|
import org.springframework.core.convert.support.GenericConversionService; |
|
|
|
import org.springframework.mock.web.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.MockHttpServletRequest; |
|
|
|
@ -17,30 +19,78 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; |
|
|
|
|
|
|
|
|
|
|
|
public class Spr7839Tests { |
|
|
|
public class Spr7839Tests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter(); |
|
|
|
@Ignore |
|
|
|
|
|
|
|
public void test() throws Exception { |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter(); |
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spr7839Controller controller = new Spr7839Controller(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
|
|
public void setUp() { |
|
|
|
ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer(); |
|
|
|
ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer(); |
|
|
|
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService(); |
|
|
|
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService(); |
|
|
|
|
|
|
|
service.addConverter(new Converter<String, NestedBean>() { |
|
|
|
|
|
|
|
public NestedBean convert(String source) { |
|
|
|
|
|
|
|
return new NestedBean(source); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
binder.setConversionService(service); |
|
|
|
binder.setConversionService(service); |
|
|
|
adapter.setWebBindingInitializer(binder); |
|
|
|
adapter.setWebBindingInitializer(binder); |
|
|
|
Spr7839Controller controller = new Spr7839Controller(); |
|
|
|
} |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void object() throws Exception { |
|
|
|
request.setRequestURI("/nested"); |
|
|
|
request.setRequestURI("/nested"); |
|
|
|
request.setPathInfo("/nested"); |
|
|
|
request.addParameter("nested", "Nested"); |
|
|
|
request.addParameter("nested.map['apple'].foo", "bar"); |
|
|
|
adapter.handle(request, response, controller); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void list() throws Exception { |
|
|
|
|
|
|
|
request.setRequestURI("/nested/list"); |
|
|
|
|
|
|
|
request.addParameter("nested.list", "Nested1,Nested2"); |
|
|
|
adapter.handle(request, response, controller); |
|
|
|
adapter.handle(request, response, controller); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void listElement() throws Exception { |
|
|
|
|
|
|
|
request.setRequestURI("/nested/listElement"); |
|
|
|
|
|
|
|
request.addParameter("nested.list[0]", "Nested"); |
|
|
|
|
|
|
|
adapter.handle(request, response, controller); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void map() throws Exception { |
|
|
|
|
|
|
|
request.setRequestURI("/nested/map"); |
|
|
|
|
|
|
|
request.addParameter("nested.map['apple'].foo", "bar"); |
|
|
|
|
|
|
|
adapter.handle(request, response, controller); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
public static class Spr7839Controller { |
|
|
|
public static class Spr7839Controller { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/nested") |
|
|
|
@RequestMapping("/nested") |
|
|
|
public void handler(JavaBean bean) { |
|
|
|
public void handler(JavaBean bean) { |
|
|
|
|
|
|
|
assertEquals("Nested", bean.nested.foo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/nested/list") |
|
|
|
|
|
|
|
public void handlerList(JavaBean bean) { |
|
|
|
|
|
|
|
assertEquals("Nested2", bean.nested.list.get(1).foo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/nested/map") |
|
|
|
|
|
|
|
public void handlerMap(JavaBean bean) { |
|
|
|
assertEquals("bar", bean.nested.map.get("apple").foo); |
|
|
|
assertEquals("bar", bean.nested.map.get("apple").foo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/nested/listElement") |
|
|
|
|
|
|
|
public void handlerListElement(JavaBean bean) { |
|
|
|
|
|
|
|
assertEquals("Nested", bean.nested.list.get(0).foo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static class JavaBean { |
|
|
|
public static class JavaBean { |
|
|
|
@ -64,8 +114,16 @@ public class Spr7839Tests { |
|
|
|
|
|
|
|
|
|
|
|
private List<NestedBean> list; |
|
|
|
private List<NestedBean> list; |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, NestedBean> map; |
|
|
|
private Map<String, NestedBean> map = new HashMap<String, NestedBean>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NestedBean() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NestedBean(String foo) { |
|
|
|
|
|
|
|
this.foo = foo; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getFoo() { |
|
|
|
public String getFoo() { |
|
|
|
return foo; |
|
|
|
return foo; |
|
|
|
} |
|
|
|
} |
|
|
|
|