Search in sources :

Example 1 with MockRestServiceServer

use of org.springframework.test.web.client.MockRestServiceServer 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 2 with MockRestServiceServer

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

the class RootUriRequestExpectationManagerTests method bindToWithExpectationManagerShouldReturnMockRestServiceServer.

@Test
public void bindToWithExpectationManagerShouldReturnMockRestServiceServer() throws Exception {
    RestTemplate restTemplate = new RestTemplateBuilder().build();
    MockRestServiceServer bound = RootUriRequestExpectationManager.bindTo(restTemplate, this.delegate);
    assertThat(bound).isNotNull();
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Example 3 with MockRestServiceServer

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

the class RestTemplateBuilderTests method rootUriShouldApply.

@Test
public void rootUriShouldApply() throws Exception {
    RestTemplate restTemplate = this.builder.rootUri("http://example.com").build();
    MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
    server.expect(requestTo("http://example.com/hello")).andRespond(withSuccess());
    restTemplate.getForEntity("/hello", String.class);
    server.verify();
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Example 4 with MockRestServiceServer

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

the class RootUriRequestExpectationManagerTests method bindToShouldReturnMockRestServiceServer.

@Test
public void bindToShouldReturnMockRestServiceServer() throws Exception {
    RestTemplate restTemplate = new RestTemplateBuilder().build();
    MockRestServiceServer bound = RootUriRequestExpectationManager.bindTo(restTemplate);
    assertThat(bound).isNotNull();
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Example 5 with MockRestServiceServer

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

the class RootUriRequestExpectationManagerTests method boundRestTemplateShouldPrefixRootUri.

@Test
public void boundRestTemplateShouldPrefixRootUri() {
    RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://example.com").build();
    MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
    server.expect(requestTo("/hello")).andRespond(withSuccess());
    restTemplate.getForEntity("/hello", String.class);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer) Test(org.junit.Test)

Aggregations

MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)6 Test (org.junit.Test)5 RestTemplate (org.springframework.web.client.RestTemplate)5 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)4 RequestExpectationManager (org.springframework.test.web.client.RequestExpectationManager)1 SimpleRequestExpectationManager (org.springframework.test.web.client.SimpleRequestExpectationManager)1