Package org.apache.http.mockup

Examples of org.apache.http.mockup.HttpDataReceiverMockup


        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


            "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 = HeaderUtils.parseHeaders(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 = HeaderUtils.parseHeaders(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 {
            HeaderUtils.parseHeaders(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 {
            HeaderUtils.parseHeaders(receiver);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException 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 = HeaderUtils.parseHeaders(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 = HeaderUtils.parseHeaders(receiver);
        assertNotNull(headers);
        assertEquals(0, headers.length);
    }
View Full Code Here

        String s =
            "header1: stuff\r\n" +
            "header2: stuff \r\n" +
            "header3: stuff\r\n" +
            "\r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        try {
            HeaderUtils.parseHeaders(receiver, 2, -1);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
View Full Code Here

        String s =
            "header1: stuff\r\n" +
            " stuff \r\n" +
            " stuff\r\n" +
            "\r\n";
        HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
        try {
            HeaderUtils.parseHeaders(receiver, 2, 15);
            fail("IOException should have been thrown");
        } catch (IOException ex) {
            // expected
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

        }
    }
   
    public void testBasicRead() throws Exception {
        byte[] input = new byte[] {'a', 'b', 'c'};
        HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
        HttpDataInputStream instream = new HttpDataInputStream(receiver);
        byte[] tmp = new byte[2];
        assertEquals(2, instream.read(tmp, 0, tmp.length));
        assertEquals('a', tmp[0]);
        assertEquals('b', tmp[1]);
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.