Configure JsonPath in RestTestClient with MappingProvider

Closes gh-35793
This commit is contained in:
rstoyanchev
2025-11-18 15:46:57 +00:00
parent adffd3dcf6
commit f80b79bc45
2 changed files with 53 additions and 1 deletions
@@ -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")