Package org.apache.http.mockup

Examples of org.apache.http.mockup.HttpDataTransmitterMockup


        // make the buffer larger than that of transmitter
        byte[] out = new byte[40];
        for (int i = 0; i < out.length; i++) {
            out[i] = (byte)(120 + i);
        }
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        for (int i = 0; i < out.length; i++) {
            transmitter.write(out[i]);
        }
        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


        String s3 = "Like hello and stuff";
       
        HttpParams params = new DefaultHttpParams(null);
        HttpProtocolParams.setHttpElementCharset(params, "UTF-8");
       
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        transmitter.reset(params);

        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        for (int i = 0; i < 10; i++) {
            chbuffer.clear();
            chbuffer.append(s1);
            transmitter.writeLine(chbuffer);
            chbuffer.clear();
            chbuffer.append(s2);
            transmitter.writeLine(chbuffer);
            chbuffer.clear();
            chbuffer.append(s3);
            transmitter.writeLine(chbuffer);
        }
        transmitter.flush();
       
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
            transmitter.getData());
        receiver.reset(params);

        for (int i = 0; i < 10; i++) {
            assertEquals(s1, receiver.readLine());
            assertEquals(s2, receiver.readLine());
View Full Code Here

        String s1 = constructString(SWISS_GERMAN_HELLO);
       
        HttpParams params = new DefaultHttpParams(null);
        HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
       
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        transmitter.reset(params);

        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        for (int i = 0; i < 10; i++) {
            chbuffer.clear();
            chbuffer.append(s1);
            transmitter.writeLine(chbuffer);
        }
        transmitter.flush();
       
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
                transmitter.getData());
        HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
        receiver.reset(params);

        for (int i = 0; i < 10; i++) {
            assertEquals(s1, receiver.readLine());
View Full Code Here

    public static Test suite() {
        return new TestSuite(TestHttpDataOutputStream.class);
    }

    public void testConstructor() throws Exception {
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        new HttpDataOutputStream(transmitter);
        try {
            new HttpDataOutputStream(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
View Full Code Here

            //expected
        }
    }
   
    public void testBasicWrite() throws Exception {
      HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
        outstream.write(new byte[] {'a', 'b'}, 0, 2);
        outstream.write('c');
        outstream.flush();
       
        byte[] input = transmitter.getData();
       
        assertNotNull(input);
        byte[] expected = new byte[] {'a', 'b', 'c'};
        assertEquals(expected.length, input.length);
        for (int i = 0; i < expected.length; i++) {
View Full Code Here

            assertEquals(expected[i], input[i]);
        }
    }
   
    public void testClosedCondition() throws Exception {
      HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
        outstream.close();
        outstream.close();
       
        try {
View Full Code Here

        String[] testCaseName = { TestContentLengthOutputStream.class.getName() };
        junit.textui.TestRunner.main(testCaseName);
    }

    public void testConstructors() throws Exception {
        new ContentLengthOutputStream(new HttpDataTransmitterMockup(), 10L);
        try {
            new ContentLengthOutputStream(null, 10L);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            new ContentLengthOutputStream(new HttpDataTransmitterMockup(), -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

        }
    }

    public void testBasics() throws Exception {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
      OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);

        byte[] tmp = new byte[10];
        out.write(tmp, 0, 10);
        out.write(1);
        out.write(tmp, 0, 10);
        out.write(tmp, 0, 10);
        out.write(tmp);
        out.write(1);
        out.write(2);
        out.flush();
        out.close();
        byte[] data = datatransmitter.getData();
        assertEquals(15, data.length);
    }
View Full Code Here

        assertEquals(15, data.length);
    }

    public void testClose() throws Exception {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
      OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);
      out.close();
      out.close();
        byte[] tmp = new byte[10];
        try {
View Full Code Here

        String[] testCaseName = { TestIdentityOutputStream.class.getName() };
        junit.textui.TestRunner.main(testCaseName);
    }

    public void testConstructors() throws Exception {
        new IdentityOutputStream(new HttpDataTransmitterMockup());
        try {
            new IdentityOutputStream(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
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.