use of org.apache.http.entity.BasicHttpEntity in project knox by apache.
the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_OB__C1_XC__C2_AC__EE.
// C1 PC/OB; C1 XC; C2 AC; EE
@Test(expected = IOException.class)
public void testS_C1_PC_OB__C1_XC__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();
}
use of org.apache.http.entity.BasicHttpEntity in project knox by apache.
the class PartiallyRepeatableHttpEntityTest method testS_C1_FC_IB__C1_XC__C2_FC.
// C1 FC/IB; C1 XC; C2 FC.
@Test
public void testS_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 = byteRead(stream, -1);
assertThat(text, is("0123456789"));
stream.close();
stream = replay.getContent();
text = byteRead(stream, -1);
assertThat(text, is("0123456789"));
}
use of org.apache.http.entity.BasicHttpEntity in project knox by apache.
the class PartiallyRepeatableHttpEntityTest method testGetContentEncoding.
@Test
public void testGetContentEncoding() 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.getContentEncoding(), nullValue());
basic = new BasicHttpEntity();
basic.setContent(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
basic.setContentEncoding(StandardCharsets.UTF_8.name());
replay = new PartiallyRepeatableHttpEntity(basic, 5);
assertThat(replay.getContentEncoding().getValue(), is(StandardCharsets.UTF_8.name()));
}
use of org.apache.http.entity.BasicHttpEntity in project knox by apache.
the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_IB__C2_PC_IB__C2_PC_IB.
// C1 PC/IB; C2 PC/IB; C1 PC/IB; C2 PC/IB - Back and forth before buffer overflow is OK.
@Test
public void testS_C1_PC_IB__C2_PC_IB__C2_PC_IB() throws IOException {
String data = "0123456789";
BasicHttpEntity basic;
PartiallyRepeatableHttpEntity replay;
InputStream stream1, stream2;
String text;
basic = new BasicHttpEntity();
basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
replay = new PartiallyRepeatableHttpEntity(basic, 20);
stream1 = replay.getContent();
text = byteRead(stream1, 3);
assertThat(text, is("012"));
stream2 = replay.getContent();
text = byteRead(stream2, 4);
assertThat(text, is("0123"));
text = byteRead(stream1, 3);
assertThat(text, is("345"));
}
use of org.apache.http.entity.BasicHttpEntity in project knox by apache.
the class PartiallyRepeatableHttpEntityTest method testS_C1_PC_IB__C2_FC.
// C1 PC/IB; C2 FC.
@Test
public void testS_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 = byteRead(stream, 4);
assertThat(text, is("0123"));
stream.close();
stream = replay.getContent();
text = byteRead(stream, -1);
assertThat(text, is("0123456789"));
}
Aggregations