Add contains form data RequestMatcher

See gh-23671
This commit is contained in:
Rossen Stoyanchev
2020-06-17 22:50:58 +01:00
parent bc33ae3f8b
commit de0a043739
2 changed files with 53 additions and 22 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.test.web.client.match;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -117,6 +118,19 @@ public class ContentRequestMatchersTests {
MockRestRequestMatchers.content().formData(map).match(this.request);
}
@Test
public void testFormDataContains() throws Exception {
String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
this.request.getHeaders().setContentType(MediaType.parseMediaType(contentType));
this.request.getBody().write(body.getBytes(StandardCharsets.UTF_8));
MockRestRequestMatchers.content()
.formDataContains(Collections.singletonMap("name 1", "value 1"))
.match(this.request);
}
@Test
public void testXml() throws Exception {
String content = "<foo><bar>baz</bar><bar>bazz</bar></foo>";