Example usage for org.springframework.mock.http.client MockClientHttpRequest MockClientHttpRequest

List of usage examples for org.springframework.mock.http.client MockClientHttpRequest MockClientHttpRequest

Introduction

In this page you can find the example usage for org.springframework.mock.http.client MockClientHttpRequest MockClientHttpRequest.

Prototype

public MockClientHttpRequest() 

Source Link

Document

Default constructor.

Usage

From source file:com.gopivotal.cla.github.RateLimitingClientHttpRequestInterceptorTest.java

@Test
public void noBlock() throws IOException {
    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    when(execution.execute(request, new byte[0])).thenReturn(response);

    this.interceptor.intercept(request, new byte[0], execution);
}

From source file:com.gopivotal.cla.github.RateLimitingClientHttpRequestInterceptorTest.java

@Test
public void block() throws InterruptedException, IOException {
    CountDownLatch latch = new CountDownLatch(1);

    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    request.setMethod(HttpMethod.GET);//  w ww .  j av  a2s .  c  om
    request.setURI(URI.create("http://localhost"));

    when(execution.execute(request, new byte[0])).thenReturn(response);

    new Thread(new Trigger(this.interceptor, latch)).start();
    latch.await();

    this.interceptor.intercept(request, new byte[0], execution);
}

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