Browse Source

spr7766

pull/7/head
Keith Donald 14 years ago
parent
commit
da898faac9
  1. 20
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7766Controller.java
  2. 36
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7766Tests.java

20
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7766Controller.java

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
package org.springframework.web.servlet.mvc.annotation;
import java.awt.Color;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class Spr7766Controller {
@RequestMapping("/colors")
public void handler(@RequestParam List<Color> colors) {
Assert.isTrue(colors.size() == 2);
Assert.isTrue(colors.get(0).equals(Color.WHITE));
Assert.isTrue(colors.get(1).equals(Color.BLACK));
}
}

36
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7766Tests.java

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
package org.springframework.web.servlet.mvc.annotation;
import java.awt.Color;
import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
public class Spr7766Tests {
@Test
public void test() throws Exception {
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
GenericConversionService service = ConversionServiceFactory.createDefaultConversionService();
service.addConverter(new ColorConverter());
binder.setConversionService(service);
adapter.setWebBindingInitializer(binder);
Spr7766Controller controller = new Spr7766Controller();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/colors");
request.setPathInfo("/colors");
request.addParameter("colors", "#ffffff,000000");
MockHttpServletResponse response = new MockHttpServletResponse();
adapter.handle(request, response, controller);
}
public class ColorConverter implements Converter<String, Color> {
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
}
}
Loading…
Cancel
Save