use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFilesAsStringArray.
@Test
public void testMultipartFilesAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
request.addFile(new MockMultipartFile("stringArray", "Eva".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals(2, target.getStringArray().length);
assertEquals("Juergen", target.getStringArray()[0]);
assertEquals("Eva", target.getStringArray()[1]);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testBindingWithNestedObjectCreationThroughAutoGrow.
@Test
public void testBindingWithNestedObjectCreationThroughAutoGrow() throws Exception {
TestBean tb = new TestBeanWithConcreteSpouse();
WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person");
binder.setIgnoreUnknownFields(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("concreteSpouse.name", "test");
binder.bind(new ServletWebRequest(request));
assertNotNull(tb.getSpouse());
assertEquals("test", tb.getSpouse().getName());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testFieldDefaultNonBoolean.
@Test
public void testFieldDefaultNonBoolean() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!name", "anonymous");
request.addParameter("name", "Scott");
binder.bind(new ServletWebRequest(request));
assertEquals("Scott", target.getName());
request.removeParameter("name");
binder.bind(new ServletWebRequest(request));
assertEquals("anonymous", target.getName());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testFieldPrefixCausesFieldReset.
@Test
public void testFieldPrefixCausesFieldReset() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(new ServletWebRequest(request));
assertTrue(target.isPostProcessed());
request.removeParameter("postProcessed");
binder.bind(new ServletWebRequest(request));
assertFalse(target.isPostProcessed());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testFieldDefault.
@Test
public void testFieldDefault() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!postProcessed", "off");
request.addParameter("postProcessed", "on");
binder.bind(new ServletWebRequest(request));
assertTrue(target.isPostProcessed());
request.removeParameter("postProcessed");
binder.bind(new ServletWebRequest(request));
assertFalse(target.isPostProcessed());
}
Aggregations