1 2 3 4 package net.nutch.net; 5 6 import java.net.URL ; 7 import junit.framework.TestCase; 8 9 10 public class TestBasicUrlNormalizer extends TestCase { 11 public TestBasicUrlNormalizer(String name) { super(name); } 12 13 public void testNormalizer() throws Exception { 14 normalizeTest(" http://foo.com/ ", "http://foo.com/"); 16 17 normalizeTest("HTTP://foo.com/", "http://foo.com/"); 19 20 normalizeTest("http://Foo.Com/index.html", "http://foo.com/index.html"); 22 normalizeTest("http://Foo.Com/index.html", "http://foo.com/index.html"); 23 24 normalizeTest("http://foo.com:80/index.html", "http://foo.com/index.html"); 26 normalizeTest("http://foo.com:81/", "http://foo.com:81/"); 27 28 normalizeTest("http://foo.com", "http://foo.com/"); 30 31 normalizeTest("http://foo.com/foo.html#ref", "http://foo.com/foo.html"); 33 34 37 normalizeTest("http://foo.com/aa/../", 39 "http://foo.com/" ); 40 normalizeTest("http://foo.com/aa/bb/../", 41 "http://foo.com/aa/"); 42 normalizeTest("http://foo.com/aa/..", 43 "http://foo.com/aa/.."); 44 normalizeTest("http://foo.com/aa/bb/cc/../../foo.html", 45 "http://foo.com/aa/foo.html"); 46 normalizeTest("http://foo.com/aa/bb/../cc/dd/../ee/foo.html", 47 "http://foo.com/aa/cc/ee/foo.html"); 48 normalizeTest("http://foo.com/../foo.html", 49 "http://foo.com/foo.html" ); 50 normalizeTest("http://foo.com/../../foo.html", 51 "http://foo.com/foo.html" ); 52 normalizeTest("http://foo.com/../aa/../foo.html", 53 "http://foo.com/foo.html" ); 54 normalizeTest("http://foo.com/aa/../../foo.html", 55 "http://foo.com/foo.html" ); 56 normalizeTest("http://foo.com/aa/../bb/../foo.html/../../", 57 "http://foo.com/" ); 58 normalizeTest("http://foo.com/../aa/foo.html", 59 "http://foo.com/aa/foo.html" ); 60 normalizeTest("http://foo.com/../aa/../foo.html", 61 "http://foo.com/foo.html" ); 62 normalizeTest("http://foo.com/a..a/foo.html", 63 "http://foo.com/a..a/foo.html" ); 64 normalizeTest("http://foo.com/a..a/../foo.html", 65 "http://foo.com/foo.html" ); 66 normalizeTest("http://foo.com/foo.foo/../foo.html", 67 "http://foo.com/foo.html" ); 68 } 69 70 private void normalizeTest(String weird, String normal) throws Exception { 71 assertEquals(normal, UrlNormalizerFactory.getNormalizer().normalize(weird)); 72 } 73 74 public static void main(String [] args) throws Exception { 75 new TestBasicUrlNormalizer("test").testNormalizer(); 76 } 77 78 79 80 } 81 | Popular Tags |