use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri.
@Test
void boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> restTemplate.getForEntity("https://spring.io/hello", String.class)).withMessageContaining("expected:<https://example.com/hello> but was:<https://spring.io/hello>");
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method boundRestTemplateShouldPrefixRootUri.
@Test
void boundRestTemplateShouldPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
restTemplate.getForEntity("/hello", String.class);
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method bindToShouldReturnMockRestServiceServer.
@Test
void bindToShouldReturnMockRestServiceServer() {
RestTemplate restTemplate = new RestTemplateBuilder().build();
MockRestServiceServer bound = RootUriRequestExpectationManager.bindTo(restTemplate);
assertThat(bound).isNotNull();
}
use of org.springframework.boot.web.client.RestTemplateBuilder 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);
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class TestRestTemplateTests method useTheSameRequestFactoryClassWithBasicAuth.
@Test
void useTheSameRequestFactoryClassWithBasicAuth() {
OkHttp3ClientHttpRequestFactory customFactory = new OkHttp3ClientHttpRequestFactory();
RestTemplateBuilder builder = new RestTemplateBuilder().requestFactory(() -> customFactory);
TestRestTemplate testRestTemplate = new TestRestTemplate(builder).withBasicAuth("test", "test");
RestTemplate restTemplate = testRestTemplate.getRestTemplate();
assertThat(restTemplate.getRequestFactory()).isEqualTo(customFactory).hasSameClassAs(customFactory);
}
Aggregations