Examples of SessionInputBufferMock


Examples of org.apache.http.impl.SessionInputBufferMock

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

        SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(),
                params);
        HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);

        CharArrayBuffer buf = new CharArrayBuffer(64);
        for (int i = 0; i < 10; i++) {
            buf.clear();
            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());
        long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

        Assert.assertEquals(expected, bytesRead);
    }

    @Test
    public void testInvalidCharArrayBuffer() throws Exception {
        SessionInputBufferMock inbuffer = new SessionInputBufferMock(new byte[] {});
        try {
            inbuffer.readLine(null);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
            long bytesRead = inbuffer.getMetrics().getBytesTransferred();
            Assert.assertEquals(0, bytesRead);
        }
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

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

        SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp);
        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());
        long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(out.length, bytesRead);
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

        HttpParams params = new BasicHttpParams();
        String s = "a very looooooooooooooooooooooooooooooooooooooong line\r\n     ";
        byte[] tmp = s.getBytes("US-ASCII");
        // no limit
        params.setIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, 0);
        SessionInputBufferMock inbuffer1 = new SessionInputBufferMock(tmp, 5, params);
        Assert.assertNotNull(inbuffer1.readLine());
        long bytesRead = inbuffer1.getMetrics().getBytesTransferred();
        Assert.assertEquals(60, bytesRead);

        // 15 char limit
        params.setIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, 15);
        SessionInputBufferMock inbuffer2 = new SessionInputBufferMock(tmp, 5, params);
        try {
            inbuffer2.readLine();
            Assert.fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
            bytesRead = inbuffer2.getMetrics().getBytesTransferred();
            Assert.assertEquals(20, bytesRead);
        }
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

        long expected = ((s1.getBytes("UTF-8").length + 2)+
                (s2.getBytes("UTF-8").length + 2) +
                (s3.getBytes("UTF-8").length + 2)) * 10;
        Assert.assertEquals(expected, bytesWritten);

        SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), params);

        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());
        long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

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

        SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(), params);

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

Examples of org.apache.http.impl.SessionInputBufferMock

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

        SessionInputBufferMock inbuffer = new SessionInputBufferMock(
                outbuffer.getData(),
                params);
        HttpProtocolParams.setHttpElementCharset(params, Consts.ISO_8859_1.name());

        CharArrayBuffer buf = new CharArrayBuffer(64);
        for (int i = 0; i < 10; i++) {
            buf.clear();
            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());
        long bytesRead = inbuffer.getMetrics().getBytesTransferred();
        Assert.assertEquals(expected, bytesRead);
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

        BasicHttpParams params = new BasicHttpParams();
        HttpProtocolParams.setHttpElementCharset(params, "UTF-8");

        // Action with report
        HttpProtocolParams.setMalformedInputAction(params, CodingErrorAction.REPORT);
        SessionInputBufferMock inbuffer = new SessionInputBufferMock(tmp, params);
        try {
            inbuffer.readLine(buf);
            Assert.fail("Expected CharacterCodingException");
        } catch (CharacterCodingException e) {
        }

        // Action with replace
        HttpProtocolParams.setMalformedInputAction(params, CodingErrorAction.REPLACE);
        inbuffer = new SessionInputBufferMock(tmp, params);
        try {
            inbuffer.readLine(buf);
        } catch (CharacterCodingException e) {
            Assert.fail("Unexpected CharacterCodingException");
        }

        // Action with ignore
        HttpProtocolParams.setMalformedInputAction(params, CodingErrorAction.IGNORE);
        inbuffer = new SessionInputBufferMock(tmp, params);
        try {
            inbuffer.readLine();
        } catch (IOException e) {
            Assert.fail("Unexpected CharacterCodingException");
        }
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

        }
    }

    @Test
    public void testInvalidCharArrayBuffer() throws Exception {
        SessionInputBufferMock inbuffer = new SessionInputBufferMock(new byte[] {});
        try {
            inbuffer.readLine(null);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
            long bytesRead = inbuffer.getMetrics().getBytesTransferred();
            Assert.assertEquals(0, bytesRead);
        }
    }
View Full Code Here

Examples of org.apache.http.impl.SessionInputBufferMock

            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        new SessionInputBufferMock(in, 10);
        try {
            new SessionInputBufferMock(in, -10);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        try {
            new SessionOutputBufferMock(out, -10);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        try {
            new SessionInputBufferMock((InputStream)null, 1024);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        try {
            new SessionInputBufferMock(in, 10, null);
            Assert.fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.