Example usage for org.springframework.boot.test.web.client TestRestTemplate setUriTemplateHandler

List of usage examples for org.springframework.boot.test.web.client TestRestTemplate setUriTemplateHandler

Introduction

In this page you can find the example usage for org.springframework.boot.test.web.client TestRestTemplate setUriTemplateHandler.

Prototype

public void setUriTemplateHandler(UriTemplateHandler handler) 

Source Link

Document

Configure the UriTemplateHandler to use to expand URI templates.

Usage

From source file:com.redhat.ipaas.runtime.ITConfig.java

@Bean
public TestRestTemplate restTemplate(ObjectProvider<RestTemplateBuilder> builderProvider,
        Environment environment) {
    RestTemplateBuilder builder = builderProvider.getIfAvailable();
    TestRestTemplate template = builder == null ? new TestRestTemplate()
            : new TestRestTemplate(builder.build());
    template.setUriTemplateHandler(new LocalHostUriTemplateHandler(environment));
    return template;
}

From source file:com.create.application.configuration.TestConfiguration.java

@Bean
@Lazy//www.  ja v a  2 s  .co m
public TestRestTemplate authenticatedUserTestRestTemplate(OAuth2RestTemplate authenticatedUserRestTemplate,
        LocalHostUriTemplateHandler localHostUriTemplateHandler, HttpClientOption[] httpClientOptions) {

    final TestRestTemplate restTemplate = new TestRestTemplate(authenticatedUserRestTemplate, null, null,
            httpClientOptions);
    restTemplate.setUriTemplateHandler(localHostUriTemplateHandler);
    return restTemplate;
}

From source file:org.springframework.boot.test.web.client.TestRestTemplateTests.java

private void verifyRelativeUriHandling(TestRestTemplateCallback callback) throws IOException {
    ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
    MockClientHttpRequest request = new MockClientHttpRequest();
    request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK));
    URI absoluteUri = URI.create("http://localhost:8080/a/b/c.txt?param=%7Bsomething%7D");
    given(requestFactory.createRequest(eq(absoluteUri), (HttpMethod) any())).willReturn(request);
    RestTemplate delegate = new RestTemplate();
    TestRestTemplate template = new TestRestTemplate(delegate);
    delegate.setRequestFactory(requestFactory);
    LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment());
    template.setUriTemplateHandler(uriTemplateHandler);
    callback.doWithTestRestTemplate(template, URI.create("/a/b/c.txt?param=%7Bsomething%7D"));
    verify(requestFactory).createRequest(eq(absoluteUri), (HttpMethod) any());
}