Fixup tests that rely on TestRestTemplate redirects

See gh-43431
This commit is contained in:
Phillip Webb 2025-04-17 17:48:23 -07:00
parent 5eee67b8da
commit 284c78f737
1 changed files with 3 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import java.net.URI;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings.Redirects;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
@ -42,7 +43,8 @@ class SampleOAuth2ClientApplicationTests {
@Test
void everythingShouldRedirectToLogin() {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
ResponseEntity<String> entity = this.restTemplate.withRedirects(Redirects.DONT_FOLLOW)
.getForEntity("/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/login"));
}