From 297ee8694540bb21243dedabb74c18000716058e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Mon, 27 Jul 2026 21:12:35 +0200 Subject: [PATCH] Polish "Deprecate `TestRestTemplate`" See gh-46632 --- .../antora/modules/ROOT/pages/redirect.adoc | 2 - .../reference/pages/features/kotlin.adoc | 3 - .../testing/spring-boot-applications.adoc | 8 --- .../pages/testing/test-utilities.adoc | 37 ----------- .../MyRandomPortTestRestTemplateTests.java | 40 ------------ .../testresttemplate/MySpringBootTests.java | 61 ------------------- .../MySpringBootTestsConfiguration.java | 46 -------------- .../utilities/testresttemplate/MyTests.java | 40 ------------ .../MyRandomPortTestRestTemplateTests.kt | 40 ------------ .../testresttemplate/MySpringBootTests.kt | 57 ----------------- .../MySpringBootTestsConfiguration.kt | 50 --------------- .../utilities/testresttemplate/MyTests.kt | 38 ------------ .../MySpringBootTestsTests.java | 26 -------- ...stEmbeddedReactiveWebEnvironmentTests.java | 1 + ...gBootTestWebServerWebEnvironmentTests.java | 1 + module/spring-boot-jersey/build.gradle | 1 - .../AutoConfigureRestClient.java | 3 +- .../boot/resttestclient/TestRestTemplate.java | 4 +- .../AutoConfigureTestRestTemplate.java | 3 + ...TestRestTemplateTestAutoConfiguration.java | 3 + .../TestRestTemplateExtensions.kt | 3 + .../resttestclient/TestRestTemplateTests.java | 2 + ...estTemplateTestAutoConfigurationTests.java | 2 + 23 files changed, 18 insertions(+), 453 deletions(-) delete mode 100644 documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.java delete mode 100644 documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java delete mode 100644 documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.java delete mode 100644 documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.java delete mode 100644 documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.kt delete mode 100644 documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt delete mode 100644 documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.kt delete mode 100644 documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.kt delete mode 100644 documentation/spring-boot-docs/src/test/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsTests.java diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc index 650798f890d..2fb7cd7c77b 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc @@ -1939,8 +1939,6 @@ * xref:reference:testing/test-utilities.adoc#testing.utilities.output-capture[#features.testing.utilities.output-capture] * xref:reference:testing/test-utilities.adoc#testing.utilities.test-property-values[#boot-features-test-property-values] * xref:reference:testing/test-utilities.adoc#testing.utilities.test-property-values[#features.testing.utilities.test-property-values] -* xref:reference:testing/test-utilities.adoc#testing.utilities.test-rest-template[#boot-features-rest-templates-test-utility] -* xref:reference:testing/test-utilities.adoc#testing.utilities.test-rest-template[#features.testing.utilities.test-rest-template] * xref:reference:testing/test-utilities.adoc#testing.utilities[#boot-features-test-utilities] * xref:reference:testing/test-utilities.adoc#testing.utilities[#features.testing.utilities] * xref:reference:testing/testcontainers.adoc#testing.testcontainers.dynamic-properties[#features.testing.testcontainers.dynamic-properties] diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc index bb32a7e5d39..d7215bff676 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc @@ -85,9 +85,6 @@ runApplication(*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.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. - [[features.kotlin.dependency-management]] diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc index f5017c69298..387c96326f5 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc @@ -199,14 +199,6 @@ TIP: javadoc:org.springframework.test.web.reactive.server.WebTestClient[] can al NOTE: For certain xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[sliced tests] you may need to use the javadoc:org.springframework.boot.web.server.test.AutoConfigureWebServer[format=annotation] annotation to auto-configure an embedded web server. -The `spring-boot-resttestclient` module also provides a javadoc:org.springframework.boot.resttestclient.TestRestTemplate[] facility: - -include-code::MyRandomPortTestRestTemplateTests[] - -To use `TestRestTemplate` a dependency on `spring-boot-restclient` is also required. -Take care when adding this dependency as it will enable auto-configuration for `RestClient.Builder`. -If your main code uses `RestClient.Builder`, declare the `spring-boot-restclient` dependency so that it is on your application's main classpath and not only on its test classpath. - [[testing.spring-boot-applications.customizing-rest-test-client]] diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-utilities.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-utilities.adoc index 64ae3f407d4..e94323cea6a 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-utilities.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-utilities.adoc @@ -36,40 +36,3 @@ javadoc:org.springframework.boot.test.system.OutputCaptureExtension[] is a JUnit To use it, add `@ExtendWith(OutputCaptureExtension.class)` and inject javadoc:org.springframework.boot.test.system.CapturedOutput[] as an argument to your test class constructor or test method as follows: include-code::MyOutputCaptureTests[] - - - -[[testing.utilities.test-rest-template]] -== TestRestTemplate - -WARNING: As of Spring Boot 4.2, `TestRestTemplate` is formally deprecated along `RestTemplate` itself in Spring Framework 7.1. -Test suites should xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-mvc-tests[migrate to `RestTestClient`], which can bind itself against a live server or a mock transport. - -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. -A dependency on `spring-boot-restclient` is also required. -Take care when adding this dependency as it will enable auto-configuration for `RestClient.Builder`. -If your main code uses `RestClient.Builder`, declare the `spring-boot-restclient` dependency so that it is on your application's main classpath and not only on its test classpath. - -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. -Instead, such errors can be detected through the returned javadoc:org.springframework.http.ResponseEntity[] and its status code. - -If you need fluent API for assertions, consider using javadoc:org.springframework.test.web.servlet.client.RestTestClient[] that works with xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[mock environments] and xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-running-server[end-to-end tests]. - -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.resttestclient.TestRestTemplate[] responds by configuring the client appropriately. - -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.resttestclient.TestRestTemplate[] by annotating the test class with javadoc:org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate[format=annotation]. -If necessary, additional customizations can be applied through the javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] bean. - -Any URLs that do not specify a host and port automatically connect to the embedded server, as shown in the following example: - -include-code::MySpringBootTests[] diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.java deleted file mode 100644 index c745b363470..00000000000 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.springbootapplications.withrunningserver; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.resttestclient.TestRestTemplate; -import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@AutoConfigureTestRestTemplate -@SuppressWarnings("removal") -class MyRandomPortTestRestTemplateTests { - - @Test - void exampleTest(@Autowired TestRestTemplate restTemplate) { - String body = restTemplate.getForObject("/", String.class); - assertThat(body).isEqualTo("Hello World"); - } - -} diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java deleted file mode 100644 index ccedfe30b18..00000000000 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.utilities.testresttemplate; - -import java.time.Duration; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.restclient.RestTemplateBuilder; -import org.springframework.boot.resttestclient.TestRestTemplate; -import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate; -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.context.annotation.Bean; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@AutoConfigureTestRestTemplate -@SuppressWarnings("removal") -class MySpringBootTests { - - @Autowired - private TestRestTemplate template; - - @Test - void testRequest() { - ResponseEntity response = this.template.getForEntity("/example", String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - // Other assertions to verify the response - } - - @TestConfiguration(proxyBeanMethods = false) - static class RestTemplateBuilderConfiguration { - - @Bean - RestTemplateBuilder restTemplateBuilder() { - return new RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1)).readTimeout(Duration.ofSeconds(1)); - } - - } - -} diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.java deleted file mode 100644 index 10f4ad060ac..00000000000 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.utilities.testresttemplate; - -import java.net.URI; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration; -import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; -import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration; -import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@SpringBootConfiguration(proxyBeanMethods = false) -@ImportAutoConfiguration({ TomcatServletWebServerAutoConfiguration.class, DispatcherServletAutoConfiguration.class, - JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) -public class MySpringBootTestsConfiguration { - - @RestController - private static final class ExampleController { - - @RequestMapping("/example") - ResponseEntity example() { - return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test"); - } - - } - -} diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.java deleted file mode 100644 index ce5a75bb3ee..00000000000 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.utilities.testresttemplate; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.resttestclient.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SuppressWarnings("removal") -class MyTests { - - private final TestRestTemplate template = new TestRestTemplate(); - - @Test - void testRequest() { - ResponseEntity response = this.template.getForEntity("https://myhost.example.com/example", - String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - // Other assertions to verify the response - } - -} diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.kt deleted file mode 100644 index 998b965ba50..00000000000 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("DEPRECATION", "REMOVAL") - -package org.springframework.boot.docs.testing.springbootapplications.withrunningserver - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -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.resttestclient.TestRestTemplate -import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@AutoConfigureTestRestTemplate -class MyRandomPortTestRestTemplateTests { - - @Test - fun exampleTest(@Autowired restTemplate: TestRestTemplate) { - val body = restTemplate.getForObject("/", String::class.java) - assertThat(body).isEqualTo("Hello World") - } - -} - diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt deleted file mode 100644 index 0047cc1237b..00000000000 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("DEPRECATION", "REMOVAL") - -package org.springframework.boot.docs.testing.utilities.testresttemplate - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -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.restclient.RestTemplateBuilder -import org.springframework.boot.resttestclient.TestRestTemplate -import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate -import org.springframework.context.annotation.Bean -import org.springframework.http.HttpStatus -import java.time.Duration - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@AutoConfigureTestRestTemplate -class MySpringBootTests(@Autowired val template: TestRestTemplate) { - - @Test - fun testRequest() { - val response = template.getForEntity("/example", String::class.java) - assertThat(response.statusCode).isEqualTo(HttpStatus.OK) - // Other assertions to verify the response - } - - @TestConfiguration(proxyBeanMethods = false) - internal class RestTemplateBuilderConfiguration { - - @Bean - fun restTemplateBuilder(): RestTemplateBuilder { - return RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1)) - .readTimeout(Duration.ofSeconds(1)) - } - - } - -} - diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.kt deleted file mode 100644 index 1878d5fbc28..00000000000 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsConfiguration.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.utilities.testresttemplate - -import org.springframework.boot.SpringBootConfiguration -import org.springframework.boot.autoconfigure.ImportAutoConfiguration -import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration -import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration -import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration -import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import java.net.URI - -@SpringBootConfiguration(proxyBeanMethods = false) -@ImportAutoConfiguration( - TomcatServletWebServerAutoConfiguration::class, - DispatcherServletAutoConfiguration::class, - JacksonAutoConfiguration::class, - HttpMessageConvertersAutoConfiguration::class -) -class MySpringBootTestsConfiguration { - - @RestController - private class ExampleController { - - @RequestMapping("/example") - fun example(): ResponseEntity { - return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test") - } - - } - -} - diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.kt deleted file mode 100644 index cb9c135809f..00000000000 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MyTests.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("DEPRECATION", "REMOVAL") - -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.resttestclient.TestRestTemplate -import org.springframework.http.HttpStatus - -class MyTests { - - private val template = TestRestTemplate() - - @Test - fun testRequest() { - val response = template.getForEntity("https://myhost.example.com/example", String::class.java) - assertThat(response.statusCode).isEqualTo(HttpStatus.OK) - // Other assertions to verify the response - } - -} - diff --git a/documentation/spring-boot-docs/src/test/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsTests.java b/documentation/spring-boot-docs/src/test/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsTests.java deleted file mode 100644 index 08b28061ab6..00000000000 --- a/documentation/spring-boot-docs/src/test/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTestsTests.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.testing.utilities.testresttemplate; - -/** - * Tests for {@link MySpringBootTests}. - * - * @author Stephane Nicoll - */ -class MySpringBootTestsTests extends MySpringBootTests { - -} diff --git a/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java b/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java index 2a5315179e1..38afafd5e08 100644 --- a/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java +++ b/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java @@ -91,6 +91,7 @@ abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests { } @Test + @Deprecated(since = "4.2.0", forRemoval = true) void injectTestRestTemplate() { String body = this.restTemplate.getForObject("/", String.class); assertThat(body).isEqualTo("Hello World"); diff --git a/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java b/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java index 44b790b2625..2b421948bae 100644 --- a/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java +++ b/integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java @@ -75,6 +75,7 @@ abstract class AbstractSpringBootTestWebServerWebEnvironmentTests { return this.context; } + @Deprecated(since = "4.2.0", forRemoval = true) TestRestTemplate getRestTemplate() { return this.restTemplate; } diff --git a/module/spring-boot-jersey/build.gradle b/module/spring-boot-jersey/build.gradle index 05b9982cbac..ae79d007b86 100644 --- a/module/spring-boot-jersey/build.gradle +++ b/module/spring-boot-jersey/build.gradle @@ -52,7 +52,6 @@ dependencies { testImplementation(project(":core:spring-boot-test")) testImplementation(project(":module:spring-boot-restclient")) - testImplementation(project(":module:spring-boot-resttestclient")) testImplementation(project(":module:spring-boot-tomcat")) testImplementation(project(":test-support:spring-boot-test-support")) testImplementation(testFixtures(project(":module:spring-boot-actuator-autoconfigure"))) diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureRestClient.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureRestClient.java index dd943f08ba3..3c7ca91ab9f 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureRestClient.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureRestClient.java @@ -24,13 +24,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.restclient.RestTemplateBuilder; import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; import org.springframework.web.client.RestClient.Builder; /** * Annotation that can be applied to a test class to enable auto-configuration of a - * {@link Builder RestClient.Builder} and a {@link RestTemplateBuilder}. + * {@link Builder RestClient.Builder}. * * @author Andy Wilkinson * @since 4.0.0 diff --git a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java index f45e9da0c4c..d219fc05351 100644 --- a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java +++ b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java @@ -90,10 +90,10 @@ import org.springframework.web.util.UriTemplateHandler; * @author Dmytro Nosan * @author Yanming Zhou * @since 4.0.0 - * @deprecated since 4.1.0 for removal in 4.3.0 in favor of + * @deprecated since 4.2.0 for removal in 4.4.0 in favor of * {@link org.springframework.test.web.servlet.client.RestTestClient} */ -@Deprecated(since = "4.1.0", forRemoval = true) +@Deprecated(since = "4.2.0", forRemoval = true) @SuppressWarnings("removal") public class TestRestTemplate { diff --git a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/AutoConfigureTestRestTemplate.java b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/AutoConfigureTestRestTemplate.java index 6459cd96eed..e11b4557950 100644 --- a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/AutoConfigureTestRestTemplate.java +++ b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/AutoConfigureTestRestTemplate.java @@ -32,12 +32,15 @@ import org.springframework.boot.resttestclient.TestRestTemplate; * * @author Andy Wilkinson * @since 4.0.0 + * @deprecated since 4.2.0 for removal in 4.4.0 in favor of + * {@link AutoConfigureRestTestClient} */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @ImportAutoConfiguration +@Deprecated(since = "4.2.0", forRemoval = true) public @interface AutoConfigureTestRestTemplate { } diff --git a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfiguration.java b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfiguration.java index 3bae6d729a6..07f5d237ec7 100644 --- a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfiguration.java +++ b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfiguration.java @@ -31,8 +31,11 @@ import org.springframework.context.annotation.Bean; * * @author Andy Wilkinson * @see AutoConfigureTestRestTemplate + * @deprecated since 4.2.0 for removal in 4.4.0 in favor of + * {@link RestTestClientTestAutoConfiguration} */ @AutoConfiguration +@Deprecated(since = "4.2.0", forRemoval = true) @SuppressWarnings("removal") final class TestRestTemplateTestAutoConfiguration { diff --git a/module/spring-boot-resttestclient/src/main/kotlin/org/springframework/boot/resttestclient/TestRestTemplateExtensions.kt b/module/spring-boot-resttestclient/src/main/kotlin/org/springframework/boot/resttestclient/TestRestTemplateExtensions.kt index a153539ecd4..662dd1e5cbb 100644 --- a/module/spring-boot-resttestclient/src/main/kotlin/org/springframework/boot/resttestclient/TestRestTemplateExtensions.kt +++ b/module/spring-boot-resttestclient/src/main/kotlin/org/springframework/boot/resttestclient/TestRestTemplateExtensions.kt @@ -34,7 +34,10 @@ import java.net.URI * * @author Sebastien Deleuze * @since 4.0.0 + * @deprecated since 4.2.0 for removal in 4.4.0 in favor of + * {@link org.springframework.test.web.servlet.client.RestTestClient} */ +@Deprecated(message = "in favor of RestTestClient", level = DeprecationLevel.ERROR) @Throws(RestClientException::class) inline fun TestRestTemplate.getForObject(url: String, vararg uriVariables: Any): T? = getForObject(url, T::class.java, *uriVariables) diff --git a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java index 85f6e0cfe8b..def29c1ab0e 100644 --- a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java +++ b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java @@ -79,7 +79,9 @@ import static org.mockito.Mockito.mock; * @author Andy Wilkinson * @author Kristine Jetzke * @author Yanming Zhou + * @deprecated since 4.2.0 for removal in 4.4.0 */ +@Deprecated(since = "4.2.0", forRemoval = true) @SuppressWarnings("removal") class TestRestTemplateTests { diff --git a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfigurationTests.java b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfigurationTests.java index d1fb3ca49d1..9e593dc5d04 100644 --- a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfigurationTests.java +++ b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/autoconfigure/TestRestTemplateTestAutoConfigurationTests.java @@ -34,7 +34,9 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link TestRestTemplateTestAutoConfiguration}. * * @author Stephane Nicoll + * @deprecated since 4.2.0 for removal in 4.4.0 */ +@Deprecated(since = "4.2.0", forRemoval = true) @SuppressWarnings("removal") class TestRestTemplateTestAutoConfigurationTests {