use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePartList.
@Test
public void resolvePartList() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
MockPart expected1 = new MockPart("pfilelist", "Hello World 1".getBytes());
MockPart expected2 = new MockPart("pfilelist", "Hello World 2".getBytes());
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(List.class, Part.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
boolean condition = result instanceof List;
assertThat(condition).isTrue();
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
}
use of org.springframework.web.testfixture.servlet.MockPart 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);
boolean condition = result instanceof Part[];
assertThat(condition).isTrue();
Part[] parts = (Part[]) result;
assertThat(parts.length).isEqualTo(2);
assertThat(expected1).isEqualTo(parts[0]);
assertThat(expected2).isEqualTo(parts[1]);
}
use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class DefaultServerRequestTests method multipartData.
@Test
void multipartData() throws Exception {
MockPart formPart = new MockPart("form", "foo".getBytes(UTF_8));
MockPart filePart = new MockPart("file", "foo.txt", "foo".getBytes(UTF_8));
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("POST", "/", true);
servletRequest.addPart(formPart);
servletRequest.addPart(filePart);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
MultiValueMap<String, Part> result = request.multipartData();
assertThat(result).hasSize(2);
assertThat(result.get("form")).containsExactly(formPart);
assertThat(result.get("file")).containsExactly(filePart);
}
Aggregations