use of org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method multipartFilesAsStringArray.
@PathPatternsParameterizedTest
void multipartFilesAsStringArray(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MultipartController.class, usePathPatterns);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.setRequestURI("/stringArray");
request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
request.addFile(new MockMultipartFile("content", "Eva".getBytes()));
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("Juergen-Eva");
}
use of org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method multipartFileAsStringArray.
@PathPatternsParameterizedTest
void multipartFileAsStringArray(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MultipartController.class, usePathPatterns);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.setRequestURI("/stringArray");
request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("Juergen");
}
use of org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithMultipartFile.
@PathPatternsParameterizedTest
void dataClassBindingWithMultipartFile(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MultipartFileDataClassController.class, usePathPatterns);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.setRequestURI("/bind");
request.addFile(new MockMultipartFile("param1", "value1".getBytes(StandardCharsets.UTF_8)));
request.addParameter("param2", "true");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("value1-true-0");
}
use of org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalMultipartFileList.
@Test
public void resolveOptionalMultipartFileList() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("requestPart", "Hello World".getBytes());
request.addFile(expected);
request.addFile(new MockMultipartFile("otherPart", "", "text/plain", "Hello World".getBytes()));
webRequest = new ServletWebRequest(request);
Object actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
boolean condition1 = actualValue instanceof Optional;
assertThat(condition1).isTrue();
assertThat(((Optional<?>) actualValue).get()).as("Invalid result").isEqualTo(Collections.singletonList(expected));
actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
assertThat(actualValue instanceof Optional).isTrue();
assertThat(((Optional<?>) actualValue).get()).as("Invalid result").isEqualTo(Collections.singletonList(expected));
}
use of org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterIntegrationTests method handleAndValidateRequestPart.
@Test
public void handleAndValidateRequestPart() throws Exception {
MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest();
multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8")));
HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestPart", String.class, Errors.class, Model.class);
ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod);
assertThat(mav).isNotNull();
assertThat(mav.getModelMap().get("error count")).isEqualTo(1);
}
Aggregations