Align TestRestTemplate redirect defaults
Align redirect settings of `TestRestTemplate` with other blocking clients and deprecate `HttpClientOption.ENABLE_REDIRECTS`. A new `withRedirects` convenience method has also been added to quickly allow the setting to be changed. Closes gh-43431
This commit is contained in:
@@ -163,9 +163,9 @@ class TestRestTemplateTests {
|
||||
void httpComponentsAreBuiltConsideringSettingsInRestTemplateBuilder() {
|
||||
RestTemplateBuilder builder = new RestTemplateBuilder()
|
||||
.requestFactoryBuilder(ClientHttpRequestFactoryBuilder.httpComponents());
|
||||
assertThat(getRedirectStrategy((RestTemplateBuilder) null)).matches(this::isDontFollowStrategy);
|
||||
assertThat(getRedirectStrategy((RestTemplateBuilder) null)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(null, HttpClientOption.ENABLE_REDIRECTS)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(builder)).matches(this::isDontFollowStrategy);
|
||||
assertThat(getRedirectStrategy(builder)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(builder, HttpClientOption.ENABLE_REDIRECTS)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(builder.redirects(Redirects.DONT_FOLLOW))).matches(this::isDontFollowStrategy);
|
||||
assertThat(getRedirectStrategy(builder.redirects(Redirects.DONT_FOLLOW), HttpClientOption.ENABLE_REDIRECTS))
|
||||
@@ -175,7 +175,7 @@ class TestRestTemplateTests {
|
||||
@Test
|
||||
void withRequestFactorySettingsRedirectsForHttpComponents() {
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
assertThat(getRedirectStrategy(template)).matches(this::isDontFollowStrategy);
|
||||
assertThat(getRedirectStrategy(template)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(template
|
||||
.withRequestFactorySettings(ClientHttpRequestFactorySettings.defaults().withRedirects(Redirects.FOLLOW))))
|
||||
.matches(this::isFollowStrategy);
|
||||
@@ -184,6 +184,15 @@ class TestRestTemplateTests {
|
||||
.matches(this::isDontFollowStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void withRedirects() {
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
assertThat(getRedirectStrategy(template)).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(template.withRedirects(Redirects.FOLLOW))).matches(this::isFollowStrategy);
|
||||
assertThat(getRedirectStrategy(template.withRedirects(Redirects.DONT_FOLLOW)))
|
||||
.matches(this::isDontFollowStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void withRequestFactorySettingsRedirectsForJdk() {
|
||||
TestRestTemplate template = new TestRestTemplate(
|
||||
|
||||
Reference in New Issue
Block a user