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.settings;
26
27 import java.io.File;
28
29 import javax.management.Attribute;
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 abstract class SettingsFrameworkTestCase extends TmpDirTestCase implements
44 ValueErrorHandler {
45 private File orderFile;
46 private File 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
57
58 protected void setUp() throws Exception {
59 super.setUp();
60 cleanUpOldFiles("SETTINGS");
61 orderFile = new File(getTmpDir(), "SETTINGS_order.xml");
62 String settingsDirName = "SETTINGS_per_host_settings";
63 settingsDir = new File(orderFile, settingsDirName);
64 settingsHandler = new XMLSettingsHandler(orderFile);
65 settingsHandler.initialize();
66 settingsHandler.getOrder().setAttribute(
67 new Attribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY, settingsDirName));
68
69 globalSettings = settingsHandler.getSettingsObject(null);
70 perDomainSettings = settingsHandler.getOrCreateSettingsObject("archive.org");
71 perHostSettings = settingsHandler.getOrCreateSettingsObject("www.archive.org");
72
73 new ServerCache(getSettingsHandler());
74
75 unMatchedURI = new CrawlURI(
76 UURIFactory.getInstance("http://localhost.com/index.html"));
77
78 matchDomainURI = new CrawlURI(
79 UURIFactory.getInstance("http://audio.archive.org/index.html"));
80
81 matchHostURI = new CrawlURI(
82 UURIFactory.getInstance("http://www.archive.org/index.html"));
83
84
85
86 MapType httpHeaders = (MapType)globalSettings.
87 getModule(CrawlOrder.ATTR_NAME).
88 getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
89 httpHeaders.setAttribute(globalSettings,
90 new Attribute(CrawlOrder.ATTR_USER_AGENT,
91 "unittest (+http://testing.one.two.three)"));
92 httpHeaders.setAttribute(globalSettings,
93 new Attribute(CrawlOrder.ATTR_FROM,
94 "unittestingtesting@one.two.three"));
95 }
96
97
98
99
100 protected void tearDown() throws Exception {
101 super.tearDown();
102 cleanUpOldFiles("SETTINGS");
103 }
104
105 /***
106 * @return global settings
107 */
108 public CrawlerSettings getGlobalSettings() {
109 return globalSettings;
110 }
111
112 /***
113 * @return per domain settings
114 */
115 public CrawlerSettings getPerDomainSettings() {
116 return perDomainSettings;
117 }
118
119 /***
120 * @return per host settings
121 */
122 public CrawlerSettings getPerHostSettings() {
123 return perHostSettings;
124 }
125
126 /***
127 * @return settings handler
128 */
129 public XMLSettingsHandler getSettingsHandler() {
130 return settingsHandler;
131 }
132
133 /***
134 * @return the order file
135 */
136 public File getOrderFile() {
137 return orderFile;
138 }
139
140 /***
141 * @return the settings directory
142 */
143 public File getSettingsDir() {
144 return settingsDir;
145 }
146
147 /***
148 * @return a uri matching the domain settings
149 */
150 public CrawlURI getMatchDomainURI() {
151 return matchDomainURI;
152 }
153
154 /***
155 * @return a uri matching the per host settings
156 */
157 public CrawlURI getMatchHostURI() {
158 return matchHostURI;
159 }
160
161 /***
162 * @return a uri that doesn't match any settings object except globals.
163 */
164 public CrawlURI getUnMatchedURI() {
165 return unMatchedURI;
166 }
167
168
169
170
171 public void handleValueError(FailedCheck error) {
172
173 }
174
175 }