use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFileAsStringArray.
@Test
public void testMultipartFileAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals(1, target.getStringArray().length);
assertEquals("Juergen", target.getStringArray()[0]);
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getURI.
@Test
public void getURI() throws Exception {
this.mockRequest.addFile(new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8")));
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
URI uri = new URI("http://example.com/path?query");
this.mockRequest.setServerName(uri.getHost());
this.mockRequest.setServerPort(uri.getPort());
this.mockRequest.setRequestURI(uri.getPath());
this.mockRequest.setQueryString(uri.getQuery());
assertEquals(uri, request.getURI());
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileNotAnnot.
@Test
public void resolveMultipartFileNotAnnot() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof MultipartFile);
assertEquals("Invalid result", expected, result);
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFile.
@Test
public void resolveMultipartFile() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
request.addFile(expected);
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);
assertEquals("Invalid result", expected, result);
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getMethod.
@Test
public void getMethod() throws Exception {
this.mockRequest.addFile(new MockMultipartFile("part", "", "", "content".getBytes("UTF-8")));
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
this.mockRequest.setMethod("POST");
assertEquals(HttpMethod.POST, request.getMethod());
}
Aggregations