use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFileAsString.
@Test
public void testMultipartFileAsString() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("name", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals("Juergen", target.getName());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testBindingWithNestedObjectCreation.
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
TestBean tb = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person");
binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean());
}
});
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("spouse", "someValue");
request.addParameter("spouse.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 testFieldDefaultPreemptsFieldMarker.
@Test
public void testFieldDefaultPreemptsFieldMarker() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!postProcessed", "on");
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(new ServletWebRequest(request));
assertTrue(target.isPostProcessed());
request.removeParameter("postProcessed");
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 ModelFactoryOrderingTests method setup.
@Before
public void setup() {
this.sessionAttributeStore = new DefaultSessionAttributeStore();
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
this.mavContainer = new ModelAndViewContainer();
this.mavContainer.addAttribute("methods", new ArrayList<String>());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class ModelFactoryTests method setUp.
@Before
public void setUp() throws Exception {
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
this.attributeStore = new DefaultSessionAttributeStore();
this.attributeHandler = new SessionAttributesHandler(TestController.class, this.attributeStore);
this.controller = new TestController();
this.mavContainer = new ModelAndViewContainer();
}
Aggregations