use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalPartArgumentWithoutMultipartRequest.
@Test
public void resolveOptionalPartArgumentWithoutMultipartRequest() throws Exception {
webRequest = new ServletWebRequest(new MockHttpServletRequest());
Object actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method isMultipartRequest.
@Test(expected = MultipartException.class)
public void isMultipartRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
resolver.resolveArgument(paramMultipartFile, new ModelAndViewContainer(), new ServletWebRequest(request), null);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolvePartListArgument.
@Test
public void resolvePartListArgument() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
request.addPart(part1);
request.addPart(part2);
request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
webRequest = new ServletWebRequest(request);
Object result = resolver.resolveArgument(paramPartList, null, webRequest, null);
assertTrue(result instanceof List);
assertEquals(Arrays.asList(part1, part2), result);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalMultipartFileArgumentNotPresent.
@Test
public void resolveOptionalMultipartFileArgumentNotPresent() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
webRequest = new ServletWebRequest(request);
Object actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalPartList.
@Test
public void resolveOptionalPartList() throws Exception {
MockPart expected = new MockPart("requestPart", "Hello World".getBytes());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(expected);
request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
webRequest = new ServletWebRequest(request);
Object actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
assertTrue(actualValue instanceof Optional);
assertEquals("Invalid result", Collections.singletonList(expected), ((Optional) actualValue).get());
}
Aggregations