Example usage for org.springframework.boot.test.web.client LocalHostUriTemplateHandler LocalHostUriTemplateHandler

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

Introduction

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

Prototype

public LocalHostUriTemplateHandler(Environment environment) 

Source Link

Document

Create a new LocalHostUriTemplateHandler that will generate http URIs using the given environment to determine the context path and port.

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: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());
}