use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method assertContentDisposition.
private void assertContentDisposition(RequestResponseBodyMethodProcessor processor, boolean expectContentDisposition, String requestURI, String comment) throws Exception {
this.servletRequest.setRequestURI(requestURI);
processor.handleReturnValue("body", this.returnTypeString, this.container, this.request);
String header = servletResponse.getHeader("Content-Disposition");
if (expectContentDisposition) {
assertThat(header).as("Expected 'Content-Disposition' header. Use case: '" + comment + "'").isEqualTo("inline;filename=f.txt");
} else {
assertThat(header).as("Did not expect 'Content-Disposition' header. Use case: '" + comment + "'").isNull();
}
this.servletRequest = new MockHttpServletRequest();
this.servletResponse = new MockHttpServletResponse();
this.request = new ServletWebRequest(servletRequest, servletResponse);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class ReactiveTypeHandlerTests method resetRequest.
private void resetRequest() {
this.servletRequest = new MockHttpServletRequest();
this.servletResponse = new MockHttpServletResponse();
this.webRequest = new ServletWebRequest(this.servletRequest, this.servletResponse);
AsyncWebRequest webRequest = new StandardServletAsyncWebRequest(this.servletRequest, this.servletResponse);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(webRequest);
this.servletRequest.setAsyncSupported(true);
}
use of org.springframework.web.context.request.ServletWebRequest 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.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalPartArgumentNotPresent.
@Test
public void resolveOptionalPartArgumentNotPresent() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
webRequest = new ServletWebRequest(request);
Object actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertThat(actualValue).as("Invalid argument value").isEqualTo(Optional.empty());
actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
assertThat(actualValue).as("Invalid argument value").isEqualTo(Optional.empty());
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolvePartArrayArgument.
@Test
public void resolvePartArrayArgument() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
request.addPart(part1);
request.addPart(part2);
request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
webRequest = new ServletWebRequest(request);
Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
assertThat(result instanceof Part[]).isTrue();
Part[] parts = (Part[]) result;
assertThat(parts.length).isEqualTo(2);
assertThat(part1).isEqualTo(parts[0]);
assertThat(part2).isEqualTo(parts[1]);
}
Aggregations