KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > pagedb > TestPage


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.pagedb;
5
6 import java.io.*;
7 import java.util.Random JavaDoc;
8 import net.nutch.io.*;
9 import net.nutch.db.*;
10 import junit.framework.TestCase;
11
12 /** Unit tests for Page. */
13 public class TestPage extends TestCase {
14   public TestPage(String JavaDoc name) { super(name); }
15
16   public static Page getTestPage() throws Exception JavaDoc {
17     return new Page("http://foo.com/", TestMD5Hash.getTestHash());
18   }
19
20   public void testPage() throws Exception JavaDoc {
21     TestWritable.testWritable(getTestPage());
22   }
23
24   public void testPageCtors() throws Exception JavaDoc {
25     Random JavaDoc random = new Random JavaDoc();
26     String JavaDoc urlString = "http://foo.com/";
27     MD5Hash md5 = MD5Hash.digest(urlString);
28     long now = System.currentTimeMillis();
29     float score = random.nextFloat();
30     float nextScore = random.nextFloat();
31
32     Page page = new Page(urlString, md5);
33     assertEquals(page.getURL().toString(), urlString);
34     assertEquals(page.getMD5(), md5);
35
36     page = new Page(urlString, score);
37     assertEquals(page.getURL().toString(), urlString);
38     assertEquals(page.getMD5(), md5);
39     assertEquals(page.getScore(), score, 0.0f);
40     assertEquals(page.getNextScore(), score, 0.0f);
41
42     page = new Page(urlString, score, now);
43     assertEquals(page.getURL().toString(), urlString);
44     assertEquals(page.getMD5(), md5);
45     assertEquals(page.getNextFetchTime(), now);
46     assertEquals(page.getScore(), score, 0.0f);
47     assertEquals(page.getNextScore(), score, 0.0f);
48
49     page = new Page(urlString, score, nextScore, now);
50     assertEquals(page.getURL().toString(), urlString);
51     assertEquals(page.getMD5(), md5);
52     assertEquals(page.getNextFetchTime(), now);
53     assertEquals(page.getScore(), score, 0.0f);
54     assertEquals(page.getNextScore(), nextScore, 0.0f);
55   }
56
57 }
58
Popular Tags