use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestAbstractCharAsyncEntityProducer method testProduceDataNoBuffering.
@Test
public void testProduceDataNoBuffering() throws Exception {
final AsyncEntityProducer producer = new ChunkCharAsyncEntityProducer(256, 0, ContentType.TEXT_PLAIN, "this", "this and that");
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("this", byteChannel.dump(StandardCharsets.US_ASCII));
producer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("this and that", byteChannel.dump(StandardCharsets.US_ASCII));
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestBasicAsyncEntityProducer method testTextContent.
@Test
public void testTextContent() 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());
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));
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestBasicAsyncEntityProducer method testBinaryContent.
@Test
public void testBinaryContent() throws Exception {
final AsyncEntityProducer producer = new BasicAsyncEntityProducer(new byte[] { 'a', 'b', 'c' }, ContentType.DEFAULT_BINARY);
Assertions.assertEquals(3, producer.getContentLength());
Assertions.assertEquals(ContentType.DEFAULT_BINARY.toString(), producer.getContentType());
Assertions.assertNull(producer.getContentEncoding());
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));
}
use of org.apache.hc.core5.http.nio.BasicDataStreamChannel in project httpcomponents-core by apache.
the class TestReactiveEntityProducer method testStreamThatEndsNormally.
@Test
public void testStreamThatEndsNormally() throws Exception {
final Flowable<ByteBuffer> publisher = Flowable.just(ByteBuffer.wrap(new byte[] { '1', '2', '3' }), ByteBuffer.wrap(new byte[] { '4', '5', '6' }));
final ReactiveEntityProducer entityProducer = new ReactiveEntityProducer(publisher, CONTENT_LENGTH, CONTENT_TYPE, GZIP_CONTENT_ENCODING);
final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
entityProducer.produce(streamChannel);
Assertions.assertTrue(byteChannel.isOpen(), "Should be open");
Assertions.assertEquals("123456", byteChannel.dump(StandardCharsets.US_ASCII));
entityProducer.produce(streamChannel);
Assertions.assertFalse(byteChannel.isOpen(), "Should be closed");
Assertions.assertEquals("", byteChannel.dump(StandardCharsets.US_ASCII));
Assertions.assertFalse(entityProducer.isChunked());
Assertions.assertEquals(GZIP_CONTENT_ENCODING, entityProducer.getContentEncoding());
Assertions.assertNull(entityProducer.getTrailerNames());
Assertions.assertEquals(CONTENT_LENGTH, entityProducer.getContentLength());
Assertions.assertEquals(CONTENT_TYPE.toString(), entityProducer.getContentType());
Assertions.assertFalse(entityProducer.isRepeatable());
Assertions.assertEquals(1, entityProducer.available());
entityProducer.releaseResources();
}
Aggregations