1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 /***
37 * @author stack
38 * @version $Revision: 3771 $, $Date: 2005-08-29 21:52:36 +0000 (Mon, 29 Aug 2005) $
39 */
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
51 this.seed.toString();
52
53 this.seed.setVia(UURIFactory.getInstance(url));
54 }
55
56 /***
57 * Test serialization/deserialization works.
58 *
59 * @throws IOException
60 * @throws ClassNotFoundException
61 */
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
76 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
103
104
105
106
107
108
109
110
111
112
113
114
115 }