mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Restore TestRestTemplate#getRootUri
This commit adapts TestRestTemplate#getRootUri to the recently introduced LocalTestWebServer. The behavior invokes the UriTemplateHandler to provide the value. If the implementation expands full URL, then it will provide the expected behavior. If not, it should return the empty string as before. Closes gh-48330
This commit is contained in:
+1
-1
@@ -193,7 +193,7 @@ public class TestRestTemplate {
|
||||
if (uriTemplateHandler instanceof RootUriTemplateHandler rootHandler) {
|
||||
return rootHandler.getRootUri();
|
||||
}
|
||||
return "";
|
||||
return uriTemplateHandler.expand("").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
@@ -120,6 +120,14 @@ class TestRestTemplateTests {
|
||||
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRootUriRootUriSetViaLocalTestWebServer() {
|
||||
LocalTestWebServer localTestWebServer = LocalTestWebServer.of(Scheme.HTTPS, 7070);
|
||||
RestTemplateBuilder delegate = new RestTemplateBuilder()
|
||||
.uriTemplateHandler(localTestWebServer.uriBuilderFactory());
|
||||
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo("https://localhost:7070");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRootUriRootUriNotSet() {
|
||||
assertThat(new TestRestTemplate().getRootUri()).isEmpty();
|
||||
|
||||
Reference in New Issue
Block a user