1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.crawler.datamodel;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.io.ObjectInputStream;
31 import java.io.ObjectOutputStream;
32
33 import junit.framework.TestCase;
34
35 import org.archive.net.UURIFactory;
36
37 /***
38 * Test CandidateURI serialization.
39 * @author stack
40 */
41 public class CandidateURITest extends TestCase {
42 public void testSerialization()
43 throws IOException, ClassNotFoundException {
44 doOneSerialization("http://www.archive.org/");
45 doOneSerialization("http://www.archive.org/a?" +
46 "sch=%2E%2F%3Faction%3Dsearch");
47 }
48
49 private void doOneSerialization(final String urlStr)
50 throws IOException, ClassNotFoundException {
51 CandidateURI cauri =
52 new CandidateURI(UURIFactory.getInstance(urlStr));
53 cauri = serialize(cauri);
54 assertEquals(urlStr + " doesn't serialize", urlStr,
55 cauri.getUURI().toString());
56 }
57
58 private CandidateURI serialize(CandidateURI cauri)
59 throws IOException, ClassNotFoundException {
60 ByteArrayOutputStream baos = new ByteArrayOutputStream();
61 ObjectOutputStream oos = new ObjectOutputStream(baos);
62 oos.writeObject(cauri);
63 oos.flush();
64 oos.close();
65 ByteArrayInputStream bais =
66 new ByteArrayInputStream(baos.toByteArray());
67 return (CandidateURI)(new ObjectInputStream(bais)).readObject();
68 }
69 }