Move RestTestClientBuilderCustomizer to spring-boot-test

Relocate `RestTestClientBuilderCustomizer` to `spring-boot-test`
and break the direct link to web-server by making use of
`spring.factories` and the new `BaseUrlProviders` class.

See gh-46356
This commit is contained in:
Phillip Webb
2025-10-01 21:51:20 -07:00
parent 6f909114e7
commit bba56ffc8b
125 changed files with 291 additions and 192 deletions
@@ -189,7 +189,7 @@ include-code::MyRandomPortWebTestClientTests[]
TIP: javadoc:org.springframework.test.web.reactive.server.WebTestClient[] can also used with a xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[mock environment], removing the need for a running server, by annotating your test class with javadoc:org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient[format=annotation] from `spring-boot-webflux-test`.
The `spring-boot-web-server-test` modules also provides a javadoc:org.springframework.boot.web.server.test.client.TestRestTemplate[] facility:
The `spring-boot-retclient-test` modules also provides a javadoc:org.springframework.boot.restclient.test.TestRestTemplate[] facility:
include-code::MyRandomPortTestRestTemplateTests[]
@@ -43,6 +43,8 @@ include-code::MyOutputCaptureTests[]
== TestRestTemplate
javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] is a convenience alternative to Spring's javadoc:org.springframework.web.client.RestTemplate[] that is useful in integration tests.
It's provided by the `spring-boot-restclient-test` module.
You can get a vanilla template or one that sends Basic HTTP authentication (with a username and password).
In either case, the template is fault tolerant.
This means that it behaves in a test-friendly way by not throwing exceptions on 4xx and 5xx errors.
@@ -19,9 +19,9 @@ package org.springframework.boot.docs.testing.springbootapplications.withrunning
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.restclient.test.TestRestTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.test.client.TestRestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -22,10 +22,10 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.restclient.RestTemplateBuilder;
import org.springframework.boot.restclient.test.TestRestTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.server.test.client.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
@@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.utilities.testresttemplate;
import org.junit.jupiter.api.Test;
import org.springframework.boot.web.server.test.client.TestRestTemplate;
import org.springframework.boot.restclient.test.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -19,9 +19,9 @@ package org.springframework.boot.docs.testing.springbootapplications.withrunning
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.restclient.test.TestRestTemplate
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.web.server.test.client.TestRestTemplate
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class MyRandomPortTestRestTemplateTests {
@@ -22,8 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.boot.web.server.test.client.TestRestTemplate
import org.springframework.boot.restclient.RestTemplateBuilder
import org.springframework.boot.restclient.test.TestRestTemplate
import org.springframework.context.annotation.Bean
import java.time.Duration
@@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.utilities.testresttemplate
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.boot.web.server.test.client.TestRestTemplate
import org.springframework.boot.restclient.test.TestRestTemplate
class MyTests {