Package org.apache.http

Examples of org.apache.http.ReadableByteChannelMock


    @Test(expected=MalformedChunkCodingException.class)
    public void testMissingLastCRLF() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "5\r\n12345\r\n5\r\n12345";
        final ReadableByteChannel channel = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
View Full Code Here


    @Test(expected=ConnectionClosedException.class)
    public void testMissingClosingChunk() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "5\r\n12345\r\n5\r\n12345\r\n";
        final ReadableByteChannel channel = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
View Full Code Here

    @Test
    public void testReadingWitSmallBuffer() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "40\r\n12345678901234561234567890123456" +
                "12345678901234561234567890123456\r\n0\r\n";
        final ReadableByteChannel channel = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
View Full Code Here

    @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}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
View Full Code Here

    }

    @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}, Consts.ASCII);

        final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.DEFAULT, null, null);
        final HttpTransportMetricsImpl metrics1 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);

        final ByteBuffer dst = ByteBuffer.allocate(1024);

        while (dst.hasRemaining() && !decoder1.isCompleted()) {
            decoder1.read(dst);
        }
        Assert.assertEquals("12345", CodecTestUtils.convert(dst));
        Assert.assertTrue(decoder1.isCompleted());

        final ReadableByteChannel channel2 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);

        final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.lineLen(10), null, null);
        final HttpTransportMetricsImpl metrics2 = new HttpTransportMetricsImpl();
View Full Code Here

    public void testTooLongFooter() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "0\r\nFooter1: looooooooooooooooooooooooooooooooooooooooooooooooooooooog\r\n\r\n";
//        final String s = "10\r\n1234567890123456\r\n" +
//                "0\r\nFooter1: looooooooooooooooooooooooooooooooooooooooog\r\n   \r\n  fghij\r\n\r\n";
        final ReadableByteChannel channel1 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.DEFAULT, Consts.ASCII);
        final HttpTransportMetricsImpl metrics1 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);

        final ByteBuffer dst = ByteBuffer.allocate(1024);

        final int bytesRead = decoder1.read(dst);
        Assert.assertEquals(16, bytesRead);
        Assert.assertEquals("1234567890123456", CodecTestUtils.convert(dst));
        final Header[] footers = decoder1.getFooters();
        Assert.assertNotNull(footers);
        Assert.assertEquals(1, footers.length);

        final ReadableByteChannel channel2 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.lineLen(25), Consts.ASCII);
        final HttpTransportMetricsImpl metrics2 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder2 = new ChunkDecoder(channel2, inbuf2, metrics2);
View Full Code Here

    @Test
    public void testTooLongFoldedFooter() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "0\r\nFooter1: blah\r\n  blah\r\n  blah\r\n  blah\r\n  blah\r\n  blah\r\n  blah\r\n  blah\r\n\r\n";
        final ReadableByteChannel channel1 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.DEFAULT, Consts.ASCII);
        final HttpTransportMetricsImpl metrics1 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);

        final ByteBuffer dst = ByteBuffer.allocate(1024);

        final int bytesRead = decoder1.read(dst);
        Assert.assertEquals(16, bytesRead);
        Assert.assertEquals("1234567890123456", CodecTestUtils.convert(dst));
        final Header[] footers = decoder1.getFooters();
        Assert.assertNotNull(footers);
        Assert.assertEquals(1, footers.length);

        final MessageConstraints constraints = MessageConstraints.lineLen(25);
        final ReadableByteChannel channel2 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256,
                constraints, Consts.ASCII);
        final HttpTransportMetricsImpl metrics2 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder2 = new ChunkDecoder(channel2, inbuf2, constraints, metrics2);
View Full Code Here

    @Test
    public void testTooManyFooters() throws Exception {
        final String s = "10\r\n1234567890123456\r\n" +
                "0\r\nFooter1: blah\r\nFooter2: blah\r\nFooter3: blah\r\nFooter4: blah\r\n\r\n";
        final ReadableByteChannel channel1 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf1 = new SessionInputBufferImpl(1024, 256,
                MessageConstraints.DEFAULT, Consts.ASCII);
        final HttpTransportMetricsImpl metrics1 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder1 = new ChunkDecoder(channel1, inbuf1, metrics1);

        final ByteBuffer dst = ByteBuffer.allocate(1024);

        final int bytesRead = decoder1.read(dst);
        Assert.assertEquals(16, bytesRead);
        Assert.assertEquals("1234567890123456", CodecTestUtils.convert(dst));
        final Header[] footers = decoder1.getFooters();
        Assert.assertNotNull(footers);
        Assert.assertEquals(4, footers.length);

        final MessageConstraints constraints = MessageConstraints.custom()
                .setMaxHeaderCount(3).build();
        final ReadableByteChannel channel2 = new ReadableByteChannelMock(
                new String[] {s}, Consts.ASCII);
        final SessionInputBuffer inbuf2 = new SessionInputBufferImpl(1024, 256,
                constraints, Consts.ASCII);
        final HttpTransportMetricsImpl metrics2 = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder2 = new ChunkDecoder(channel2, inbuf2, constraints, metrics2);
View Full Code Here

        }
    }

    @Test
    public void testInvalidConstructor() {
        final ReadableByteChannel channel = new ReadableByteChannelMock(
                new String[] {"stuff;", "more stuff"}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        try {
            new ChunkDecoder(null, null, null);
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    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}, Consts.ASCII);

        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
View Full Code Here

TOP

Related Classes of org.apache.http.ReadableByteChannelMock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.