Search in sources :

Example 1 with ServletRequestParameterPropertyValues

use of org.springframework.web.bind.ServletRequestParameterPropertyValues in project spring-framework by spring-projects.

the class WebRequestDataBinderTests method testPrefix.

@Test
public void testPrefix() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("test_forname", "Tony");
    request.addParameter("test_surname", "Blair");
    request.addParameter("test_age", "" + 50);
    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    assertTrue("Didn't fidn normal when given prefix", !pvs.contains("forname"));
    assertTrue("Did treat prefix as normal when not given prefix", pvs.contains("test_forname"));
    pvs = new ServletRequestParameterPropertyValues(request, "test");
    doTestTony(pvs);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletRequestParameterPropertyValues(org.springframework.web.bind.ServletRequestParameterPropertyValues) Test(org.junit.Test)

Example 2 with ServletRequestParameterPropertyValues

use of org.springframework.web.bind.ServletRequestParameterPropertyValues 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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletRequestParameterPropertyValues(org.springframework.web.bind.ServletRequestParameterPropertyValues) Test(org.junit.Test)

Example 3 with ServletRequestParameterPropertyValues

use of org.springframework.web.bind.ServletRequestParameterPropertyValues in project spring-framework by spring-projects.

the class WebRequestDataBinderTests method testMultipleValuesForParameter.

@Test
public void testMultipleValuesForParameter() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    String[] original = new String[] { "Tony", "Rod" };
    request.addParameter("forname", original);
    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
    assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
    String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
    assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletRequestParameterPropertyValues(org.springframework.web.bind.ServletRequestParameterPropertyValues) Test(org.junit.Test)

Example 4 with ServletRequestParameterPropertyValues

use of org.springframework.web.bind.ServletRequestParameterPropertyValues in project spring-framework by spring-projects.

the class WebRequestDataBinderTests method testNoPrefix.

@Test
public void testNoPrefix() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("forname", "Tony");
    request.addParameter("surname", "Blair");
    request.addParameter("age", "" + 50);
    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    doTestTony(pvs);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletRequestParameterPropertyValues(org.springframework.web.bind.ServletRequestParameterPropertyValues) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 ServletRequestParameterPropertyValues (org.springframework.web.bind.ServletRequestParameterPropertyValues)4