Package org.apache.http.mockup

Examples of org.apache.http.mockup.HttpDataReceiverMockup


            "header3: stuff\r\n" +
            "     and more stuff\r\n" +
            "\t and even more stuff\r\n"
            "     \r\n"
            "\r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        Header[] headers = Header.parseAll(receiver);
        assertNotNull(headers);
        assertEquals(3, headers.length);
        assertEquals("header1", headers[0].getName());
        assertEquals("stuff", headers[0].getValue());
View Full Code Here


    public void testBufferedHeader() throws Exception {
        String s =
            "header1  : stuff; param1 = value1; param2 = \"value 2\" \r\n" +
            "\r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        Header[] headers = Header.parseAll(receiver);
        assertNotNull(headers);
        assertEquals(1, headers.length);
        assertEquals("header1  : stuff; param1 = value1; param2 = \"value 2\" ", headers[0].toString());
        HeaderElement[] elements = headers[0].getElements();
View Full Code Here

    public void testParsingInvalidHeaders() throws Exception {
        String s = "    stuff\r\n" +
            "header1: stuff\r\n" +
            "\r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        try {
            Header.parseAll(receiver);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
        }
        s = "  :  stuff\r\n" +
            "header1: stuff\r\n" +
            "\r\n";
        receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        try {
            Header.parseAll(receiver);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
View Full Code Here

    }

    private static final String CONTENT_CHARSET = "ISO-8859-1";
       
    public void testConstructors() throws Exception {
        new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[] {}), 10);
        try {
            new ContentLengthInputStream(null, 10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[] {}), -10);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

   
    public void testParsingMalformedFirstHeader() throws Exception {
        String s =
            "    header1: stuff\r\n" +
            "header2  : stuff \r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        Header[] headers = Header.parseAll(receiver);
        assertNotNull(headers);
        assertEquals(2, headers.length);
        assertEquals("header1", headers[0].getName());
        assertEquals("stuff", headers[0].getValue());
View Full Code Here

        assertEquals("stuff", headers[1].getValue());
    }
   
    public void testEmptyDataStream() throws Exception {
        String s = "";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        Header[] headers = Header.parseAll(receiver);
        assertNotNull(headers);
        assertEquals(0, headers.length);
    }
View Full Code Here

        }
    }

    public void testBasics() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new HttpDataReceiverMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] buffer = new byte[50];
        int len = in.read(buffer, 0, 2);
View Full Code Here

        String result = EncodingUtils.getString(out.toByteArray(), CONTENT_CHARSET);
        assertEquals(result, "1234567890");
    }

    public void testSkip() throws IOException {
        InputStream in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[20]), 10L);
        assertEquals(10, in.skip(10));
        assertTrue(in.read() == -1);

        in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[20]), 10L);
        in.read();
        assertEquals(9, in.skip(10));
        assertTrue(in.read() == -1);

        in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[20]), 2L);
        in.read();
        in.read();
        assertTrue(in.skip(10) <= 0);
        assertTrue(in.skip(-1) == 0);
        assertTrue(in.read() == -1);
       
        in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[2]), 4L);
        in.read();
        assertTrue(in.skip(2) == 1);
    }
View Full Code Here

        assertTrue(in.skip(2) == 1);
    }

    public void testClose() throws IOException {
        String correct = "1234567890123456";
        InputStream in = new ContentLengthInputStream(new HttpDataReceiverMockup(
            EncodingUtils.getBytes(correct, CONTENT_CHARSET)), 10L);
        in.close();
        in.close();
        try {
            in.read();
View Full Code Here

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

    public void testConstructor() throws Exception {
        HttpDataReceiver receiver = new HttpDataReceiverMockup(new byte[] {});
        new HttpDataInputStream(receiver);
        try {
            new HttpDataInputStream(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
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.