1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
54 Class [] tmp = {
55 BackgroundImageExtractionSelfTestCase.class,
56 FramesSelfTestCase.class,
57 MaxLinkHopsSelfTest.class,
58 CharsetSelfTest.class,
59 AuthSelfTest.class,
60 BadURIsStopPageParsingSelfTest.class,
61
62
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 }