This commit is contained in:
Arjen Poutsma
2024-05-16 11:51:36 +02:00
parent fa275f908e
commit 14861024d5
5 changed files with 111 additions and 40 deletions

View File

@@ -117,13 +117,14 @@ class FormHttpMessageConverterTests {
assertCanWrite(MULTIPART_RELATED);
}
@SuppressWarnings("unchecked")
@Test
void readForm() throws Exception {
void readMultiValueForm() throws Exception {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
inputMessage.getHeaders().setContentType(
new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
MultiValueMap<String, String> result = (MultiValueMap<String, String>) this.converter.read(null, inputMessage);
assertThat(result).as("Invalid result").hasSize(3);
assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
@@ -132,6 +133,21 @@ class FormHttpMessageConverterTests {
assertThat(result.getFirst("name 3")).as("Invalid result").isNull();
}
@SuppressWarnings("unchecked")
@Test
void readSingleValueForm() throws Exception {
String body = "name+1=value+1&name+2=value+2&name+3";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
inputMessage.getHeaders().setContentType(
new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
Map<String, String> result = (Map<String, String>) this.converter.read((Class<? extends Map<String, ?>>) Map.class, inputMessage);
assertThat(result).as("Invalid result").hasSize(3);
assertThat(result.get("name 1")).as("Invalid result").isEqualTo("value 1");
assertThat(result.get("name 2")).as("Invalid result").isEqualTo("value 2");
assertThat(result.get("name 3")).as("Invalid result").isNull();
}
@Test
void writeForm() throws IOException {
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();