added further conversion tests (triggered by 3.0.6 backports)

This commit is contained in:
Juergen Hoeller
2011-06-13 23:43:46 +00:00
parent 90c3d04958
commit 6c3cc786d0
2 changed files with 80 additions and 10 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.
@@ -1817,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) {
@@ -1844,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());
}
@Test
public void testMatchWithoutMethodLevelPath() throws Exception {
initServlet(NoPathGetAndM2PostController.class);
@@ -3114,6 +3142,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, "-"));
}
}
@Controller
@@ -3130,6 +3164,4 @@ public class ServletAnnotationControllerTests {
}
}
}