Package org.apache.http.mockup

Examples of org.apache.http.mockup.HttpDataReceiverMockup


        assertEquals(-1, instream.read());       
    }
   
    public void testClosedCondition() throws Exception {
        byte[] input = new byte[] {'a', 'b', 'c'};
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
        HttpDataInputStream instream = new HttpDataInputStream(receiver);

        instream.close();
        instream.close();
       
View Full Code Here


        assertEquals(-1, instream.read());       
    }

    public void testAvailable() throws Exception {
        byte[] input = new byte[] {'a', 'b', 'c'};
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
        HttpDataInputStream instream = new HttpDataInputStream(receiver);
        assertTrue(instream.available() > 0);       
    }
View Full Code Here

        = "123456789012345612345";
   
    // Test for when buffer is larger than chunk size
    public void testChunkedInputStreamLargeBuffer() throws IOException {
        ChunkedInputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(CHUNKED_INPUT, CONTENT_CHARSET)));
        byte[] buffer = new byte[300];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len;
        while ((len = in.read(buffer)) > 0) {
View Full Code Here

    }       

    //Test for when buffer is smaller than chunk size.
    public void testChunkedInputStreamSmallBuffer() throws IOException {
        ChunkedInputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                            EncodingUtils.getBytes(CHUNKED_INPUT, CONTENT_CHARSET)));

        byte[] buffer = new byte[7];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len;
View Full Code Here

       
    // One byte read
    public void testChunkedInputStreamOneByteRead() throws IOException {
        String s = "5\r\n01234\r\n5\r\n56789\r\n0\r\n";
        ChunkedInputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
        int ch;
        int i = '0';
        while ((ch = in.read()) != -1) {
            assertEquals(i, ch);
View Full Code Here

    }

    public void testChunkedInputStreamClose() throws IOException {
        String s = "5\r\n01234\r\n5\r\n56789\r\n0\r\n";
        ChunkedInputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
        in.close();
        in.close();
        try {
            in.read();
View Full Code Here

    // Missing \r\n at the end of the first chunk
    public void testCorruptChunkedInputStreamMissingCRLF() throws IOException {
        String s = "5\r\n012345\r\n56789\r\n0\r\n";
        InputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
        byte[] buffer = new byte[300];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int len;
        try {
View Full Code Here

    // Missing LF
    public void testCorruptChunkedInputStreamMissingLF() throws IOException {
        String s = "5\r01234\r\n5\r\n56789\r\n0\r\n";
        InputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
        try {
            in.read();
            fail("MalformedChunkCodingException should have been thrown");
        } catch(MalformedChunkCodingException e) {
View Full Code Here

    }

    // Missing closing chunk
    public void testCorruptChunkedInputStreamNoClosingChunk() throws IOException {
        InputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(new byte[] {}));
        try {
            in.read();
            fail("MalformedChunkCodingException should have been thrown");
        } catch(MalformedChunkCodingException e) {
            /* expected exception */
 
View Full Code Here

    // Invalid chunk size
    public void testCorruptChunkedInputStreamInvalidSize() throws IOException {
        String s = "whatever\r\n01234\r\n5\r\n56789\r\n0\r\n";
        InputStream in = new ChunkedInputStream(
                new HttpDataReceiverMockup(
                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
        try {
            in.read();
            fail("MalformedChunkCodingException should have been thrown");
        } catch(MalformedChunkCodingException e) {
View Full Code Here

TOP

Related Classes of org.apache.http.mockup.HttpDataReceiverMockup

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.