001: /* SettingsFrameworkTestCase
002: *
003: * $Id: SettingsFrameworkTestCase.java 4928 2007-02-21 10:19:40Z gojomo $
004: *
005: * Created on Feb 2, 2004
006: *
007: * Copyright (C) 2004 Internet Archive.
008: *
009: * This file is part of the Heritrix web crawler (crawler.archive.org).
010: *
011: * Heritrix is free software; you can redistribute it and/or modify
012: * it under the terms of the GNU Lesser Public License as published by
013: * the Free Software Foundation; either version 2.1 of the License, or
014: * any later version.
015: *
016: * Heritrix is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU Lesser Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser Public License
022: * along with Heritrix; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: */
025: package org.archive.crawler.settings;
026:
027: import java.io.File;
028:
029: import javax.management.Attribute;
030:
031: import org.archive.crawler.datamodel.CrawlOrder;
032: import org.archive.crawler.datamodel.CrawlURI;
033: import org.archive.crawler.datamodel.ServerCache;
034: import org.archive.crawler.settings.Constraint.FailedCheck;
035: import org.archive.net.UURIFactory;
036: import org.archive.util.TmpDirTestCase;
037:
038: /** Set up a couple of settings to test different functions of the settings
039: * framework.
040: *
041: * @author John Erik Halse
042: */
043: public abstract class SettingsFrameworkTestCase extends TmpDirTestCase
044: implements ValueErrorHandler {
045: private File orderFile;
046: private File settingsDir;
047: private CrawlerSettings globalSettings;
048: private CrawlerSettings perDomainSettings;
049: private CrawlerSettings perHostSettings;
050: protected XMLSettingsHandler settingsHandler;
051: private CrawlURI unMatchedURI;
052: private CrawlURI matchDomainURI;
053: private CrawlURI matchHostURI;
054:
055: /*
056: * @see TmpDirTestCase#setUp()
057: */
058: protected void setUp() throws Exception {
059: super .setUp();
060: orderFile = new File(getTmpDir(), "SETTINGS_order.xml");
061: String settingsDirName = "SETTINGS_per_host_settings";
062: settingsDir = new File(orderFile, settingsDirName);
063: settingsHandler = new XMLSettingsHandler(orderFile);
064: settingsHandler.initialize();
065: settingsHandler.getOrder().setAttribute(
066: new Attribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY,
067: settingsDirName));
068:
069: globalSettings = settingsHandler.getSettingsObject(null);
070: perDomainSettings = settingsHandler
071: .getOrCreateSettingsObject("archive.org");
072: perHostSettings = settingsHandler
073: .getOrCreateSettingsObject("www.archive.org");
074:
075: new ServerCache(getSettingsHandler());
076:
077: unMatchedURI = new CrawlURI(UURIFactory
078: .getInstance("http://localhost.com/index.html"));
079:
080: matchDomainURI = new CrawlURI(UURIFactory
081: .getInstance("http://audio.archive.org/index.html"));
082:
083: matchHostURI = new CrawlURI(UURIFactory
084: .getInstance("http://www.archive.org/index.html"));
085:
086: // Write legit email and url so we avoid warnings if tests are reading
087: // and writing order files.
088: MapType httpHeaders = (MapType) globalSettings.getModule(
089: CrawlOrder.ATTR_NAME).getAttribute(
090: CrawlOrder.ATTR_HTTP_HEADERS);
091: httpHeaders.setAttribute(globalSettings, new Attribute(
092: CrawlOrder.ATTR_USER_AGENT,
093: "unittest (+http://testing.one.two.three)"));
094: httpHeaders.setAttribute(globalSettings, new Attribute(
095: CrawlOrder.ATTR_FROM,
096: "unittestingtesting@one.two.three"));
097: }
098:
099: /*
100: * @see TmpDirTestCase#tearDown()
101: */
102: protected void tearDown() throws Exception {
103: super .tearDown();
104: cleanUpOldFiles("SETTINGS");
105: }
106:
107: /**
108: * @return global settings
109: */
110: public CrawlerSettings getGlobalSettings() {
111: return globalSettings;
112: }
113:
114: /**
115: * @return per domain settings
116: */
117: public CrawlerSettings getPerDomainSettings() {
118: return perDomainSettings;
119: }
120:
121: /**
122: * @return per host settings
123: */
124: public CrawlerSettings getPerHostSettings() {
125: return perHostSettings;
126: }
127:
128: /**
129: * @return settings handler
130: */
131: public XMLSettingsHandler getSettingsHandler() {
132: return settingsHandler;
133: }
134:
135: /**
136: * @return the order file
137: */
138: public File getOrderFile() {
139: return orderFile;
140: }
141:
142: /**
143: * @return the settings directory
144: */
145: public File getSettingsDir() {
146: return settingsDir;
147: }
148:
149: /**
150: * @return a uri matching the domain settings
151: */
152: public CrawlURI getMatchDomainURI() {
153: return matchDomainURI;
154: }
155:
156: /**
157: * @return a uri matching the per host settings
158: */
159: public CrawlURI getMatchHostURI() {
160: return matchHostURI;
161: }
162:
163: /**
164: * @return a uri that doesn't match any settings object except globals.
165: */
166: public CrawlURI getUnMatchedURI() {
167: return unMatchedURI;
168: }
169:
170: /* (non-Javadoc)
171: * @see org.archive.crawler.settings.ValueErrorHandler#handleValueError(org.archive.crawler.settings.Constraint.FailedCheck)
172: */
173: public void handleValueError(FailedCheck error) {
174: // TODO Auto-generated method stub
175: }
176:
177: }
|