use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testNoParameters.
@Test
public void testNoParameters() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertTrue("Found no parameters", pvs.getPropertyValues().length == 0);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testFieldDefaultPreemptsFieldMarker.
@Test
public void testFieldDefaultPreemptsFieldMarker() throws Exception {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!postProcessed", "on");
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(request);
assertTrue(target.isPostProcessed());
request.removeParameter("postProcessed");
binder.bind(request);
assertTrue(target.isPostProcessed());
request.removeParameter("!postProcessed");
binder.bind(request);
assertFalse(target.isPostProcessed());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testFieldDefaultNonBoolean.
@Test
public void testFieldDefaultNonBoolean() throws Exception {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!name", "anonymous");
request.addParameter("name", "Scott");
binder.bind(request);
assertEquals("Scott", target.getName());
request.removeParameter("name");
binder.bind(request);
assertEquals("anonymous", target.getName());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testBindingWithNestedObjectCreation.
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
TestBean tb = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(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(request);
assertNotNull(tb.getSpouse());
assertEquals("test", tb.getSpouse().getName());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ServletRequestUtilsTests method testDoubleParameters.
@Test
public void testDoubleParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param", new String[] { "1.5", "2.5", "3" });
request.addParameter("param2", "1.5");
request.addParameter("param2", "2");
request.addParameter("param2", "bogus");
double[] array = new double[] { 1.5, 2.5, 3 };
double[] values = ServletRequestUtils.getRequiredDoubleParameters(request, "param");
assertEquals(3, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i], 0);
}
try {
ServletRequestUtils.getRequiredDoubleParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
} catch (ServletRequestBindingException ex) {
// expected
}
}
Aggregations