KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* SettingsFrameworkTestCase
2  *
3  * $Id: SettingsFrameworkTestCase.java,v 1.8 2005/07/18 17:29:56 stack-sf Exp $
4  *
5  * Created on Feb 2, 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.File JavaDoc;
28
29 import javax.management.Attribute JavaDoc;
30
31 import org.archive.crawler.datamodel.CrawlOrder;
32 import org.archive.crawler.datamodel.CrawlURI;
33 import org.archive.crawler.datamodel.ServerCache;
34 import org.archive.crawler.settings.Constraint.FailedCheck;
35 import org.archive.net.UURIFactory;
36 import org.archive.util.TmpDirTestCase;
37
38 /** Set up a couple of settings to test different functions of the settings
39  * framework.
40  *
41  * @author John Erik Halse
42  */

43 public class SettingsFrameworkTestCase extends TmpDirTestCase implements
44         ValueErrorHandler {
45     private File JavaDoc orderFile;
46     private File JavaDoc settingsDir;
47     private CrawlerSettings globalSettings;
48     private CrawlerSettings perDomainSettings;
49     private CrawlerSettings perHostSettings;
50     protected XMLSettingsHandler settingsHandler;
51     private CrawlURI unMatchedURI;
52     private CrawlURI matchDomainURI;
53     private CrawlURI matchHostURI;
54
55     /*
56      * @see TmpDirTestCase#setUp()
57      */

58     protected void setUp() throws Exception JavaDoc {
59         super.setUp();
60         orderFile = new File JavaDoc(getTmpDir(), "SETTINGS_order.xml");
61         String JavaDoc settingsDirName = "SETTINGS_per_host_settings";
62         settingsDir = new File JavaDoc(orderFile, settingsDirName);
63         settingsHandler = new XMLSettingsHandler(orderFile);
64         settingsHandler.initialize();
65         settingsHandler.getOrder().setAttribute(
66           new Attribute JavaDoc(CrawlOrder.ATTR_SETTINGS_DIRECTORY, settingsDirName));
67
68         globalSettings = settingsHandler.getSettingsObject(null);
69         perDomainSettings = settingsHandler.getOrCreateSettingsObject("archive.org");
70         perHostSettings = settingsHandler.getOrCreateSettingsObject("www.archive.org");
71
72         new ServerCache(getSettingsHandler());
73
74         unMatchedURI = new CrawlURI(
75             UURIFactory.getInstance("http://localhost.com/index.html"));
76
77         matchDomainURI = new CrawlURI(
78             UURIFactory.getInstance("http://audio.archive.org/index.html"));
79
80         matchHostURI = new CrawlURI(
81             UURIFactory.getInstance("http://www.archive.org/index.html"));
82
83         // Write legit email and url so we avoid warnings if tests are reading
84
// and writing order files.
85
MapType httpHeaders = (MapType)globalSettings.
86             getModule(CrawlOrder.ATTR_NAME).
87                 getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
88         httpHeaders.setAttribute(globalSettings,
89             new Attribute JavaDoc(CrawlOrder.ATTR_USER_AGENT,
90                 "unittest (+http://testing.one.two.three)"));
91         httpHeaders.setAttribute(globalSettings,
92                 new Attribute JavaDoc(CrawlOrder.ATTR_FROM,
93                     "unittestingtesting@one.two.three"));
94     }
95
96     /*
97      * @see TmpDirTestCase#tearDown()
98      */

99     protected void tearDown() throws Exception JavaDoc {
100         super.tearDown();
101         cleanUpOldFiles("SETTINGS");
102     }
103
104     /**
105      * @return global settings
106      */

107     public CrawlerSettings getGlobalSettings() {
108         return globalSettings;
109     }
110
111     /**
112      * @return per domain settings
113      */

114     public CrawlerSettings getPerDomainSettings() {
115         return perDomainSettings;
116     }
117
118     /**
119      * @return per host settings
120      */

121     public CrawlerSettings getPerHostSettings() {
122         return perHostSettings;
123     }
124
125     /**
126      * @return settings handler
127      */

128     public XMLSettingsHandler getSettingsHandler() {
129         return settingsHandler;
130     }
131
132     /**
133      * @return the order file
134      */

135     public File JavaDoc getOrderFile() {
136         return orderFile;
137     }
138
139     /**
140      * @return the settings directory
141      */

142     public File JavaDoc getSettingsDir() {
143         return settingsDir;
144     }
145
146     /**
147      * @return a uri matching the domain settings
148      */

149     public CrawlURI getMatchDomainURI() {
150         return matchDomainURI;
151     }
152
153     /**
154      * @return a uri matching the per host settings
155      */

156     public CrawlURI getMatchHostURI() {
157         return matchHostURI;
158     }
159
160     /**
161      * @return a uri that doesn't match any settings object except globals.
162      */

163     public CrawlURI getUnMatchedURI() {
164         return unMatchedURI;
165     }
166
167     /* (non-Javadoc)
168      * @see org.archive.crawler.settings.ValueErrorHandler#handleValueError(org.archive.crawler.settings.Constraint.FailedCheck)
169      */

170     public void handleValueError(FailedCheck error) {
171         // TODO Auto-generated method stub
172
}
173
174 }
175
Popular Tags