1 23 package org.archive.crawler.datamodel; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileOutputStream ; 28 import java.io.IOException ; 29 import java.io.ObjectInputStream ; 30 import java.io.ObjectOutputStream ; 31 32 import org.apache.commons.httpclient.URIException; 33 import org.archive.net.UURIFactory; 34 import org.archive.util.TmpDirTestCase; 35 36 40 public class CrawlURITest extends TmpDirTestCase { 41 42 CrawlURI seed = null; 43 44 protected void setUp() throws Exception { 45 super.setUp(); 46 final String url = "http://www.dh.gov.uk/Home/fs/en"; 47 this.seed = new CrawlURI(UURIFactory.getInstance(url)); 48 this.seed.setSchedulingDirective(CandidateURI.MEDIUM); 49 this.seed.setIsSeed(true); 50 this.seed.toString(); 52 this.seed.setVia(UURIFactory.getInstance(url)); 54 } 55 56 62 final public void testSerialization() 63 throws IOException , ClassNotFoundException { 64 File serialize = new File (getTmpDir(), 65 this.getClass().getName() + ".serialize"); 66 try { 67 FileOutputStream fos = new FileOutputStream (serialize); 68 ObjectOutputStream oos = new ObjectOutputStream (fos); 69 oos.writeObject(this.seed); 70 oos.reset(); 71 oos.writeObject(this.seed); 72 oos.reset(); 73 oos.writeObject(this.seed); 74 oos.close(); 75 FileInputStream fis = new FileInputStream (serialize); 77 ObjectInputStream ois = new ObjectInputStream (fis); 78 CrawlURI deserializedCuri = (CrawlURI)ois.readObject(); 79 deserializedCuri = (CrawlURI)ois.readObject(); 80 deserializedCuri = (CrawlURI)ois.readObject(); 81 assertTrue("Deserialized not equal to original", 82 this.seed.toString().equals(deserializedCuri.toString())); 83 String host = this.seed.getUURI().getHost(); 84 assertTrue("Deserialized host not null", 85 host != null && host.length() >= 0); 86 } finally { 87 serialize.delete(); 88 } 89 } 90 91 public void testCandidateURIWithLoadedAList() 92 throws URIException { 93 CandidateURI c = CandidateURI. 94 createSeedCandidateURI(UURIFactory. 95 getInstance("http://www.archive.org")); 96 c.putString("key", "value"); 97 CrawlURI curi = new CrawlURI(c, 0); 98 assertTrue("Didn't find AList item", 99 curi.getString("key").equals("value")); 100 } 101 102 } 116 | Popular Tags |