KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > net > TestRegexUrlNormalizer


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 import net.nutch.net.RegexUrlNormalizer;
9
10 /** Unit tests for RegexUrlNormalizer. */
11 public class TestRegexUrlNormalizer extends TestBasicUrlNormalizer {
12   public TestRegexUrlNormalizer(String JavaDoc name) { super(name); }
13
14   public void testNormalizer() throws Exception JavaDoc {
15     normalizeTest("http://foo.com/foo.php?f=2&PHPSESSID=cdc993a493e899bed04f4d0c8a462a03",
16       "http://foo.com/foo.php?f=2");
17     normalizeTest("http://foo.com/foo.php?f=2&PHPSESSID=cdc993a493e899bed04f4d0c8a462a03&q=3",
18       "http://foo.com/foo.php?f=2&q=3");
19     normalizeTest("http://foo.com/foo.php?PHPSESSID=cdc993a493e899bed04f4d0c8a462a03&f=2",
20       "http://foo.com/foo.php?f=2");
21     normalizeTest("http://foo.com/foo.php?PHPSESSID=cdc993a493e899bed04f4d0c8a462a03",
22       "http://foo.com/foo.php");
23   }
24
25   private void normalizeTest(String JavaDoc weird, String JavaDoc normal) throws Exception JavaDoc {
26     String JavaDoc testSrcDir = System.getProperty("test.src.dir");
27     String JavaDoc path = testSrcDir + "/net/nutch/net/test-regex-normalize.xml";
28     RegexUrlNormalizer normalizer = new RegexUrlNormalizer(path);
29     assertEquals(normal, normalizer.normalize(weird));
30   }
31     
32   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
33     new TestRegexUrlNormalizer("test").testNormalizer();
34     new TestBasicUrlNormalizer("test").testNormalizer(); // need to make sure it passes this test too
35
}
36
37
38
39 }
40
Popular Tags