1 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 43 public 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 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 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 99 protected void tearDown() throws Exception { 100 super.tearDown(); 101 cleanUpOldFiles("SETTINGS"); 102 } 103 104 107 public CrawlerSettings getGlobalSettings() { 108 return globalSettings; 109 } 110 111 114 public CrawlerSettings getPerDomainSettings() { 115 return perDomainSettings; 116 } 117 118 121 public CrawlerSettings getPerHostSettings() { 122 return perHostSettings; 123 } 124 125 128 public XMLSettingsHandler getSettingsHandler() { 129 return settingsHandler; 130 } 131 132 135 public File getOrderFile() { 136 return orderFile; 137 } 138 139 142 public File getSettingsDir() { 143 return settingsDir; 144 } 145 146 149 public CrawlURI getMatchDomainURI() { 150 return matchDomainURI; 151 } 152 153 156 public CrawlURI getMatchHostURI() { 157 return matchHostURI; 158 } 159 160 163 public CrawlURI getUnMatchedURI() { 164 return unMatchedURI; 165 } 166 167 170 public void handleValueError(FailedCheck error) { 171 } 173 174 } 175 | Popular Tags |