KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > selftest > MaxLinkHopsSelfTest


1 /* MaxLinkHopsSelfTest
2  *
3  * Created on Feb 17, 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.selftest;
24
25 import java.io.File JavaDoc;
26 import java.util.Arrays JavaDoc;
27 import java.util.List JavaDoc;
28
29 import javax.management.AttributeNotFoundException JavaDoc;
30 import javax.management.MBeanException JavaDoc;
31 import javax.management.ReflectionException JavaDoc;
32
33 import org.archive.crawler.framework.CrawlScope;
34 import org.archive.crawler.scope.ClassicScope;
35
36
37 /**
38  * Test the max-link-hops setting.
39  *
40  * @author stack
41  * @version $Id: MaxLinkHopsSelfTest.java,v 1.7.18.1 2007/01/13 01:31:26 stack-sf Exp $
42  */

43 public class MaxLinkHopsSelfTest
44     extends SelfTestCase
45 {
46     /**
47      * Files to find as a list.
48      */

49     private static final List JavaDoc<File JavaDoc> FILES_TO_FIND =
50         Arrays.asList(new File JavaDoc[] {new File JavaDoc("2.html"),
51             new File JavaDoc("3.html"), new File JavaDoc("4.html"), new File JavaDoc("5.html")});
52
53     /**
54      * Files not to find as a list.
55      */

56     private static final List JavaDoc FILES_NOT_TO_FIND =
57         Arrays.asList(new File JavaDoc[] {new File JavaDoc("1.html"), new File JavaDoc("6.html")});
58
59     /**
60      * Assumption is that the setting for max-link-hops is less than this
61      * number.
62      */

63     private static final int MAXLINKHOPS = 5;
64
65
66     /**
67      * Test the max-link-hops setting is being respected.
68      */

69     public void testMaxLinkHops()
70         throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
71     {
72         CrawlScope scope =
73            (CrawlScope)getCrawlJob().getSettingsHandler()
74            .getModule(CrawlScope.ATTR_NAME);
75         int maxLinkHops =
76             ((Integer JavaDoc)scope.getAttribute(ClassicScope.ATTR_MAX_LINK_HOPS))
77             .intValue();
78         assertTrue("max-link-hops incorrect", MAXLINKHOPS == maxLinkHops);
79
80         // Make sure file we're NOT supposed to find is actually on disk.
81
assertTrue("File present on disk", filesExist(FILES_NOT_TO_FIND));
82
83         // Ok. The file not to find exists. Lets see if it made it into arc.
84
testFilesInArc(FILES_TO_FIND);
85     }
86 }
87
88
Popular Tags