use of org.apache.hc.core5.http.nio.AsyncEntityProducer in project httpcomponents-core by apache.
the class TestStringAsyncEntityProducer method testTextContent.
@Test
public void testTextContent() throws Exception {
final AsyncEntityProducer producer = new StringAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
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.assertFalse(byteChannel.isOpen());
Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
}
use of org.apache.hc.core5.http.nio.AsyncEntityProducer 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.AsyncEntityProducer in project httpcomponents-core by apache.
the class TestAsyncEntityProducers method testPathEntityProducerWithTrailers.
@Test
public void testPathEntityProducerWithTrailers() throws IOException {
final Path path = Paths.get("src/test/resources/test-ssl.txt");
final Header header1 = new BasicHeader("Tailer1", "Value1");
final Header header2 = new BasicHeader("Tailer2", "Value2");
final AsyncEntityProducer producer = AsyncEntityProducers.create(path, ContentType.APPLICATION_OCTET_STREAM, header1, header2);
try {
Assertions.assertTrue(producer.isChunked());
Assertions.assertEquals(-1, producer.getContentLength());
Assertions.assertEquals(ContentType.APPLICATION_OCTET_STREAM.toString(), producer.getContentType());
} finally {
producer.releaseResources();
}
}
use of org.apache.hc.core5.http.nio.AsyncEntityProducer 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.AsyncEntityProducer 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));
}
Aggregations