View Javadoc

1   /* AllTests
2    *
3    * Created on Jan 29, 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.Collections;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  import junit.extensions.TestSetup;
32  import junit.framework.Test;
33  import junit.framework.TestSuite;
34  
35  import org.archive.crawler.admin.CrawlJob;
36  
37  
38  /***
39   * All registered heritrix selftests.
40   *
41   * @author stack
42   * @version $Id: AllSelfTestCases.java 4931 2007-02-21 18:48:17Z gojomo $
43   */
44  public class AllSelfTestCases
45  {
46      /***
47       * All known selftests as a list.
48       *
49       * Gets initialized by the static block that immediately follows.
50       */
51      private static List allKnownSelftests;
52      static {
53          // List of all known selftests.
54          Class [] tmp = {
55                  BackgroundImageExtractionSelfTestCase.class,
56                  FramesSelfTestCase.class,
57                  MaxLinkHopsSelfTest.class,
58                  CharsetSelfTest.class,
59                  AuthSelfTest.class,
60                  BadURIsStopPageParsingSelfTest.class,
61                  // Works locally but not on builds.archive.org.
62                  // FlashParseSelfTest.class
63                  CheckpointSelfTest.class,
64              };
65          AllSelfTestCases.allKnownSelftests =
66              Collections.unmodifiableList(Arrays.asList(tmp));
67      }
68  
69      /***
70       * Run all known tests in the selftest suite.
71       *
72       * Each unit test to run as part of selftest needs to be added here.
73       *
74       * @param selftestURL Base url to selftest webapp.
75       * @param job The completed selftest job.
76       * @param jobDir Job output directory.  Has the seed file, the order file
77       * and logs.
78       * @param htdocs Expanded webapp directory location.
79       *
80       * @return Suite of all selftests.
81       */
82      public static Test suite(final String selftestURL, final CrawlJob job,
83              final File jobDir, final File htdocs)
84      {
85          return suite(selftestURL, job, jobDir, htdocs,
86               AllSelfTestCases.allKnownSelftests);
87      }
88  
89      /***
90       * Run list of passed tests.
91       *
92       * This method is exposed so can run something less than all of the
93       * selftests.
94       *
95       * @param selftestURL Base url to selftest webapp.
96       * @param job The completed selftest job.
97       * @param jobDir Job output directory.  Has the seed file, the order file
98       * and logs.
99       * @param htdocs Expanded webapp directory location.
100      * @param selftests List of selftests to run.
101      *
102      * @return Suite of all selftests.
103      */
104     public static Test suite(final String selftestURL, final CrawlJob job,
105             final File jobDir, final File htdocs, final List selftests) {
106         TestSuite suite =
107             new TestSuite("Test(s) for org.archive.crawler.selftest");
108         for (Iterator i = selftests.iterator(); i.hasNext();) {
109             suite.addTest(new AltTestSuite((Class)i.next(),"stest"));
110         }
111 
112         return new TestSetup(suite) {
113                 protected void setUp() throws Exception {
114                     SelfTestCase.initialize(selftestURL, job, jobDir, htdocs);
115                 }
116         };
117     }
118 }