mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Polish "Deprecate TestRestTemplate"
See gh-46632
This commit is contained in:
@@ -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]
|
||||
|
||||
-3
@@ -85,9 +85,6 @@ 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.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]]
|
||||
|
||||
-8
@@ -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]]
|
||||
|
||||
-37
@@ -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[]
|
||||
|
||||
-40
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
-61
@@ -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<String> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-46
@@ -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<String> example() {
|
||||
return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -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<String> response = this.template.getForEntity("https://myhost.example.com/example",
|
||||
String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
// Other assertions to verify the response
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-57
@@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-50
@@ -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<String> {
|
||||
return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-38
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-26
@@ -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 {
|
||||
|
||||
}
|
||||
+1
@@ -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");
|
||||
|
||||
+1
@@ -75,6 +75,7 @@ abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
@Deprecated(since = "4.2.0", forRemoval = true)
|
||||
TestRestTemplate getRestTemplate() {
|
||||
return this.restTemplate;
|
||||
}
|
||||
|
||||
@@ -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")))
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
|
||||
+3
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -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 {
|
||||
|
||||
|
||||
+3
@@ -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 <reified T : Any> TestRestTemplate.getForObject(url: String, vararg uriVariables: Any): T? =
|
||||
getForObject(url, T::class.java, *uriVariables)
|
||||
|
||||
+2
@@ -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 {
|
||||
|
||||
|
||||
+2
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user