Simplify form data handling in HttpRequestValues
Closes gh-29615
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.service.invoker;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -58,8 +58,9 @@ public class HttpRequestValuesTests {
|
||||
.build();
|
||||
|
||||
Object body = requestValues.getBodyValue();
|
||||
assertThat(body).isNotNull().isInstanceOf(byte[].class);
|
||||
assertThat(new String((byte[]) body, UTF_8)).isEqualTo("param1=1st+value¶m2=2nd+value+A¶m2=2nd+value+B");
|
||||
assertThat((MultiValueMap<String, String>) body).hasSize(2)
|
||||
.containsEntry("param1", List.of("1st value"))
|
||||
.containsEntry("param2", List.of("2nd value A", "2nd value B"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.web.service.invoker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -58,8 +60,10 @@ public class RequestParamArgumentResolverTests {
|
||||
this.service.postForm("value 1", "value 2");
|
||||
|
||||
Object body = this.client.getRequestValues().getBodyValue();
|
||||
assertThat(body).isNotNull().isInstanceOf(byte[].class);
|
||||
assertThat(new String((byte[]) body, UTF_8)).isEqualTo("param1=value+1¶m2=value+2");
|
||||
assertThat(body).isNotNull().isInstanceOf(MultiValueMap.class);
|
||||
assertThat((MultiValueMap<String, String>) body).hasSize(2)
|
||||
.containsEntry("param1", List.of("value 1"))
|
||||
.containsEntry("param2", List.of("value 2"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user