|
18 | 18 |
|
19 | 19 | import java.nio.charset.StandardCharsets;
|
20 | 20 | import java.util.Collections;
|
| 21 | +import java.util.Map; |
21 | 22 |
|
22 | 23 | import org.junit.jupiter.api.Test;
|
23 | 24 |
|
@@ -124,6 +125,72 @@ public void testFormDataContains() throws Exception {
|
124 | 125 | .match(this.request);
|
125 | 126 | }
|
126 | 127 |
|
| 128 | + @Test |
| 129 | + public void testMultipartData() throws Exception { |
| 130 | + String contentType = "multipart/form-data;boundary=1234567890"; |
| 131 | + String body = "--1234567890\r\n" + |
| 132 | + "Content-Disposition: form-data; name=\"name 1\"\r\n" + |
| 133 | + "\r\n" + |
| 134 | + "vølue 1\r\n" + |
| 135 | + "--1234567890\r\n" + |
| 136 | + "Content-Disposition: form-data; name=\"name 2\"\r\n" + |
| 137 | + "\r\n" + |
| 138 | + "value 🙂\r\n" + |
| 139 | + "--1234567890\r\n" + |
| 140 | + "Content-Disposition: form-data; name=\"name 3\"\r\n" + |
| 141 | + "\r\n" + |
| 142 | + "value 漢字\r\n" + |
| 143 | + "--1234567890\r\n" + |
| 144 | + "Content-Disposition: form-data; name=\"name 4\"\r\n" + |
| 145 | + "\r\n" + |
| 146 | + "\r\n" + |
| 147 | + "--1234567890--\r\n"; |
| 148 | + |
| 149 | + this.request.getHeaders().setContentType(MediaType.parseMediaType(contentType)); |
| 150 | + this.request.getBody().write(body.getBytes(StandardCharsets.UTF_8)); |
| 151 | + |
| 152 | + MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); |
| 153 | + map.add("name 1", "vølue 1"); |
| 154 | + map.add("name 2", "value 🙂"); |
| 155 | + map.add("name 3", "value 漢字"); |
| 156 | + map.add("name 4", ""); |
| 157 | + MockRestRequestMatchers.content().multipartData(map).match(this.request); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void testMultipartDataContains() throws Exception { |
| 162 | + String contentType = "multipart/form-data;boundary=1234567890"; |
| 163 | + String body = "--1234567890\r\n" + |
| 164 | + "Content-Disposition: form-data; name=\"name 1\"\r\n" + |
| 165 | + "\r\n" + |
| 166 | + "vølue 1\r\n" + |
| 167 | + "--1234567890\r\n" + |
| 168 | + "Content-Disposition: form-data; name=\"name 2\"\r\n" + |
| 169 | + "\r\n" + |
| 170 | + "value 🙂\r\n" + |
| 171 | + "--1234567890\r\n" + |
| 172 | + "Content-Disposition: form-data; name=\"name 3\"\r\n" + |
| 173 | + "\r\n" + |
| 174 | + "value 漢字\r\n" + |
| 175 | + "--1234567890\r\n" + |
| 176 | + "Content-Disposition: form-data; name=\"name 4\"\r\n" + |
| 177 | + "\r\n" + |
| 178 | + "\r\n" + |
| 179 | + "--1234567890--\r\n"; |
| 180 | + |
| 181 | + this.request.getHeaders().setContentType(MediaType.parseMediaType(contentType)); |
| 182 | + this.request.getBody().write(body.getBytes(StandardCharsets.UTF_8)); |
| 183 | + |
| 184 | + MockRestRequestMatchers.content() |
| 185 | + .multipartDataContains(Map.of( |
| 186 | + "name 1", "vølue 1", |
| 187 | + "name 2", "value 🙂", |
| 188 | + "name 3", "value 漢字", |
| 189 | + "name 4", "") |
| 190 | + ) |
| 191 | + .match(this.request); |
| 192 | + } |
| 193 | + |
127 | 194 | @Test
|
128 | 195 | public void testXml() throws Exception {
|
129 | 196 | String content = "<foo><bar>baz</bar><bar>bazz</bar></foo>";
|
|
0 commit comments