View Javadoc

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;
26  import java.util.Arrays;
27  import java.util.List;
28  
29  import javax.management.AttributeNotFoundException;
30  import javax.management.MBeanException;
31  import javax.management.ReflectionException;
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 4931 2007-02-21 18:48:17Z gojomo $
42   */
43  public class MaxLinkHopsSelfTest
44      extends SelfTestCase
45  {
46      /***
47       * Files to find as a list.
48       */
49      private static final List<File> FILES_TO_FIND =
50          Arrays.asList(new File[] {new File("2.html"),
51              new File("3.html"), new File("4.html"), new File("5.html")});
52  
53      /***
54       * Files not to find as a list.
55       */
56      private static final List FILES_NOT_TO_FIND =
57          Arrays.asList(new File[] {new File("1.html"), new File("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 stestMaxLinkHops()
70          throws AttributeNotFoundException, MBeanException, ReflectionException
71      {
72          assertInitialized();
73          CrawlScope scope =
74             (CrawlScope)getCrawlJob().getSettingsHandler()
75             .getModule(CrawlScope.ATTR_NAME);
76          int maxLinkHops =
77              ((Integer)scope.getAttribute(ClassicScope.ATTR_MAX_LINK_HOPS))
78              .intValue();
79          assertTrue("max-link-hops incorrect", MAXLINKHOPS == maxLinkHops);
80  
81          // Make sure file we're NOT supposed to find is actually on disk.
82          assertTrue("File present on disk", filesExist(FILES_NOT_TO_FIND));
83  
84          // Ok.  The file not to find exists.  Lets see if it made it into arc.
85          testFilesInArc(FILES_TO_FIND);
86      }
87  }
88