use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method setUp.
@Before
public void setUp() throws Exception {
this.request = new ServletWebRequest(new MockHttpServletRequest());
this.container = new ModelAndViewContainer();
this.processor = new ModelAttributeMethodProcessor(false);
Method method = ModelAttributeHandler.class.getDeclaredMethod("modelAttribute", TestBean.class, Errors.class, int.class, TestBean.class, TestBean.class, TestBean.class);
this.paramNamedValidModelAttr = new SynthesizingMethodParameter(method, 0);
this.paramErrors = new SynthesizingMethodParameter(method, 1);
this.paramInt = new SynthesizingMethodParameter(method, 2);
this.paramModelAttr = new SynthesizingMethodParameter(method, 3);
this.paramBindingDisabledAttr = new SynthesizingMethodParameter(method, 4);
this.paramNonSimpleType = new SynthesizingMethodParameter(method, 5);
method = getClass().getDeclaredMethod("annotatedReturnValue");
this.returnParamNamedModelAttr = new MethodParameter(method, -1);
method = getClass().getDeclaredMethod("notAnnotatedReturnValue");
this.returnParamNonSimpleType = new MethodParameter(method, -1);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method isMultipartRequestHttpPut.
// SPR-9079
@Test
public void isMultipartRequestHttpPut() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes());
request.addFile(expected);
request.setMethod("PUT");
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(actual instanceof List);
assertEquals(expected, ((List<?>) actual).get(0));
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileArray.
@Test
public void resolveMultipartFileArray() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes());
request.addFile(expected1);
request.addFile(expected2);
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof MultipartFile[]);
MultipartFile[] parts = (MultipartFile[]) result;
assertEquals(2, parts.length);
assertEquals(parts[0], expected1);
assertEquals(parts[1], expected2);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileListNotannot.
@Test
public void resolveMultipartFileListNotannot() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("multipartFileList", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("multipartFileList", "Hello World 2".getBytes());
request.addFile(expected1);
request.addFile(expected2);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof List);
assertEquals(Arrays.asList(expected1, expected2), result);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePartArray.
@Test
public void resolvePartArray() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockPart expected1 = new MockPart("pfilearray", "Hello World 1".getBytes());
MockPart expected2 = new MockPart("pfilearray", "Hello World 2".getBytes());
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(expected1);
request.addPart(expected2);
request.addPart(new MockPart("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof Part[]);
Part[] parts = (Part[]) result;
assertEquals(2, parts.length);
assertEquals(parts[0], expected1);
assertEquals(parts[1], expected2);
}
Aggregations