KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > datamodel > ServerCacheTest


1 /* ServerCacheTest
2 *
3 * Created on August 4, 2004
4 *
5 * Copyright (C) 2004 Internet Archive.
6 *
7 * This file is part of the Heritrix web crawler (crawler.archive.org).
8 *
9 * Heritrix is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * any later version.
13 *
14 * Heritrix is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser Public License
20 * along with Heritrix; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.archive.crawler.datamodel;
24
25 import junit.framework.TestCase;
26
27 import org.apache.commons.httpclient.URIException;
28 import org.archive.crawler.settings.SettingsHandler;
29 import org.archive.net.UURI;
30 import org.archive.net.UURIFactory;
31
32 /**
33  * Test the BigMapServerCache
34  *
35  * @author gojomo
36  */

37 public class ServerCacheTest extends TestCase {
38     public void testHolds() throws Exception JavaDoc {
39         ServerCache servers = new ServerCache((SettingsHandler)null);
40         String JavaDoc serverKey = "www.example.com:9090";
41         String JavaDoc hostKey = "www.example.com";
42         servers.getServerFor(serverKey);
43         servers.getHostFor(hostKey);
44         assertTrue("cache lost server", servers.containsServer(serverKey));
45         assertTrue("cache lost host", servers.containsHost(hostKey));
46     }
47     
48     public void testCrawlURIKeys()
49     throws Exception JavaDoc {
50         ServerCache servers = new ServerCache((SettingsHandler)null);
51         testHostServer(servers, "http://www.example.com");
52         testHostServer(servers, "http://www.example.com:9090");
53         testHostServer(servers, "dns://www.example.com:9090");
54     }
55     
56     private void testHostServer(ServerCache servers, String JavaDoc uri)
57     throws URIException {
58         UURI uuri = UURIFactory.getInstance(uri);
59         CrawlURI curi = new CrawlURI(uuri);
60         servers.getServerFor(curi);
61         servers.getHostFor(curi);
62         assertTrue("cache lost server",
63             servers.containsServer(CrawlServer.getServerKey(curi)));
64         assertTrue("cache lost host",
65             servers.containsHost(curi.getUURI().getHost()));
66     }
67 }
Popular Tags