KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > settings > CrawlerSettingsTest


1 /* CrawlerSettingsTest
2  *
3  * $Id: CrawlerSettingsTest.java,v 1.3.16.1 2007/01/13 01:31:27 stack-sf Exp $
4  *
5  * Created on Jan 28, 2004
6  *
7  * Copyright (C) 2004 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.settings;
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 javax.management.AttributeNotFoundException JavaDoc;
34 import javax.management.MBeanException JavaDoc;
35 import javax.management.ReflectionException JavaDoc;
36
37
38 /** Test the CrawlerSettings object
39  *
40  * @author John Erik Halse
41  */

42 public class CrawlerSettingsTest extends SettingsFrameworkTestCase {
43
44     /*
45      * @see TestCase#setUp()
46      */

47     protected void setUp() throws Exception JavaDoc {
48         super.setUp();
49     }
50
51     /*
52      * @see TestCase#tearDown()
53      */

54     protected void tearDown() throws Exception JavaDoc {
55         super.tearDown();
56     }
57
58     final public void testAddComplexType() {
59         ModuleType mod = new ModuleType("name");
60         DataContainer data = getGlobalSettings().addComplexType(mod);
61         assertNotNull(data);
62     }
63
64     final public void testGetModule() {
65         ModuleType mod = new ModuleType("name");
66         getGlobalSettings().addComplexType(mod);
67         assertSame(mod, getGlobalSettings().getModule("name"));
68     }
69     
70     public void testSerializingSimpleModuleType()
71     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
72         ModuleType mt =
73             new ModuleType("testSerializingSimpleModuleType");
74         ModuleType mtDeserialized = (ModuleType)serializeDeserialize(mt);
75         assertEquals(mt.getName(), mtDeserialized.getName());
76     }
77     
78     public void testSerializingStringAttributeModuleType()
79     throws IOException JavaDoc, ClassNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
80     MBeanException JavaDoc, ReflectionException JavaDoc {
81         ModuleType mt =
82             new ModuleType("testSerializingStringAttributeModuleType");
83         final String JavaDoc value = "value";
84         mt.addElementToDefinition(new SimpleType("name", "description",
85             value));
86         ModuleType mtDeserialized = (ModuleType)serializeDeserialize(mt);
87         assertEquals(mt.getName(), mtDeserialized.getName());
88         assertEquals(value, (String JavaDoc)mtDeserialized.getAttribute("name"));
89     }
90     
91     public void testSerializingTextField()
92     throws IOException JavaDoc, ClassNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
93     MBeanException JavaDoc, ReflectionException JavaDoc {
94         TextField tf = new TextField("testSerializingTextField");
95         TextField tfDeserialized = (TextField)serializeDeserialize(tf);
96         assertEquals(tf.toString(), tfDeserialized.toString());
97     }
98     
99     protected Object JavaDoc serializeDeserialize(Object JavaDoc obj)
100     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
101         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
102         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
103         oos.writeObject(obj);
104         oos.close();
105         byte [] objectBytes = baos.toByteArray();
106         ObjectInputStream JavaDoc ois =
107             new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(objectBytes));
108         return ois.readObject();
109     }
110 }
111
Popular Tags