Package org.apache.http.mockup

Examples of org.apache.http.mockup.HttpDataTransmitterMockup


        junit.textui.TestRunner.main(testCaseName);
    }

    public void testInit() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        new HttpDataTransmitterMockup(out);
        try {
            new HttpDataTransmitterMockup(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        new HttpDataReceiverMockup(in, 10);
        try {
            new HttpDataReceiverMockup(in, -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        try {
            new HttpDataTransmitterMockup(out, -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
        try {
View Full Code Here


        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            transmitter.writeLine(chbuffer);
        }
        //these write operations should have no effect
        transmitter.writeLine((String)null);
        transmitter.writeLine((CharArrayBuffer)null);
        transmitter.flush();
       
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
            transmitter.getData());

        for (int i = 0; i < teststrs.length; i++) {
            assertEquals(teststrs[i], receiver.readLine());
        }
        assertNull(receiver.readLine());
View Full Code Here

        assertNull(receiver.readLine());
        assertNull(receiver.readLine());
    }

    public void testComplexReadWriteLine() throws Exception {
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        transmitter.write(new byte[] {'a', '\n'});
        transmitter.write(new byte[] {'\r', '\n'});
        transmitter.write(new byte[] {'\r', '\r', '\n'});
        transmitter.write(new byte[] {'\n'});
        //these write operations should have no effect
        transmitter.write(null);
        transmitter.write(null, 0, 12);
       
        transmitter.flush();

        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < 14; i++) {
            buffer.append("a");
        }
        String s1 = buffer.toString();
        buffer.append("\r\n");
        transmitter.write(buffer.toString().getBytes("US-ASCII"));
        transmitter.flush();

        buffer.setLength(0);
        for (int i = 0; i < 15; i++) {
            buffer.append("a");
        }
        String s2 = buffer.toString();
        buffer.append("\r\n");
        transmitter.write(buffer.toString().getBytes("US-ASCII"));
        transmitter.flush();

        buffer.setLength(0);
        for (int i = 0; i < 16; i++) {
            buffer.append("a");
        }
        String s3 = buffer.toString();
        buffer.append("\r\n");
        transmitter.write(buffer.toString().getBytes("US-ASCII"));
        transmitter.flush();

        transmitter.write(new byte[] {'a'});
        transmitter.flush();
       
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
            transmitter.getData());

        assertEquals("a", receiver.readLine());
        assertEquals("", receiver.readLine());
        assertEquals("\r", receiver.readLine());
        assertEquals("", receiver.readLine());
View Full Code Here

        }
    }

    public void testChunkedOutputStreamClose() throws IOException {
        ChunkedOutputStream out = new ChunkedOutputStream(
                new HttpDataTransmitterMockup());
        out.close();
        out.close();
        try {
          out.write(new byte[] {1,2,3});
            fail("IOException should have been thrown");
View Full Code Here

    }
   
    public void testChunkedConsitance() throws IOException {
        String input = "76126;27823abcd;:q38a-\nkjc\rk%1ad\tkh/asdui\r\njkh+?\\suweb";
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        OutputStream out = new ChunkedOutputStream(new HttpDataTransmitterMockup(buffer));
        out.write(EncodingUtils.getBytes(input, CONTENT_CHARSET));
        out.flush();
        out.close();
        out.close();
        buffer.close();
View Full Code Here

        String output = EncodingUtils.getString(result.toByteArray(), CONTENT_CHARSET);
        assertEquals(input, output);
    }

    public void testChunkedOutputStream() throws IOException {
      HttpDataTransmitterMockup buffer = new HttpDataTransmitterMockup();
        ChunkedOutputStream out = new ChunkedOutputStream(buffer, 2);
        out.write('1')
        out.write('2')
        out.write('3')
        out.write('4')
        out.finish();
        out.close();
       
        byte [] rawdata =  buffer.getData();
       
        assertEquals(19, rawdata.length);
        assertEquals('2', rawdata[0]);
        assertEquals('\r', rawdata[1]);
        assertEquals('\n', rawdata[2]);
View Full Code Here

        assertEquals('\r', rawdata[17]);
        assertEquals('\n', rawdata[18]);
    }

    public void testChunkedOutputStreamLargeChunk() throws IOException {
      HttpDataTransmitterMockup buffer = new HttpDataTransmitterMockup();
        ChunkedOutputStream out = new ChunkedOutputStream(buffer, 2);
        out.write(new byte[] {'1', '2', '3', '4'});
        out.finish();
        out.close();
       
        byte [] rawdata =  buffer.getData();
       
        assertEquals(14, rawdata.length);
        assertEquals('4', rawdata[0]);
        assertEquals('\r', rawdata[1]);
        assertEquals('\n', rawdata[2]);
View Full Code Here

        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            transmitter.writeLine(chbuffer);
        }
        //these write operations should have no effect
        transmitter.writeLine((String)null);
        transmitter.writeLine((CharArrayBuffer)null);
        transmitter.flush();
       
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
            transmitter.getData(), 1024);

        for (int i = 0; i < teststrs.length; i++) {
            assertEquals(teststrs[i], receiver.readLine());
        }
        assertNull(receiver.readLine());
View Full Code Here

    }

    public void testChunkedOutputStreamSmallChunk() throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ChunkedOutputStream out = new ChunkedOutputStream(
            new HttpDataTransmitterMockup(buffer), 2);
        out.write('1')
        out.finish();
        out.close();
       
        byte [] rawdata =  buffer.toByteArray();
View Full Code Here

        // make the buffer larger than that of transmitter
        byte[] out = new byte[40];
        for (int i = 0; i < out.length; i++) {
            out[i] = (byte)('0' + i);
        }
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        int off = 0;
        int remaining = out.length;
        while (remaining > 0) {
            int chunk = 10;
            if (chunk > remaining) {
                chunk = remaining;
            }
            transmitter.write(out, off, chunk);
            off += chunk;
            remaining -= chunk;
        }
        transmitter.flush();

        byte[] tmp = transmitter.getData();
        assertEquals(out.length, tmp.length);
        for (int i = 0; i < out.length; i++) {
            assertEquals(out[i], tmp[i]);
        }
       
View Full Code Here

TOP

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

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.