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

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

Introduction

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

Prototype

public TestRestTemplate(RestTemplateBuilder builder, String username, String password,
        HttpClientOption... httpClientOptions) 

Source Link

Document

Create a new TestRestTemplate instance with the specified credentials.

Usage

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

@Bean
@Lazy//from   w w  w.  jav  a  2 s .  c o 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.TestRestTemplate.java

/**
 * Creates a new {@code TestRestTemplate} with the same configuration as this one,
 * except that it will send basic authorization headers using the given
 * {@code username} and {@code password}.
 * @param username the username/*  w w  w .j  a  va 2  s .co m*/
 * @param password the password
 * @return the new template
 * @since 1.4.1
 */
public TestRestTemplate withBasicAuth(String username, String password) {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(getRestTemplate().getMessageConverters());
    restTemplate.setInterceptors(getRestTemplate().getInterceptors());
    restTemplate.setRequestFactory(getRestTemplate().getRequestFactory());
    restTemplate.setUriTemplateHandler(getRestTemplate().getUriTemplateHandler());
    TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplate, username, password,
            this.httpClientOptions);
    testRestTemplate.getRestTemplate().setErrorHandler(getRestTemplate().getErrorHandler());
    return testRestTemplate;
}