FileDocCategorySizeDatePackage
TestHttpUrl.javaAPI DocphoneME MR2 API (J2ME)10625Wed May 02 18:00:14 BST 2007com.sun.midp.io

TestHttpUrl

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

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()
Runs all the tests.

        declare("testAbsUrl");
        testAbsUrl();
        declare("testRelUrl");
        testRelUrl();
    
voidtestAbsUrl()
Tests parsing of different pieces of the absolute URL.

        HttpUrl url;

        info("scheme://machine.domain:8080/path?query#fragment");
        url = new HttpUrl("scheme://machine.domain:8080/path?query#fragment");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain:8080", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", 8080, url.port);
        assertEquals("path", "/path", url.path);
        assertEquals("query", "query", url.query);
        assertEquals("fragment", "fragment", url.fragment);

        info("scheme://machine.domain:8080/path?query#");
        url = new HttpUrl("scheme://machine.domain:8080/path?query#");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain:8080", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", 8080, url.port);
        assertEquals("path", "/path", url.path);
        assertEquals("query", "query", url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine.domain:8080/path");
        url = new HttpUrl("scheme://machine.domain:8080/path");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain:8080", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", 8080, url.port);
        assertEquals("path", "/path", url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine.domain:8080/");
        url = new HttpUrl("scheme://machine.domain:8080/");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain:8080", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", 8080, url.port);
        assertEquals("path", "/", url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine.domain:8080");
        url = new HttpUrl("scheme://machine.domain:8080");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain:8080", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", 8080, url.port);
        assertEquals("path", null, url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine.domain");
        url = new HttpUrl("scheme://machine.domain");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine.domain", url.authority);
        assertEquals("host", "machine.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "domain", url.domain);
        assertEquals("port", -1, url.port);
        assertEquals("path", null, url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine");
        url = new HttpUrl("scheme://machine");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", "machine", url.authority);
        assertEquals("host", "machine", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", null, url.domain);
        assertEquals("port", -1, url.port);
        assertEquals("path", null, url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://");
        url = new HttpUrl("scheme://");
        assertEquals("scheme", "scheme", url.scheme);
        assertEquals("authority", null, url.authority);
        assertEquals("host", null, url.host);
        assertEquals("machine name", null, url.machine);
        assertEquals("domain", null, url.domain);
        assertEquals("port", -1, url.port);
        assertEquals("path", null, url.path);
        assertEquals("query", null, url.query);
        assertEquals("fragment", null, url.fragment);

        info("scheme://machine.subdomain.domain");
        url = new HttpUrl("scheme://machine.subdomain.domain");
        assertEquals("authority", "machine.subdomain.domain", url.authority);
        assertEquals("host", "machine.subdomain.domain", url.host);
        assertEquals("machine name", "machine", url.machine);
        assertEquals("domain", "subdomain.domain", url.domain);

        info("scheme://123.domain");
        url = new HttpUrl("scheme://123.domain");
        assertEquals("authority", "123.domain", url.authority);
        assertEquals("host", "123.domain", url.host);
        assertEquals("machine name", "123", url.machine);
        assertEquals("domain", "domain", url.domain);

        info("scheme://1234.5678.901.2345");
        url = new HttpUrl("scheme://1234.5678.901.2345");
        assertEquals("authority", "1234.5678.901.2345", url.authority);
        assertEquals("host", "1234.5678.901.2345", url.host);
        assertEquals("machine name", null, url.machine);
        assertEquals("domain", null, url.domain);

        info("scheme://123");
        url = new HttpUrl("scheme://1234");
        assertEquals("authority", "1234", url.authority);
        assertEquals("host", "1234", url.host);
        assertEquals("machine name", "1234", url.machine);
        assertEquals("domain", null, url.domain);

        // IP v4 address
        info("scheme://123.123");
        url = new HttpUrl("scheme://123.123");
        assertEquals("authority", "123.123", url.authority);
        assertEquals("host", "123.123", url.host);
        assertEquals("machine name", null, url.machine);
        assertEquals("domain", null, url.domain);

        // IP v6 address
        info("scheme://[123]");
        url = new HttpUrl("scheme://[123]");
        assertEquals("authority", "[123]", url.authority);
        assertEquals("host", "[123]", url.host);
        assertEquals("machine name", null, url.machine);
        assertEquals("domain", null, url.domain);

        info("scheme://authority/");
        url = new HttpUrl("scheme://authority/");
        assertEquals("path", "/", url.path);
    
voidtestRelUrl()
Tests parsing of different pieces of the relative URL.

        HttpUrl url;

        url = new HttpUrl("//authority/path?query#fragment");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", "authority", url.authority);
        assertEquals("path", "/path", url.path);
        assertEquals("query", "query", url.query);
        assertEquals("fragment", "fragment", url.fragment);

        url = new HttpUrl("//authority/path?query");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", "authority", url.authority);
        assertEquals("path", "/path", url.path);
        assertEquals("query", "query", url.query);
        assertEquals("fragment", null, url.fragment);

        url = new HttpUrl("//authority/path");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", "authority", url.authority);
        assertEquals("path", "/path", url.path);
        assertEquals("query", null, url.query);

        url = new HttpUrl("//authority/");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", "authority", url.authority);
        assertEquals("path", "/", url.path);

        url = new HttpUrl("//authority");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", "authority", url.authority);
        assertEquals("path", null, url.path);

        url = new HttpUrl("/path");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", null, url.authority);
        assertEquals("path", "/path", url.path);
        assertEquals("query", null, url.query);

        url = new HttpUrl("/");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", null, url.authority);
        assertEquals("path", "/", url.path);

        url = new HttpUrl("path/subpath");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", null, url.authority);
        assertEquals("path", "path/subpath", url.path);

        url = new HttpUrl("path");
        assertEquals("scheme", null, url.scheme);
        assertEquals("authority", null, url.authority);
        assertEquals("path", "path", url.path);