Add ServerRequest::multipartData in WebMvc.fn
This commit adds the multipartData method to ServerRequest in WebMvc.fn, returning a MultiValueMap<String, Part>. Closes gh-24909
This commit is contained in:
@@ -33,6 +33,7 @@ import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -53,6 +54,7 @@ import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
||||
import org.springframework.web.testfixture.servlet.MockHttpSession;
|
||||
import org.springframework.web.testfixture.servlet.MockPart;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -129,6 +131,25 @@ public class DefaultServerRequestTests {
|
||||
assertThat(request.param("foo")).isEqualTo(Optional.of("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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 = new MockHttpServletRequest("POST", "/");
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyQueryParam() {
|
||||
MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/");
|
||||
|
||||
Reference in New Issue
Block a user