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 orderFile = new File(getTmpDir(), "SETTINGS_order.xml");
61 String settingsDirName = "SETTINGS_per_host_settings";
62 settingsDir = new File(orderFile, settingsDirName);
63 settingsHandler = new XMLSettingsHandler(orderFile);
64 settingsHandler.initialize();
65 settingsHandler.getOrder().setAttribute(
66 new Attribute(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
84
85 MapType httpHeaders = (MapType)globalSettings.
86 getModule(CrawlOrder.ATTR_NAME).
87 getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
88 httpHeaders.setAttribute(globalSettings,
89 new Attribute(CrawlOrder.ATTR_USER_AGENT,
90 "unittest (+http://testing.one.two.three)"));
91 httpHeaders.setAttribute(globalSettings,
92 new Attribute(CrawlOrder.ATTR_FROM,
93 "unittestingtesting@one.two.three"));
94 }
95
96
97
98
99 protected void tearDown() throws Exception {
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 getOrderFile() {
136 return orderFile;
137 }
138
139 /***
140 * @return the settings directory
141 */
142 public File 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
168
169
170 public void handleValueError(FailedCheck error) {
171
172 }
173
174 }