use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestChunkDecoder method testTooLongChunkHeader.
@Test
public void testTooLongChunkHeader() throws Exception {
final String s = "5; and some very looooong comment\r\n12345\r\n0\r\n";
final ReadableByteChannel channel1 = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
final BasicHttpTransportMetrics metrics1 = new BasicHttpTransportMetrics();
final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256);
final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);
final ByteBuffer dst = ByteBuffer.allocate(1024);
while (dst.hasRemaining() && !decoder1.isCompleted()) {
decoder1.read(dst);
}
Assertions.assertEquals("12345", CodecTestUtils.convert(dst));
Assertions.assertTrue(decoder1.isCompleted());
final ReadableByteChannel channel2 = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256, 10);
final BasicHttpTransportMetrics metrics2 = new BasicHttpTransportMetrics();
final ChunkDecoder decoder2 = new ChunkDecoder(channel2, inbuf2, metrics2);
dst.clear();
Assertions.assertThrows(MessageConstraintException.class, () -> decoder2.read(dst));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestChunkDecoder method testInvalidConstructor.
@Test
public void testInvalidConstructor() {
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { "stuff;", "more stuff" }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
Assertions.assertThrows(NullPointerException.class, () -> new ChunkDecoder(null, null, null));
Assertions.assertThrows(NullPointerException.class, () -> new ChunkDecoder(channel, inbuf, null));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestChunkDecoder method testEndOfStreamConditionReadingFooters.
@Test
public void testEndOfStreamConditionReadingFooters() throws Exception {
final String s = "10\r\n1234567890123456\r\n" + "5\r\n12345\r\n5\r\n12345\r\n0\r\n";
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
final ByteBuffer dst = ByteBuffer.allocate(1024);
int bytesRead = 0;
while (dst.hasRemaining() && !decoder.isCompleted()) {
final int i = decoder.read(dst);
if (i > 0) {
bytesRead += i;
}
}
Assertions.assertEquals(26, bytesRead);
Assertions.assertEquals("12345678901234561234512345", CodecTestUtils.convert(dst));
Assertions.assertTrue(decoder.isCompleted());
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestChunkDecoder method testInvalidInput.
@Test
public void testInvalidInput() throws Exception {
final String s = "10;key=\"value\"\r\n1234567890123456\r\n" + "5\r\n12345\r\n5\r\n12345\r\n0\r\nFooter1 abcde\r\n\r\n";
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
Assertions.assertThrows(NullPointerException.class, () -> decoder.read(null));
}
Aggregations