mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-30 22:39:06 +00:00
Polish documentation following relocation of TestRestTemplate
See gh-46356 See gh-47322
This commit is contained in:
+1
-1
@@ -86,7 +86,7 @@ runApplication<MyApplication>(*args) {
|
||||
Kotlin {url-kotlin-docs}/extensions.html[extensions] provide the ability to extend existing classes with additional functionality.
|
||||
The Spring Boot Kotlin API makes use of these extensions to add new Kotlin specific conveniences to existing APIs.
|
||||
|
||||
javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] extensions, similar to those provided by Spring Framework for javadoc:org.springframework.web.client.RestOperations[] in Spring Framework, are provided.
|
||||
javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] extensions, similar to those provided by Spring Framework for javadoc:org.springframework.web.client.RestOperations[] in Spring Framework, are provided.
|
||||
Among other things, the extensions make it possible to take advantage of Kotlin reified type parameters.
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -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-retclient-test` modules also provides a javadoc:org.springframework.boot.restclient.test.TestRestTemplate[] facility:
|
||||
The `spring-boot-resttestclient` modules also provides a javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] facility:
|
||||
|
||||
include-code::MyRandomPortTestRestTemplateTests[]
|
||||
|
||||
|
||||
+5
-5
@@ -42,8 +42,8 @@ include-code::MyOutputCaptureTests[]
|
||||
[[testing.utilities.test-rest-template]]
|
||||
== 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.
|
||||
javadoc:org.springframework.boot.resttestclient.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-resttestclient` 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.
|
||||
@@ -55,14 +55,14 @@ If you need fluent API for assertions, consider using javadoc:org.springframewor
|
||||
If you are using Spring WebFlux, consider the javadoc:org.springframework.test.web.reactive.server.WebTestClient[] that provides a similar API and works with xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[mock environments], xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-webflux-tests[WebFlux integration tests], and xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-running-server[end-to-end tests].
|
||||
|
||||
It is recommended, but not mandatory, to use the Apache HTTP Client (version 5.1 or better).
|
||||
If you have that on your classpath, the javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] responds by configuring the client appropriately.
|
||||
If you have that on your classpath, the javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] responds by configuring the client appropriately.
|
||||
If you do use Apache's HTTP client it is configured to ignore cookies (so the template is stateless).
|
||||
|
||||
javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] can be instantiated directly in your integration tests, as shown in the following example:
|
||||
javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] can be instantiated directly in your integration tests, as shown in the following example:
|
||||
|
||||
include-code::MyTests[]
|
||||
|
||||
Alternatively, if you use the javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] annotation with `WebEnvironment.RANDOM_PORT` or `WebEnvironment.DEFINED_PORT`, you can inject a fully configured javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] and start using it.
|
||||
Alternatively, if you use the javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] annotation with `WebEnvironment.RANDOM_PORT` or `WebEnvironment.DEFINED_PORT`, you can inject a fully configured javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] and start using it.
|
||||
If necessary, additional customizations can be applied through the javadoc:org.springframework.boot.web.client.RestTemplateBuilder[] bean.
|
||||
Any URLs that do not specify a host and port automatically connect to the embedded server, as shown in the following example:
|
||||
|
||||
|
||||
+6
-3
@@ -44,6 +44,7 @@ import org.springframework.boot.http.client.HttpComponentsHttpClientBuilder.TlsS
|
||||
import org.springframework.boot.http.client.HttpRedirects;
|
||||
import org.springframework.boot.restclient.RestTemplateBuilder;
|
||||
import org.springframework.boot.restclient.RootUriTemplateHandler;
|
||||
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -77,9 +78,11 @@ import org.springframework.web.util.UriTemplateHandler;
|
||||
* {@link #getRestTemplate()}.
|
||||
* <p>
|
||||
* If you are using the {@code @SpringBootTest} annotation with an embedded server, a
|
||||
* {@link TestRestTemplate} is automatically available and can be {@code @Autowired} into
|
||||
* your test. If you need customizations (for example to adding additional message
|
||||
* converters) use a {@link RestTemplateBuilder} {@code @Bean}.
|
||||
* {@link TestRestTemplate} can be auto-configured by adding
|
||||
* {@link AutoConfigureTestRestTemplate @AutoConfigureTestRestTemplate} to your test
|
||||
* class. It can then be {@code @Autowired} into your test. If you need customizations
|
||||
* (for example to adding additional message converters) use a {@link RestTemplateBuilder}
|
||||
* {@code @Bean}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
|
||||
Reference in New Issue
Block a user