use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestAbstractBinAsyncEntityProducer method testProduceDataNoBuffering.
@Test
public void testProduceDataNoBuffering() throws Exception {
final AsyncEntityProducer producer = new ChunkByteAsyncEntityProducer(0, ContentType.TEXT_PLAIN, new byte[] { '1', '2', '3' }, new byte[] { '4', '5', '6' });
Assertions.assertEquals(-1, producer.getContentLength());
Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
Assertions.assertNull(producer.getContentEncoding());
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
producer.produce(streamChannel);
Assertions.assertTrue(byteChannel.isOpen());
Assertions.assertEquals("123", byteChannel.dump(StandardCharsets.US_ASCII));
producer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("456", byteChannel.dump(StandardCharsets.US_ASCII));
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestAbstractCharAsyncEntityProducer method testProduceDataWithBuffering.
@Test
public void testProduceDataWithBuffering() throws Exception {
final AsyncEntityProducer producer = new ChunkCharAsyncEntityProducer(256, 5, ContentType.TEXT_PLAIN, "this", " and that", "all", " sorts of stuff");
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
producer.produce(streamChannel);
Assertions.assertTrue(byteChannel.isOpen());
Assertions.assertEquals("", byteChannel.dump(StandardCharsets.US_ASCII));
producer.produce(streamChannel);
Assertions.assertTrue(byteChannel.isOpen());
Assertions.assertEquals("this and that", byteChannel.dump(StandardCharsets.US_ASCII));
producer.produce(streamChannel);
Assertions.assertTrue(byteChannel.isOpen());
Assertions.assertEquals("", byteChannel.dump(StandardCharsets.US_ASCII));
producer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("all sorts of stuff", byteChannel.dump(StandardCharsets.US_ASCII));
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestBasicAsyncEntityProducer method testTextContentRepeatable.
@Test
public void testTextContentRepeatable() throws Exception {
final AsyncEntityProducer producer = new BasicAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
Assertions.assertEquals(3, producer.getContentLength());
Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
Assertions.assertNull(producer.getContentEncoding());
for (int i = 0; i < 3; i++) {
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
producer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
producer.releaseResources();
}
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestDigestingEntityProducer method testProduceData.
@Test
public void testProduceData() throws Exception {
final DigestingEntityProducer producer = new DigestingEntityProducer("MD5", new StringAsyncEntityProducer("12345", ContentType.TEXT_PLAIN));
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final BasicDataStreamChannel dataStreamChannel = new BasicDataStreamChannel(byteChannel);
while (byteChannel.isOpen()) {
producer.produce(dataStreamChannel);
}
Assertions.assertEquals("12345", byteChannel.dump(StandardCharsets.US_ASCII));
final List<Header> trailers = dataStreamChannel.getTrailers();
Assertions.assertNotNull(trailers);
Assertions.assertEquals(2, trailers.size());
Assertions.assertEquals("digest-algo", trailers.get(0).getName());
Assertions.assertEquals("MD5", trailers.get(0).getValue());
Assertions.assertEquals("digest", trailers.get(1).getName());
Assertions.assertEquals("827ccb0eea8a706c4c34a16891f84e7b", trailers.get(1).getValue());
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestFileAsyncEntityProducer method testTextContentRepeatable.
@Test
public void testTextContentRepeatable() throws Exception {
final AsyncEntityProducer producer = new FileEntityProducer(tempFile, ContentType.TEXT_PLAIN);
Assertions.assertEquals(6, producer.getContentLength());
Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
Assertions.assertNull(producer.getContentEncoding());
for (int i = 0; i < 3; i++) {
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
producer.produce(streamChannel);
producer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("abcdef", byteChannel.dump(StandardCharsets.US_ASCII));
producer.releaseResources();
}
}
Aggregations