Package org.apache.http

Examples of org.apache.http.HeaderIterator


            new BasicHeader("single"  , "value2=whatever"),
            new BasicHeader("match"   , "value3;tag=nil"),
        };

        // without filter
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, first & last
        hit = new BasicHeaderIterator(headers, "match");
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, one match
        hit = new BasicHeaderIterator(headers, "single");
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, no match
        hit = new BasicHeaderIterator(headers, "way-off");
        assertFalse(hit.hasNext());
    }
View Full Code Here


            new BasicHeader("yellow", "0d"),
            new BasicHeader("orange", "0e"),
        };

        // without filter
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("4", headers[4], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("5", headers[5], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("6", headers[6], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("7", headers[7], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("8", headers[8], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("9", headers[9], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("a", headers[10], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[11], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("c", headers[12], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("d", headers[13], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("e", headers[14], hit.nextHeader());
        assertFalse(hit.hasNext());

        // yellow 0, 5, 9, 11, 13
        hit = new BasicHeaderIterator(headers, "Yellow");
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("5", headers[5], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("9", headers[9], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[11], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("d", headers[13], hit.nextHeader());
        assertFalse(hit.hasNext());

        // maroon 1, 6, 7, 8, 10
        hit = new BasicHeaderIterator(headers, "marOOn");
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("6", headers[6], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("7", headers[7], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("8", headers[8], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("a", headers[10], hit.nextHeader());
        assertFalse(hit.hasNext());

        // orange 2, 3, 4, 12, 14
        hit = new BasicHeaderIterator(headers, "OranGe");
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("4", headers[4], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[12], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("e", headers[14], hit.nextHeader());
        assertFalse(hit.hasNext());
    }
View Full Code Here

    }


    public void testInvalid() {

        HeaderIterator hit = null;
        try {
            hit = new BasicHeaderIterator(null, "whatever");
            fail("null headers not detected");
        } catch (IllegalArgumentException iax) {
            // expected
        }

        // this is not invalid
        hit = new BasicHeaderIterator(new Header[0], "whatever");
        assertFalse(hit.hasNext());

        // but this is
        try {
            hit.nextHeader();
            fail("next beyond end not detected");
        } catch (NoSuchElementException nsx) {
            // expected
        }
    }
View Full Code Here

            new BasicHeader("naMe", "value2=whatever"),
            new BasicHeader("namE", "value3;tag=nil"),
        };

        // without filter, using plain next()
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.next());
        assertFalse(hit.hasNext());

        hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        try {
            hit.remove();
            fail("remove not detected");
        } catch (UnsupportedOperationException uox) {
            // expected
        }
View Full Code Here

    public void testSingleHeader() {
        Header[] headers = new Header[]{
            new BasicHeader("Name", "token0,token1, token2 , token3")
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

            new BasicHeader("Name", " "),
            new BasicHeader("Name", "token3 "),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", "token4"),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

            new BasicHeader("Name", " "),
            new BasicHeader("Name", ""),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", " ,, "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertFalse(ti.hasNext());

View Full Code Here

            new BasicHeader("Name", ",token2"),
            new BasicHeader("Name", " ,token3"),
            new BasicHeader("Name", ", token4"),
            new BasicHeader("Name", " , token5"),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

            new BasicHeader("Name", "token2,"),
            new BasicHeader("Name", "token3 ,"),
            new BasicHeader("Name", "token4, "),
            new BasicHeader("Name", "token5 , "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

    public void testTokenChar() {
        Header[] headers = new Header[]{
            new BasicHeader("Name", "token0")
        };
        HeaderIterator     hit = new BasicHeaderIterator(headers, null);
        BasicTokenIterator bti = new BasicTokenIterator(hit);

        assertTrue ("letter"   , bti.isTokenChar('j'));
        assertFalse("control"  , bti.isTokenChar('\b'));
        assertFalse("separator", bti.isTokenChar('?'));
View Full Code Here

TOP

Related Classes of org.apache.http.HeaderIterator

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.