Search in sources :

Example 31 with RestTemplateBuilder

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

the class TestRestTemplateTests method doNotReplaceCustomRequestFactory.

@Test
void doNotReplaceCustomRequestFactory() {
    RestTemplateBuilder builder = new RestTemplateBuilder().requestFactory(OkHttp3ClientHttpRequestFactory.class);
    TestRestTemplate testRestTemplate = new TestRestTemplate(builder);
    assertThat(testRestTemplate.getRestTemplate().getRequestFactory()).isInstanceOf(OkHttp3ClientHttpRequestFactory.class);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) Test(org.junit.jupiter.api.Test)

Example 32 with RestTemplateBuilder

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

the class TestRestTemplateTests method fromRestTemplateBuilder.

@Test
void fromRestTemplateBuilder() {
    RestTemplateBuilder builder = mock(RestTemplateBuilder.class);
    RestTemplate delegate = new RestTemplate();
    given(builder.build()).willReturn(delegate);
    assertThat(new TestRestTemplate(builder).getRestTemplate()).isEqualTo(delegate);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 33 with RestTemplateBuilder

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

the class CloudFoundrySecurityServiceTests method doNotSkipSslValidationWhenFalse.

@Test
void doNotSkipSslValidationWhenFalse() {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
    RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
    assertThat(restTemplate.getRequestFactory()).isNotInstanceOf(SkipSslVerificationHttpRequestFactory.class);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 34 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project tutorials by eugenp.

the class TestRestTemplateBasicLiveTest method givenRestTemplateBuilderWrapper_whenSendGetForEntity_thenStatusOk.

@Test
public void givenRestTemplateBuilderWrapper_whenSendGetForEntity_thenStatusOk() {
    RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
    restTemplateBuilder.build();
    TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder);
    ResponseEntity<String> response = testRestTemplate.getForEntity(FOO_RESOURCE_URL + "/1", String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Test(org.junit.Test)

Example 35 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    jettyServer = new Server(0);
    WebAppContext webApp = new WebAppContext();
    webApp.setServer(jettyServer);
    webApp.setContextPath(CONTEXT_PATH);
    webApp.setWar("src/test/webapp");
    jettyServer.setHandler(webApp);
    jettyServer.start();
    serverPort = ((ServerConnector) jettyServer.getConnectors()[0]).getLocalPort();
    testRestTemplate = new TestRestTemplate(new RestTemplateBuilder().rootUri("http://localhost:" + serverPort + CONTEXT_PATH));
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) Server(org.eclipse.jetty.server.Server) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) BeforeClass(org.junit.BeforeClass)

Aggregations

RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)37 Test (org.junit.jupiter.api.Test)22 RestTemplate (org.springframework.web.client.RestTemplate)21 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)5 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)4 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 Test (org.junit.Test)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 LocalHostUriTemplateHandler (org.springframework.boot.test.web.client.LocalHostUriTemplateHandler)3 Bean (org.springframework.context.annotation.Bean)3 RestTemplateResponseErrorHandler (edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 MockServerRestTemplateCustomizer (org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 RequestExpectationManager (org.springframework.test.web.client.RequestExpectationManager)2 Builder (io.micrometer.core.instrument.Timer.Builder)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1