1 2 3 4 package net.nutch.pagedb; 5 6 import java.io.*; 7 import java.util.Random ; 8 import net.nutch.io.*; 9 import net.nutch.db.*; 10 import junit.framework.TestCase; 11 12 13 public class TestPage extends TestCase { 14 public TestPage(String name) { super(name); } 15 16 public static Page getTestPage() throws Exception { 17 return new Page("http://foo.com/", TestMD5Hash.getTestHash()); 18 } 19 20 public void testPage() throws Exception { 21 TestWritable.testWritable(getTestPage()); 22 } 23 24 public void testPageCtors() throws Exception { 25 Random random = new Random (); 26 String 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 |