1 17 package org.apache.excalibur.source.test; 18 19 import org.apache.excalibur.source.SourceUtil; 20 21 import junit.framework.TestCase; 22 23 29 public class SourceUtilTestCase extends TestCase 30 { 31 public SourceUtilTestCase() 32 { 33 this("SourceUtil"); 34 } 35 36 public SourceUtilTestCase(String name) 37 { 38 super(name); 39 } 40 41 public void testNominalScheme() throws Exception 42 { 43 String uri = "http://foo"; 44 assertEquals(4, SourceUtil.indexOfSchemeColon(uri)); 45 assertEquals("http", SourceUtil.getScheme(uri)); 46 assertEquals("//foo", SourceUtil.getSpecificPart(uri)); 47 } 48 49 public void testDoubleColon() throws Exception 50 { 51 assertEquals(4, SourceUtil.indexOfSchemeColon("file:foo:bar")); 52 } 53 54 public void testSpecialScheme() throws Exception 55 { 56 String uri = "a-+.:foo"; assertEquals(4, SourceUtil.indexOfSchemeColon(uri)); 58 assertEquals("a-+.", SourceUtil.getScheme(uri)); 59 assertEquals("foo", SourceUtil.getSpecificPart(uri)); 60 } 61 62 public void testSpecialPart() throws Exception 63 { 64 String uri = "bar:"; 65 assertEquals(3, SourceUtil.indexOfSchemeColon(uri)); 66 assertEquals("bar", SourceUtil.getScheme(uri)); 67 assertEquals("", SourceUtil.getSpecificPart(uri)); 68 } 69 70 public void testInvalidScheme() throws Exception 71 { 72 String uri = "2foo:bar"; 73 assertEquals(-1, SourceUtil.indexOfSchemeColon(uri)); 74 assertEquals(null, SourceUtil.getScheme(uri)); 75 assertEquals(null, SourceUtil.getSpecificPart(uri)); 76 77 assertEquals(-1, SourceUtil.indexOfSchemeColon("h ttp:foo")); 79 assertEquals(-1, SourceUtil.indexOfSchemeColon(" http:foo")); 80 assertEquals(-1, SourceUtil.indexOfSchemeColon("http :foo")); 81 82 assertEquals(-1, SourceUtil.indexOfSchemeColon("h_ttp:foo")); 84 assertEquals(-1, SourceUtil.indexOfSchemeColon("_http:foo")); 85 assertEquals(-1, SourceUtil.indexOfSchemeColon("http_:foo")); 86 87 assertEquals(-1, SourceUtil.indexOfSchemeColon("h~ttp:foo")); 89 assertEquals(-1, SourceUtil.indexOfSchemeColon("~http:foo")); 90 assertEquals(-1, SourceUtil.indexOfSchemeColon("http~:foo")); 91 } 92 93 public void testAbsolutize() 94 { 95 String base = "http://a/b/c/d;p?q"; 96 97 101 assertEquals("g:h", SourceUtil.absolutize(base, "g:h")); 103 assertEquals("http://a/b/c/g", SourceUtil.absolutize(base, "g")); 104 assertEquals("http://a/b/c/g", SourceUtil.absolutize(base, "./g")); 105 assertEquals("http://a/b/c/g/", SourceUtil.absolutize(base, "g/")); 106 assertEquals("http://a/g", SourceUtil.absolutize(base, "/g")); 107 assertEquals("http://g", SourceUtil.absolutize(base, "//g")); 108 assertEquals("http://a/b/c/?y", SourceUtil.absolutize(base, "?y")); 109 assertEquals("http://a/b/c/g?y", SourceUtil.absolutize(base, "g?y")); 110 assertEquals("http://a/b/c/d;p?q#s", SourceUtil.absolutize(base, "#s")); 111 assertEquals("http://a/b/c/g#s", SourceUtil.absolutize(base, "g#s")); 112 assertEquals("http://a/b/c/g?y#s", SourceUtil.absolutize(base, "g?y#s")); 113 assertEquals("http://a/b/c/;x", SourceUtil.absolutize(base, ";x")); 114 assertEquals("http://a/b/c/g;x", SourceUtil.absolutize(base, "g;x")); 115 assertEquals("http://a/b/c/g;x?y#s", SourceUtil.absolutize(base, "g;x?y#s")); 116 assertEquals("http://a/b/c/", SourceUtil.absolutize(base, ".")); 117 assertEquals("http://a/b/c/", SourceUtil.absolutize(base, "./")); 118 assertEquals("http://a/b/", SourceUtil.absolutize(base, "..")); 119 assertEquals("http://a/b/", SourceUtil.absolutize(base, "../")); 120 assertEquals("http://a/b/g", SourceUtil.absolutize(base, "../g")); 121 assertEquals("http://a/", SourceUtil.absolutize(base, "../..")); 122 assertEquals("http://a/", SourceUtil.absolutize(base, "../../")); 123 assertEquals("http://a/g", SourceUtil.absolutize(base, "../../g")); 124 125 assertEquals("http://a/../g", SourceUtil.absolutize(base, "../../../g")); 127 assertEquals("http://a/../../g", SourceUtil.absolutize(base, "../../../../g")); 128 129 assertEquals("http://a/./g", SourceUtil.absolutize(base, "/./g")); 130 assertEquals("http://a/../g", SourceUtil.absolutize(base, "/../g")); 131 assertEquals("http://a/b/c/g.", SourceUtil.absolutize(base, "g.")); 132 assertEquals("http://a/b/c/.g", SourceUtil.absolutize(base, ".g")); 133 assertEquals("http://a/b/c/g..", SourceUtil.absolutize(base, "g..")); 134 assertEquals("http://a/b/c/..g", SourceUtil.absolutize(base, "..g")); 135 136 assertEquals("http://a/b/g", SourceUtil.absolutize(base, "./../g")); 137 assertEquals("http://a/b/c/g/", SourceUtil.absolutize(base, "./g/.")); 138 assertEquals("http://a/b/c/g/h", SourceUtil.absolutize(base, "g/./h")); 139 assertEquals("http://a/b/c/h", SourceUtil.absolutize(base, "g/../h")); 140 assertEquals("http://a/b/c/g;x=1/y", SourceUtil.absolutize(base, "g;x=1/./y")); 141 assertEquals("http://a/b/c/y", SourceUtil.absolutize(base, "g;x=1/../y")); 142 143 assertEquals("http://a/b/c/g?y/./x", SourceUtil.absolutize(base, "g?y/./x")); 144 assertEquals("http://a/b/c/g?y/../x", SourceUtil.absolutize(base, "g?y/../x")); 145 assertEquals("http://a/b/c/g#s/./x", SourceUtil.absolutize(base, "g#s/./x")); 146 assertEquals("http://a/b/c/g#s/../x", SourceUtil.absolutize(base, "g#s/../x")); 147 148 152 assertEquals("http://a", SourceUtil.absolutize("", "http://a")); 154 assertEquals("cocoon:/a", SourceUtil.absolutize("", "cocoon:/a", true)); 155 156 assertEquals("a", SourceUtil.absolutize(null, "a")); 158 159 assertEquals("http://a/b", SourceUtil.absolutize("http://myhost", "//a/b")); 161 162 assertEquals("http:///a/b", SourceUtil.absolutize("http:///a/", "b")); 164 165 assertEquals("cocoon://a/b/c", SourceUtil.absolutize("cocoon://a/b/", "c", true)); 167 assertEquals("cocoon:/a/b/c", SourceUtil.absolutize("cocoon:/a/b/", "c", true)); 168 assertEquals("cocoon://c", SourceUtil.absolutize("cocoon://a", "c", true)); 169 assertEquals("cocoon://c", SourceUtil.absolutize("cocoon://a/b/", "../../c", true)); 170 171 assertEquals("file://C:/projects/avalon-excalibur/build/docs/framework/api/index.html%3Ffoo=bar", 173 SourceUtil.absolutize("file://C:/projects/avalon-excalibur/build/docs/framework/", "api/index.html%3Ffoo=bar")); 174 assertEquals( "file://C:/foo/api/", SourceUtil.absolutize( "file://C:/foo/", "api/" ) ); 175 } 176 } 177 | Popular Tags |