Search in sources :

Example 41 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_FC_IB__C2_FC_IB.

@Test
public void testS_C1_FC_IB__C2_FC_IB() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);
    String output;
    output = byteRead(replay.getContent(), -1);
    assertThat(output, is(data));
    output = byteRead(replay.getContent(), -1);
    assertThat(output, is(data));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 42 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testS_C1_FC_OB__C2_AC__EE.

@Test(expected = IOException.class)
public void testS_C1_FC_OB__C2_AC__EE() throws Exception {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    String output;
    output = byteRead(replay.getContent(), -1);
    assertThat(output, is(data));
    replay.getContent();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 43 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testB_C1_PC_IB__C2_FC.

// C1 PC/IB; C2 FC.
@Test
public void testB_C1_PC_IB__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    InputStream stream;
    String text;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 20);
    stream = replay.getContent();
    text = blockRead(stream, StandardCharsets.UTF_8, 4, 1);
    assertThat(text, is("0123"));
    stream.close();
    stream = replay.getContent();
    text = blockRead(stream, StandardCharsets.UTF_8, -1, 7);
    assertThat(text, is("0123456789"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 44 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testIsChunked.

@Test
public void testIsChunked() throws Exception {
    String input = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.isChunked(), is(false));
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
    basic.setChunked(true);
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.isChunked(), is(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 45 with BasicHttpEntity

use of org.apache.http.entity.BasicHttpEntity in project knox by apache.

the class PartiallyRepeatableHttpEntityTest method testIsStreaming.

@Test
public void testIsStreaming() throws Exception {
    String input = "0123456789";
    BasicHttpEntity basic;
    InputStreamEntity streaming;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.isStreaming(), is(true));
    basic = new BasicHttpEntity();
    basic.setContent(null);
    replay = new PartiallyRepeatableHttpEntity(basic, 5);
    assertThat(replay.isStreaming(), is(false));
    streaming = new InputStreamEntity(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), 10, ContentType.TEXT_PLAIN);
    replay = new PartiallyRepeatableHttpEntity(streaming, 5);
    assertThat(replay.isStreaming(), is(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) InputStreamEntity(org.apache.http.entity.InputStreamEntity) Test(org.junit.Test)

Aggregations

BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)139 ByteArrayInputStream (java.io.ByteArrayInputStream)104 Test (org.junit.Test)89 InputStream (java.io.InputStream)60 IOException (java.io.IOException)24 HttpResponse (org.apache.http.HttpResponse)15 StatusLine (org.apache.http.StatusLine)12 BasicStatusLine (org.apache.http.message.BasicStatusLine)11 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)9 HttpException (org.apache.http.HttpException)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpContext (org.apache.http.protocol.HttpContext)8 URISyntaxException (java.net.URISyntaxException)7 Map (java.util.Map)7 URI (java.net.URI)6 Header (org.apache.http.Header)6 ProtocolVersion (org.apache.http.ProtocolVersion)6 HttpGet (org.apache.http.client.methods.HttpGet)6 ChunkedInputStream (org.apache.http.impl.io.ChunkedInputStream)6 ContentLengthInputStream (org.apache.http.impl.io.ContentLengthInputStream)6