use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePartNotAnnot.
@Test
public void resolvePartNotAnnot() throws Exception {
MockPart expected = new MockPart("part", "Hello World".getBytes());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
boolean condition = result instanceof Part;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePartListMissing.
@Test
public void resolvePartListMissing() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
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);
assertThatExceptionOfType(MissingServletRequestPartException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null));
}
use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePartArrayMissing.
@Test
public void resolvePartArrayMissing() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(new MockPart("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
assertThatExceptionOfType(MissingServletRequestPartException.class).isThrownBy(() -> resolver.resolveArgument(param, null, webRequest, null));
}
use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class StandardMultipartHttpServletRequestTests method requestWithPart.
private StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
MockHttpServletRequest request = new MockHttpServletRequest();
MockPart part = new MockPart(name, null, content.getBytes(StandardCharsets.UTF_8));
part.getHeaders().set("Content-Disposition", disposition);
request.addPart(part);
return new StandardMultipartHttpServletRequest(request);
}
use of org.springframework.web.testfixture.servlet.MockPart in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalPartArgument.
@Test
public void resolveOptionalPartArgument() throws Exception {
MockPart expected = new MockPart("optionalPart", "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(optionalPart, null, webRequest, null);
boolean condition1 = actualValue instanceof Optional;
assertThat(condition1).isTrue();
assertThat(((Optional<?>) actualValue).get()).as("Invalid result").isEqualTo(expected);
actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertThat(actualValue instanceof Optional).isTrue();
assertThat(((Optional<?>) actualValue).get()).as("Invalid result").isEqualTo(expected);
}
Aggregations