Package org.apache.http.impl

Examples of org.apache.http.impl.SessionInputBufferMock


        for (final String teststr : teststrs) {
            expected += (teststr.length() + 2/*CRLF*/);
        }
        Assert.assertEquals(expected, bytesWritten);

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), 1024);

        for (final String teststr : teststrs) {
            Assert.assertEquals(teststr, inbuffer.readLine());
        }
        Assert.assertNull(inbuffer.readLine());
        Assert.assertNull(inbuffer.readLine());
        final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here


        Assert.assertEquals(out.length, tmp.length);
        for (int i = 0; i < out.length; i++) {
            Assert.assertEquals(out[i], tmp[i]);
        }

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp);

        // these read operations will have no effect
        Assert.assertEquals(0, inbuffer.read(null, 0, 10));
        Assert.assertEquals(0, inbuffer.read(null));
        long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(0, bytesRead);

        final byte[] in = new byte[40];
        off = 0;
        remaining = in.length;
        while (remaining > 0) {
            int chunk = 10;
            if (chunk > remaining) {
                chunk = remaining;
            }
            final int l = inbuffer.read(in, off, chunk);
            if (l == -1) {
                break;
            }
            off += l;
            remaining -= l;
        }
        for (int i = 0; i < out.length; i++) {
            Assert.assertEquals(out[i], in[i]);
        }
        Assert.assertEquals(-1, inbuffer.read(tmp));
        Assert.assertEquals(-1, inbuffer.read(tmp));
        bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(out.length, bytesRead);
    }
View Full Code Here

        Assert.assertEquals(out.length, tmp.length);
        for (int i = 0; i < out.length; i++) {
            Assert.assertEquals(out[i], tmp[i]);
        }

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp);
        final byte[] in = new byte[40];
        for (int i = 0; i < in.length; i++) {
            in[i] = (byte)inbuffer.read();
        }
        for (int i = 0; i < out.length; i++) {
            Assert.assertEquals(out[i], in[i]);
        }
        Assert.assertEquals(-1, inbuffer.read());
        Assert.assertEquals(-1, inbuffer.read());
        final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(out.length, bytesRead);
    }
View Full Code Here

    @Test
    public void testLineLimit() throws Exception {
        final String s = "a very looooooooooooooooooooooooooooooooooooooooooong line\r\n";
        final byte[] tmp = s.getBytes(Consts.ASCII);
        // no limit
        final SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 5,
                MessageConstraints.DEFAULT);
        Assert.assertNotNull(inbuffer1.readLine());
        final long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
        Assert.assertEquals(60, bytesRead);

        // 15 char limit
        final SessionInputBufferMock inbuffer2 = new SessionInputBufferMock(tmp, 5,
                MessageConstraints.lineLen(15));
        try {
            inbuffer2.readLine();
            Assert.fail("MessageConstraintException expected");
        } catch (MessageConstraintException ex) {
        }
    }
View Full Code Here

    @Test
    public void testLineLimit2() throws Exception {
        final String s = "just a line\r\n";
        final byte[] tmp = s.getBytes(Consts.ASCII);
        // no limit
        final SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 25,
                MessageConstraints.DEFAULT);
        Assert.assertNotNull(inbuffer1.readLine());
        final long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
        Assert.assertEquals(13, bytesRead);

        // 10 char limit
        final SessionInputBufferMock inbuffer2 = new SessionInputBufferMock(tmp, 25,
                MessageConstraints.lineLen(10));
        try {
            inbuffer2.readLine();
            Assert.fail("MessageConstraintException expected");
        } catch (MessageConstraintException ex) {
        }
    }
View Full Code Here

    @Test
    public void testReadLineFringeCase1() throws Exception {
        final String s = "abc\r\n";
        final byte[] tmp = s.getBytes(Consts.ASCII);
        final SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 128);
        Assert.assertEquals('a', inbuffer1.read());
        Assert.assertEquals('b', inbuffer1.read());
        Assert.assertEquals('c', inbuffer1.read());
        Assert.assertEquals('\r', inbuffer1.read());
        Assert.assertEquals("", inbuffer1.readLine());
    }
View Full Code Here

        final long expected = ((s1.getBytes(Consts.UTF_8).length + 2)+
                (s2.getBytes(Consts.UTF_8).length + 2) +
                (s3.getBytes(Consts.UTF_8).length + 2)) * 10;
        Assert.assertEquals(expected, bytesWritten);

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), Consts.UTF_8);

        for (int i = 0; i < 10; i++) {
            Assert.assertEquals(s1, inbuffer.readLine());
            Assert.assertEquals(s2, inbuffer.readLine());
            Assert.assertEquals(s3, inbuffer.readLine());
        }
        Assert.assertNull(inbuffer.readLine());
        Assert.assertNull(inbuffer.readLine());
        final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here

        final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        chbuffer.append(s);
        outbuffer.writeLine(chbuffer);
        outbuffer.flush();

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), Consts.UTF_8);

        Assert.assertEquals(s, inbuffer.readLine());
    }
View Full Code Here

        outbuffer.flush();
        final long bytesWritten = outbuffer.getMetrics().getBytesTransferred();
        final long expected = ((s1.toString().getBytes(Consts.ISO_8859_1).length + 2)) * 10 + 2;
        Assert.assertEquals(expected, bytesWritten);

        final SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), Consts.ISO_8859_1);

        final CharArrayBuffer buf = new CharArrayBuffer(64);
        for (int i = 0; i < 10; i++) {
            buf.clear();
            final int len = inbuffer.readLine(buf);
            Assert.assertEquals(len, SWISS_GERMAN_HELLO.length);
            Assert.assertEquals(s1, buf.toString());
        }
        buf.clear();
        Assert.assertEquals("", inbuffer.readLine());
        Assert.assertNull(inbuffer.readLine());
        Assert.assertNull(inbuffer.readLine());
        final long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here

public class TestContentLengthInputStream {

    @Test
    public void testConstructors() throws Exception {
        final ContentLengthInputStream in = new ContentLengthInputStream(
                new SessionInputBufferMock(new byte[] {}), 0);
        in.close();
        try {
            new ContentLengthInputStream(null, 10);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (final IllegalArgumentException ex) {
            // expected
        }
        try {
            new ContentLengthInputStream(new SessionInputBufferMock(new byte[] {}), -10);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (final IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.SessionInputBufferMock

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.