File tree Expand file tree Collapse file tree 4 files changed +18
-9
lines changed
documentation/spring-boot-docs/src/main
java/org/springframework/boot/docs/testing/utilities/testresttemplate
kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate Expand file tree Collapse file tree 4 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 2828import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
2929import org .springframework .boot .test .context .TestConfiguration ;
3030import org .springframework .context .annotation .Bean ;
31- import org .springframework .http .HttpHeaders ;
31+ import org .springframework .http .HttpStatus ;
32+ import org .springframework .http .ResponseEntity ;
3233
3334import static org .assertj .core .api .Assertions .assertThat ;
3435
@@ -41,8 +42,9 @@ class MySpringBootTests {
4142
4243 @ Test
4344 void testRequest () {
44- HttpHeaders headers = this .template .getForEntity ("/example" , String .class ).getHeaders ();
45- assertThat (headers .getLocation ()).hasHost ("other.example.com" );
45+ ResponseEntity <String > response = this .template .getForEntity ("/example" , String .class );
46+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
47+ // Other assertions to verify the response
4648 }
4749
4850 @ TestConfiguration (proxyBeanMethods = false )
Original file line number Diff line number Diff line change 1919import org .junit .jupiter .api .Test ;
2020
2121import org .springframework .boot .resttestclient .TestRestTemplate ;
22+ import org .springframework .http .HttpStatus ;
2223import org .springframework .http .ResponseEntity ;
2324
2425import static org .assertj .core .api .Assertions .assertThat ;
@@ -29,8 +30,10 @@ class MyTests {
2930
3031 @ Test
3132 void testRequest () {
32- ResponseEntity <String > headers = this .template .getForEntity ("https://myhost.example.com/example" , String .class );
33- assertThat (headers .getHeaders ().getLocation ()).hasHost ("other.example.com" );
33+ ResponseEntity <String > response = this .template .getForEntity ("https://myhost.example.com/example" ,
34+ String .class );
35+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
36+ // Other assertions to verify the response
3437 }
3538
3639}
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import org.springframework.boot.restclient.RestTemplateBuilder
2626import org.springframework.boot.resttestclient.TestRestTemplate
2727import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate
2828import org.springframework.context.annotation.Bean
29+ import org.springframework.http.HttpStatus
2930import java.time.Duration
3031
3132@SpringBootTest(webEnvironment = WebEnvironment .RANDOM_PORT )
@@ -34,8 +35,9 @@ class MySpringBootTests(@Autowired val template: TestRestTemplate) {
3435
3536 @Test
3637 fun testRequest () {
37- val headers = template.getForEntity(" /example" , String ::class .java).headers
38- assertThat(headers.location).hasHost(" other.example.com" )
38+ val response = template.getForEntity(" /example" , String ::class .java)
39+ assertThat(response.statusCode).isEqualTo(HttpStatus .OK )
40+ // Other assertions to verify the response
3941 }
4042
4143 @TestConfiguration(proxyBeanMethods = false )
Original file line number Diff line number Diff line change @@ -19,15 +19,17 @@ package org.springframework.boot.docs.testing.utilities.testresttemplate
1919import org.assertj.core.api.Assertions.assertThat
2020import org.junit.jupiter.api.Test
2121import org.springframework.boot.resttestclient.TestRestTemplate
22+ import org.springframework.http.HttpStatus
2223
2324class MyTests {
2425
2526 private val template = TestRestTemplate ()
2627
2728 @Test
2829 fun testRequest () {
29- val headers = template.getForEntity(" https://myhost.example.com/example" , String ::class .java)
30- assertThat(headers.headers.location).hasHost(" other.example.com" )
30+ val response = template.getForEntity(" https://myhost.example.com/example" , String ::class .java)
31+ assertThat(response.statusCode).isEqualTo(HttpStatus .OK )
32+ // Other assertions to verify the response
3133 }
3234
3335}
You can’t perform that action at this time.
0 commit comments