Search in sources :

Example 1 with LocalHostUriTemplateHandler

use of org.springframework.boot.test.web.client.LocalHostUriTemplateHandler in project spring-boot by spring-projects.

the class CorsSampleActuatorApplicationTests method setUp.

@BeforeEach
void setUp() {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(), "http");
    builder = builder.uriTemplateHandler(handler);
    this.testRestTemplate = new TestRestTemplate(builder);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LocalHostUriTemplateHandler(org.springframework.boot.test.web.client.LocalHostUriTemplateHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with LocalHostUriTemplateHandler

use of org.springframework.boot.test.web.client.LocalHostUriTemplateHandler in project spring-boot by spring-projects.

the class MetricsRestTemplateCustomizerTests method whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild.

@Test
void whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("local.server.port", "8443");
    LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(environment, "https");
    RestTemplate restTemplate = new RestTemplateBuilder(this.customizer).uriTemplateHandler(uriTemplateHandler).build();
    assertThat(restTemplate.getUriTemplateHandler()).asInstanceOf(InstanceOfAssertFactories.type(RootUriTemplateHandler.class)).extracting(RootUriTemplateHandler::getRootUri).isEqualTo("https://localhost:8443");
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) MockEnvironment(org.springframework.mock.env.MockEnvironment) RestTemplate(org.springframework.web.client.RestTemplate) RootUriTemplateHandler(org.springframework.boot.web.client.RootUriTemplateHandler) LocalHostUriTemplateHandler(org.springframework.boot.test.web.client.LocalHostUriTemplateHandler) Test(org.junit.jupiter.api.Test)

Example 3 with LocalHostUriTemplateHandler

use of org.springframework.boot.test.web.client.LocalHostUriTemplateHandler in project spring-boot by spring-projects.

the class CorsSampleActuatorApplicationTests method setUp.

@BeforeEach
void setUp() {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(), "http");
    builder = builder.uriTemplateHandler(handler);
    this.testRestTemplate = new TestRestTemplate(builder);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LocalHostUriTemplateHandler(org.springframework.boot.test.web.client.LocalHostUriTemplateHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LocalHostUriTemplateHandler (org.springframework.boot.test.web.client.LocalHostUriTemplateHandler)3 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)2 Test (org.junit.jupiter.api.Test)1 RootUriTemplateHandler (org.springframework.boot.web.client.RootUriTemplateHandler)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1 RestTemplate (org.springframework.web.client.RestTemplate)1