Use full URI for URI template keyvalue with RestClient
Prior to this commit, `RestClient` would not use the full URI created by the uri handler as a template request attribute. This means that HTTP client observations would not contain the base URI in recorded observations as the uri template keyvalue. Closes gh-33928
This commit is contained in:
@@ -83,6 +83,7 @@ class RestClientObservationTests {
|
||||
|
||||
RestClient.Builder createBuilder() {
|
||||
return RestClient.builder()
|
||||
.baseUrl("https://example.com/base")
|
||||
.messageConverters(converters -> converters.add(0, this.converter))
|
||||
.requestFactory(this.requestFactory)
|
||||
.observationRegistry(this.observationRegistry);
|
||||
@@ -90,26 +91,37 @@ class RestClientObservationTests {
|
||||
|
||||
@Test
|
||||
void shouldContributeTemplateWhenUriVariables() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/hotels/42/bookings/21");
|
||||
mockSentRequest(GET, "https://example.com/base/hotels/42/bookings/21");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
client.get().uri("https://example.com/hotels/{hotel}/bookings/{booking}", "42", "21")
|
||||
client.get().uri("/hotels/{hotel}/bookings/{booking}", "42", "21")
|
||||
.retrieve().toBodilessEntity();
|
||||
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/hotels/{hotel}/bookings/{booking}");
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/base/hotels/{hotel}/bookings/{booking}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldContributeTemplateWhenMap() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/hotels/42/bookings/21");
|
||||
mockSentRequest(GET, "https://example.com/base/hotels/42/bookings/21");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
Map<String, String> vars = Map.of("hotel", "42", "booking", "21");
|
||||
|
||||
client.get().uri("https://example.com/hotels/{hotel}/bookings/{booking}", vars)
|
||||
client.get().uri("/hotels/{hotel}/bookings/{booking}", vars)
|
||||
.retrieve().toBodilessEntity();
|
||||
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/hotels/{hotel}/bookings/{booking}");
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/base/hotels/{hotel}/bookings/{booking}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldContributeTemplateWhenFunction() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/base/hotels/42/bookings/21");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
client.get().uri("/hotels/{hotel}/bookings/{booking}", builder -> builder.build("42", "21"))
|
||||
.retrieve().toBodilessEntity();
|
||||
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("uri", "/base/hotels/{hotel}/bookings/{booking}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user