Example usage for org.apache.http.client.entity UrlEncodedFormEntity isChunked

List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity isChunked

Introduction

In this page you can find the example usage for org.apache.http.client.entity UrlEncodedFormEntity isChunked.

Prototype

public boolean isChunked() 

Source Link

Usage

From source file:com.thoughtworks.go.util.HttpServiceTest.java

@Test
public void shouldSetTheAcceptHeaderWhilePostingProperties() throws Exception {
    HttpPost post = mock(HttpPost.class);
    String url = "http://url";
    when(httpClientFactory.createPost(url)).thenReturn(post);
    when(post.getURI()).thenReturn(new URI(url));
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    when(httpClient.execute(post)).thenReturn(response);

    ArgumentCaptor<UrlEncodedFormEntity> entityCaptor = ArgumentCaptor.forClass(UrlEncodedFormEntity.class);

    service.postProperty(url, "value");

    verify(post).setHeader("Confirm", "true");
    verify(post).setEntity(entityCaptor.capture());

    UrlEncodedFormEntity expected = new UrlEncodedFormEntity(
            Arrays.asList(new BasicNameValuePair("value", "value")));

    UrlEncodedFormEntity actual = entityCaptor.getValue();

    assertEquals(IOUtils.toString(expected.getContent()), IOUtils.toString(actual.getContent()));
    assertEquals(expected.getContentLength(), expected.getContentLength());
    assertEquals(expected.getContentType(), expected.getContentType());
    assertEquals(expected.getContentEncoding(), expected.getContentEncoding());
    assertEquals(expected.isChunked(), expected.isChunked());
}