@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy;
@@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target ;
import java.net.URI ;
import java.net.URISyntaxException ;
import java.nio.charset.StandardCharsets ;
import java.util.List ;
import java.util.Map ;
import java.util.function.Consumer ;
@ -56,6 +55,7 @@ import org.springframework.util.LinkedMultiValueMap;
@@ -56,6 +55,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap ;
import org.springframework.web.testfixture.xml.Pojo ;
import static java.nio.charset.StandardCharsets.UTF_8 ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.junit.jupiter.api.Assumptions.assumeFalse ;
@ -660,8 +660,8 @@ class RestClientIntegrationTests {
@@ -660,8 +660,8 @@ class RestClientIntegrationTests {
startServer ( requestFactory ) ;
String content = "Internal Server error" ;
prepareResponse ( response - > response . setResponseCode ( 500 )
. setHeader ( "Content-Type" , "text/plain" ) . setBody ( content ) ) ;
prepareResponse ( response - >
response . setResponseCode ( 500 ) . setHeader ( "Content-Type" , "text/plain" ) . setBody ( content ) ) ;
ResponseEntity < String > result = this . restClient . get ( )
. uri ( "/" ) . accept ( MediaType . APPLICATION_JSON )
@ -689,7 +689,7 @@ class RestClientIntegrationTests {
@@ -689,7 +689,7 @@ class RestClientIntegrationTests {
String result = this . restClient . get ( )
. uri ( "/greeting" )
. header ( "X-Test-Header" , "testvalue" )
. exchange ( ( request , response ) - > new String ( RestClientUtils . getBody ( response ) , StandardCharsets . UTF_8 ) ) ;
. exchange ( ( request , response ) - > new String ( RestClientUtils . getBody ( response ) , UTF_8 ) ) ;
assertThat ( result ) . isEqualTo ( "Hello Spring!" ) ;
@ -753,12 +753,12 @@ class RestClientIntegrationTests {
@@ -753,12 +753,12 @@ class RestClientIntegrationTests {
void exchangeFor404 ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setResponseCode ( 404 )
. setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Not Found" ) ) ;
prepareResponse ( response - >
response . setResponseCode ( 404 ) . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Not Found" ) ) ;
String result = this . restClient . get ( )
. uri ( "/greeting" )
. exchange ( ( request , response ) - > new String ( RestClientUtils . getBody ( response ) , StandardCharsets . UTF_8 ) ) ;
. exchange ( ( request , response ) - > new String ( RestClientUtils . getBody ( response ) , UTF_8 ) ) ;
assertThat ( result ) . isEqualTo ( "Not Found" ) ;
@ -770,8 +770,8 @@ class RestClientIntegrationTests {
@@ -770,8 +770,8 @@ class RestClientIntegrationTests {
void requestInitializer ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient initializedClient = this . restClient . mutate ( )
. requestInitializer ( request - > request . getHeaders ( ) . add ( "foo" , "bar" ) )
@ -792,9 +792,8 @@ class RestClientIntegrationTests {
@@ -792,9 +792,8 @@ class RestClientIntegrationTests {
void requestInterceptor ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient interceptedClient = this . restClient . mutate ( )
. requestInterceptor ( ( request , body , execution ) - > {
@ -819,6 +818,7 @@ class RestClientIntegrationTests {
@@ -819,6 +818,7 @@ class RestClientIntegrationTests {
startServer ( requestFactory ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient restClientWithCookies = this . restClient . mutate ( )
. defaultCookie ( "testCookie" , "firstValue" , "secondValue" )
. build ( ) ;
@ -852,8 +852,8 @@ class RestClientIntegrationTests {
@@ -852,8 +852,8 @@ class RestClientIntegrationTests {
RestClient interceptedClient = this . restClient . mutate ( ) . requestInterceptor ( interceptor ) . build ( ) ;
// header not present
prepareResponse ( response - > response
. setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
assertThatExceptionOfType ( MyException . class ) . isThrownBy ( ( ) - >
interceptedClient . get ( )
@ -881,8 +881,8 @@ class RestClientIntegrationTests {
@@ -881,8 +881,8 @@ class RestClientIntegrationTests {
void defaultHeaders ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient headersClient = this . restClient . mutate ( )
. defaultHeaders ( headers - > headers . add ( "foo" , "bar" ) )
@ -903,8 +903,8 @@ class RestClientIntegrationTests {
@@ -903,8 +903,8 @@ class RestClientIntegrationTests {
void defaultRequest ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient headersClient = this . restClient . mutate ( )
. defaultRequest ( request - > request . header ( "foo" , "bar" ) )
@ -925,8 +925,8 @@ class RestClientIntegrationTests {
@@ -925,8 +925,8 @@ class RestClientIntegrationTests {
void defaultRequestOverride ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient headersClient = this . restClient . mutate ( )
. defaultRequest ( request - > request . accept ( MediaType . APPLICATION_JSON ) )
@ -948,8 +948,8 @@ class RestClientIntegrationTests {
@@ -948,8 +948,8 @@ class RestClientIntegrationTests {
void relativeUri ( ClientHttpRequestFactory requestFactory ) throws URISyntaxException {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
URI uri = new URI ( null , null , "/foo bar" , null ) ;
@ -969,23 +969,28 @@ class RestClientIntegrationTests {
@@ -969,23 +969,28 @@ class RestClientIntegrationTests {
@ParameterizedRestClientTest
void cookieAddsCookie ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
this . restClient . get ( )
. uri ( "/greeting" )
. cookie ( "foo" , "bar" )
. cookie ( "c1" , "v1a" )
. cookie ( "c1" , "v1b" )
. cookie ( "c2" , "v2a" )
. retrieve ( )
. body ( String . class ) ;
expectRequest ( request - > assertThat ( request . getHeader ( "Cookie" ) ) . isEqualTo ( "foo=bar " ) ) ;
expectRequest ( request - > assertThat ( request . getHeader ( "Cookie" ) ) . isEqualTo ( "c1=v1a; c1=v1b; c2=v2a " ) ) ;
}
@ParameterizedRestClientTest
void cookieOverridesDefaultCookie ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
RestClient restClientWithCookies = this . restClient . mutate ( )
. defaultCookie ( "testCookie" , "firstValue" , "secondValue" )
. build ( ) ;
@ -1002,8 +1007,9 @@ class RestClientIntegrationTests {
@@ -1002,8 +1007,9 @@ class RestClientIntegrationTests {
@ParameterizedRestClientTest
void cookiesCanRemoveCookie ( ClientHttpRequestFactory requestFactory ) {
startServer ( requestFactory ) ;
prepareResponse ( response - > response . setHeader ( "Content-Type" , "text/plain" )
. setBody ( "Hello Spring!" ) ) ;
prepareResponse ( response - >
response . setHeader ( "Content-Type" , "text/plain" ) . setBody ( "Hello Spring!" ) ) ;
this . restClient . get ( )
. uri ( "/greeting" )