KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > datamodel > CandidateURITest


1 /* CandidateURITest.java
2  *
3  * $Id: CandidateURITest.java,v 1.3 2005/08/29 21:52:36 stack-sf Exp $
4  *
5  * Created Jun 23, 2005
6  *
7  * Copyright (C) 2005 Internet Archive.
8  *
9  * This file is part of the Heritrix web crawler (crawler.archive.org).
10  *
11  * Heritrix is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or
14  * any later version.
15  *
16  * Heritrix is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser Public License
22  * along with Heritrix; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */

25 package org.archive.crawler.datamodel;
26
27 import java.io.ByteArrayInputStream JavaDoc;
28 import java.io.ByteArrayOutputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.ObjectInputStream JavaDoc;
31 import java.io.ObjectOutputStream JavaDoc;
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 JavaDoc, ClassNotFoundException JavaDoc {
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 JavaDoc urlStr)
50     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
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 JavaDoc, ClassNotFoundException JavaDoc {
60         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
61         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
62         oos.writeObject(cauri);
63         oos.flush();
64         oos.close();
65         ByteArrayInputStream JavaDoc bais =
66             new ByteArrayInputStream JavaDoc(baos.toByteArray());
67         return (CandidateURI)(new ObjectInputStream JavaDoc(bais)).readObject();
68     }
69 }
70
Popular Tags