KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > net > TestBasicUrlNormalizer


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.net;
5
6 import java.net.URL JavaDoc;
7 import junit.framework.TestCase;
8
9 /** Unit tests for BasicUrlNormalizer. */
10 public class TestBasicUrlNormalizer extends TestCase {
11   public TestBasicUrlNormalizer(String JavaDoc name) { super(name); }
12
13   public void testNormalizer() throws Exception JavaDoc {
14     // check that leading and trailing spaces are removed
15
normalizeTest(" http://foo.com/ ", "http://foo.com/");
16
17     // check that protocol is lower cased
18
normalizeTest("HTTP://foo.com/", "http://foo.com/");
19
20     // check that host is lower cased
21
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     // check that port number is normalized
25
normalizeTest("http://foo.com:80/index.html", "http://foo.com/index.html");
26     normalizeTest("http://foo.com:81/", "http://foo.com:81/");
27
28     // check that null path is normalized
29
normalizeTest("http://foo.com", "http://foo.com/");
30
31     // check that references are removed
32
normalizeTest("http://foo.com/foo.html#ref", "http://foo.com/foo.html");
33
34     // // check that encoding is normalized
35
// normalizeTest("http://foo.com/%66oo.html", "http://foo.com/foo.html");
36

37     // check that unnecessary "../" are removed
38
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 JavaDoc weird, String JavaDoc normal) throws Exception JavaDoc {
71     assertEquals(normal, UrlNormalizerFactory.getNormalizer().normalize(weird));
72   }
73     
74   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
75     new TestBasicUrlNormalizer("test").testNormalizer();
76   }
77
78
79
80 }
81
Popular Tags