FileDocCategorySizeDatePackage
TestHttpHeaders.javaAPI DocphoneME MR2 API (J2ME)5614Wed May 02 18:00:14 BST 2007com.sun.midp.io.j2me.http

TestHttpHeaders

public class TestHttpHeaders extends com.sun.midp.i3test.TestCase

Fields Summary
final String
URL
StubHttpProtocol
conn
Constructors Summary
Methods Summary
public voidrunTests()
Runs all the tests.

        declare("testParsing");
        setUp();
        testParsing();
        tearDown();

        declare("testSetGet");
        setUp();
        testSetGet();
        tearDown();

        declare("testOverwrite");
        setUp();
        testOverwrite();
        tearDown();

        declare("testOutput");
        setUp();
        testOutput();
        tearDown();
    
voidsetUp()


        
        conn = new StubHttpProtocol();
        conn.openPrim(getSecurityToken(), URL);
    
voidtearDown()

    
voidtestOutput()
Tests that the output matches the case of what was passed by the programmer.

        conn.setRequestProperty("calvin", "hobbes");
        conn.setRequestProperty("CaLvIN", "Wittgenstein");
        conn.setInputBuffer("");

        conn.startRequest();

        String outbuf = conn.getOutputBuffer();
        assertTrue("calvin", outbuf.indexOf("CaLvIN: Wittgenstein") >= 0);
    
voidtestOverwrite()
Tests overwriting of a property in a case-insensitive fashion.

        conn.setRequestProperty("hello", "tweedledee");
        conn.setRequestProperty("HELLO", "tweedledum");
        assertEquals("three", "tweedledum", conn.getRequestProperty("hElLo"));
        assertEquals("count", 1, conn.reqProperties.size());
        assertEquals("value", "HELLO",
            conn.reqProperties.getKeyAt(0));
    
voidtestParsing()
Tests parsing of different pieces of the URL.

        assertEquals("URL", URL, conn.getURL());
        assertEquals("protocol", "http", conn.getProtocol());
        assertEquals("host", "nonexistent.example.com", conn.getHost());
        assertEquals("file", "/foo/bar", conn.getFile());
        assertEquals("query", "bazz", conn.getQuery());
        assertEquals("ref", "mumble", conn.getRef());
        assertEquals("port", 8080, conn.getPort());
    
voidtestSetGet()
Tests that getting a property is case-insensitive relative to a property that had been set previously.

        conn.setRequestProperty("hElLo", "goodbye");
        assertEquals("two", "goodbye", conn.getRequestProperty("hello"));