Search in sources :

Example 1 with RequestExpectationManager

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

the class RootUriRequestExpectationManagerTests method forRestTemplateWhenUsingRootUriTemplateHandlerShouldReturnRootUriRequestExpectationManager.

@Test
void forRestTemplateWhenUsingRootUriTemplateHandlerShouldReturnRootUriRequestExpectationManager() {
    RestTemplate restTemplate = new RestTemplateBuilder().rootUri(this.uri).build();
    RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate, this.delegate);
    assertThat(actual).isInstanceOf(RootUriRequestExpectationManager.class);
    assertThat(actual).extracting("rootUri").isEqualTo(this.uri);
}
Also used : RequestExpectationManager(org.springframework.test.web.client.RequestExpectationManager) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with RequestExpectationManager

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

the class MockServerRestTemplateCustomizer method customize.

@Override
public void customize(RestTemplate restTemplate) {
    RequestExpectationManager expectationManager = createExpectationManager();
    if (this.detectRootUri) {
        expectationManager = RootUriRequestExpectationManager.forRestTemplate(restTemplate, expectationManager);
    }
    MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build(expectationManager);
    this.expectationManagers.put(restTemplate, expectationManager);
    this.servers.put(restTemplate, server);
}
Also used : SimpleRequestExpectationManager(org.springframework.test.web.client.SimpleRequestExpectationManager) RequestExpectationManager(org.springframework.test.web.client.RequestExpectationManager) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer)

Example 3 with RequestExpectationManager

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

the class MockServerRestTemplateCustomizerTests method getExpectationManagersShouldReturnExpectationManagers.

@Test
void getExpectationManagersShouldReturnExpectationManagers() {
    RestTemplate template1 = new RestTemplate();
    RestTemplate template2 = new RestTemplate();
    this.customizer.customize(template1);
    this.customizer.customize(template2);
    RequestExpectationManager manager1 = this.customizer.getExpectationManagers().get(template1);
    RequestExpectationManager manager2 = this.customizer.getExpectationManagers().get(template2);
    assertThat(this.customizer.getServer(template1)).extracting("expectationManager").isEqualTo(manager1);
    assertThat(this.customizer.getServer(template2)).extracting("expectationManager").isEqualTo(manager2);
}
Also used : SimpleRequestExpectationManager(org.springframework.test.web.client.SimpleRequestExpectationManager) RequestExpectationManager(org.springframework.test.web.client.RequestExpectationManager) UnorderedRequestExpectationManager(org.springframework.test.web.client.UnorderedRequestExpectationManager) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with RequestExpectationManager

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

the class RootUriRequestExpectationManagerTests method forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager.

@Test
void forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager() {
    RestTemplate restTemplate = new RestTemplateBuilder().build();
    RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate, this.delegate);
    assertThat(actual).isSameAs(this.delegate);
}
Also used : RequestExpectationManager(org.springframework.test.web.client.RequestExpectationManager) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

RequestExpectationManager (org.springframework.test.web.client.RequestExpectationManager)4 Test (org.junit.jupiter.api.Test)3 RestTemplate (org.springframework.web.client.RestTemplate)3 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)2 SimpleRequestExpectationManager (org.springframework.test.web.client.SimpleRequestExpectationManager)2 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)1 UnorderedRequestExpectationManager (org.springframework.test.web.client.UnorderedRequestExpectationManager)1