use of org.springframework.web.testfixture.servlet.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("https://example.com/path?query");
this.mockRequest.setScheme(uri.getScheme());
this.mockRequest.setServerName(uri.getHost());
this.mockRequest.setServerPort(uri.getPort());
this.mockRequest.setRequestURI(uri.getPath());
this.mockRequest.setQueryString(uri.getQuery());
assertThat(request.getURI()).isEqualTo(uri);
}
use of org.springframework.web.testfixture.servlet.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileArrayMissing.
@Test
public void resolveMultipartFileArrayMissing() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
assertThatExceptionOfType(MissingServletRequestPartException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null));
}
use of org.springframework.web.testfixture.servlet.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileListMissing.
@Test
public void resolveMultipartFileListMissing() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
assertThatExceptionOfType(MissingServletRequestPartException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null));
}
use of org.springframework.web.testfixture.servlet.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);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.web.testfixture.servlet.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);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
Aggregations