FileDocCategorySizeDatePackage
URITest.javaAPI DocAndroid 1.5 API7006Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.tests.java.net

URITest

public class URITest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtest_ConstructorLjava_lang_String()

tests
java.net.URI(java.lang.String)

        // Regression test for HARMONY-23
        try {
            new URI("%3");
            fail("Assert 0: URI constructor failed to throw exception on invalid input.");
        } catch (URISyntaxException e) {
            // Expected
            assertEquals("Assert 1: Wrong index in URISyntaxException.", 0, e.getIndex());
        }
        
        // Regression test for HARMONY-25
        // if port value is negative, the authority should be considered registry-based.
        URI uri = new URI("http://host:-8096/path/index.html");
        assertEquals("Assert 2: returned wrong port value,", -1, uri.getPort());
        assertNull("Assert 3: returned wrong host value,", uri.getHost());
        try {
            uri.parseServerAuthority();
            fail("Assert 4: Expected URISyntaxException");
        } catch (URISyntaxException e){
            // Expected
        }
        
        uri = new URI("http","//myhost:-8096", null);
        assertEquals("Assert 5: returned wrong port value,", -1, uri.getPort());
        assertNull("Assert 6: returned wrong host value,", uri.getHost());
        try {
            uri.parseServerAuthority();
            fail("Assert 7: Expected URISyntaxException");
        } catch (URISyntaxException e){
            // Expected
        }
    
public voidtest_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String()

tests
java.net.URI(java.lang.String, java.lang.String, java.lang.String)

        // scheme can not be empty string    
        try {
            new URI("","//authority/path", "fragment");
            fail ("Assert 0: Expected URISyntaxException with empty URI scheme");    
        } catch(URISyntaxException e) {
            // Expected
            assertEquals("Assert 1: Wrong index in URISyntaxException.", 0, e.getIndex());
        }
    
public voidtest_compareToLjava_net_URI()

tests
java.net.URI#compareTo(java.net.URI)

        URI uri1, uri2;

        // URIs whose host names have different casing
        uri1 = new URI("http://MixedCaseHost/path/resource");
        uri2 = new URI("http://mixedcasehost/path/resource");
        assertEquals("Assert 0: host name equality failure", 0, uri1.compareTo(uri2));
        assertEquals("Assert 1: host name equality failure", 0, uri1.compareTo(uri2));

        // URIs with one undefined component (port)
        uri1 = new URI("http://anyhost:80/path/resource");
        uri2 = new URI("http://anyhost/path/resource");
        assertTrue("Assert 2: comparison failure", uri1.compareTo(uri2) > 0);
        assertTrue("Assert 3: comparison failure", uri2.compareTo(uri1) < 0);
        
        // URIs with one undefined component (user-info)
        uri1 = new URI("http://user-info@anyhost/path/resource");
        uri2 = new URI("http://anyhost/path/resource");
        assertTrue("Assert 4: comparison failure", uri1.compareTo(uri2) > 0);
        assertTrue("Assert 5: comparison failure", uri2.compareTo(uri1) < 0);
        
    
public voidtest_relativizeBasedOneEclipseCoreResources()

        URI one = new URI("file:/C:/test/ws");
        URI two = new URI("file:/C:/test/ws");
        
        URI empty = new URI("");
        assertEquals(empty, one.relativize(two));
        
        one = new URI("file:/C:/test/ws");
        two = new URI("file:/C:/test/ws/p1");
        URI result = new URI("p1");
        assertEquals(result, one.relativize(two));
        
        one = new URI("file:/C:/test/ws/");
        assertEquals(result, one.relativize(two));
    
public voidtest_relativizeLjava_net_URI()

tests
java.net.URI#relativize(java.net.URI)

        URI a = new URI("http://host/dir");
        URI b = new URI("http://host/dir/file?query");        
        assertEquals("Assert 0: URI relativized incorrectly,",
                new URI("file?query"), a.relativize(b));        
    
        // One URI with empty host
        a = new URI("file:///~/first");
        b = new URI("file://tools/~/first");
        assertEquals("Assert 1: URI relativized incorrectly,",
                new URI("file://tools/~/first"), a.relativize(b));        
        assertEquals("Assert 2: URI relativized incorrectly,",
                new URI("file:///~/first"), b.relativize(a));        

        // Both URIs with empty hosts
        b = new URI("file:///~/second");
        assertEquals("Assert 3: URI relativized incorrectly,",
                new URI("file:///~/second"), a.relativize(b));
        assertEquals("Assert 4: URI relativized incorrectly,",
                new URI("file:///~/first"), b.relativize(a));