Search in sources :

Example 31 with BasicHttpEntity

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

the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_OB__C2_AC__EE.

// C1 PC/OB; C2 AC; EE
@Test(expected = IOException.class)
public void testS_C1_PC_OB__C2_AC__EE() 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, 5);
    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();
    replay.getContent();
}
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 32 with BasicHttpEntity

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

the class PartiallyRepeatableHttpEntityTest method testIsRepeatable.

@Test
public void testIsRepeatable() throws Exception {
    String text = "0123456789";
    BasicHttpEntity basic;
    PartiallyRepeatableHttpEntity replay;
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
    replay = new PartiallyRepeatableHttpEntity(basic);
    assertThat(replay.isRepeatable(), is(true));
    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
    BufferedHttpEntity buffered = new BufferedHttpEntity(basic);
    replay = new PartiallyRepeatableHttpEntity(buffered);
    assertThat(replay.isRepeatable(), is(true));
}
Also used : BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 33 with BasicHttpEntity

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

the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_IB__C1_XC__C2_FC.

// C1 PC/IB; C1 XC; C2 FC.
@Test
public void testS_C1_PC_IB__C1_XC__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 = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();
    stream = replay.getContent();
    text = byteRead(stream, -1);
    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 34 with BasicHttpEntity

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

the class PartiallyRepeatableHttpEntityTest method testWriteTo.

@Test
public void testWriteTo() 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);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    replay.writeTo(buffer);
    String output = new String(buffer.toByteArray(), StandardCharsets.UTF_8);
    assertThat(output, is(input));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 35 with BasicHttpEntity

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

the class PartiallyRepeatableHttpEntityTest method testB_C1_FC_IB__C1_XC__C2_FC.

// C1 FC/IB; C1 XC; C2 FC.
@Test
public void testB_C1_FC_IB__C1_XC__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, -1, 3);
    assertThat(text, is("0123456789"));
    stream.close();
    stream = replay.getContent();
    text = blockRead(stream, StandardCharsets.UTF_8, -1, 3);
    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)

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