mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 05:09:13 +00:00
Configure JsonPath in RestTestClient with MappingProvider
Closes gh-35793
This commit is contained in:
+14
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.Person;
|
||||
@@ -106,6 +107,19 @@ class JsonPathAssertionTests {
|
||||
.jsonPath("$.performers[1].name").value(v -> MatcherAssert.assertThat(v, equalTo("Yehudi Menuhin")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void valueConsumer() {
|
||||
client.get().uri("/music/people")
|
||||
.exchange()
|
||||
.expectBody()
|
||||
.jsonPath("$.composers[0].name").value(
|
||||
String.class,
|
||||
name -> assertThat(name).isEqualTo("Johann Sebastian Bach"))
|
||||
.jsonPath("$.composers[0].name").value(
|
||||
ParameterizedTypeReference.forType(String.class),
|
||||
name -> assertThat(name).isEqualTo("Johann Sebastian Bach"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hamcrestMatcher() {
|
||||
client.get().uri("/music/people")
|
||||
|
||||
Reference in New Issue
Block a user