001: /* AllTests
002: *
003: * Created on Jan 29, 2004
004: *
005: * Copyright (C) 2004 Internet Archive.
006: *
007: * This file is part of the Heritrix web crawler (crawler.archive.org).
008: *
009: * Heritrix is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU Lesser Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * any later version.
013: *
014: * Heritrix is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU Lesser Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser Public License
020: * along with Heritrix; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: package org.archive.crawler.selftest;
024:
025: import java.io.File;
026: import java.util.Arrays;
027: import java.util.Collections;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: import junit.extensions.TestSetup;
032: import junit.framework.Test;
033: import junit.framework.TestSuite;
034:
035: import org.archive.crawler.admin.CrawlJob;
036:
037: /**
038: * All registered heritrix selftests.
039: *
040: * @author stack
041: * @version $Id: AllSelfTestCases.java 4931 2007-02-21 18:48:17Z gojomo $
042: */
043: public class AllSelfTestCases {
044: /**
045: * All known selftests as a list.
046: *
047: * Gets initialized by the static block that immediately follows.
048: */
049: private static List allKnownSelftests;
050: static {
051: // List of all known selftests.
052: Class[] tmp = { BackgroundImageExtractionSelfTestCase.class,
053: FramesSelfTestCase.class, MaxLinkHopsSelfTest.class,
054: CharsetSelfTest.class, AuthSelfTest.class,
055: BadURIsStopPageParsingSelfTest.class,
056: // Works locally but not on builds.archive.org.
057: // FlashParseSelfTest.class
058: CheckpointSelfTest.class, };
059: AllSelfTestCases.allKnownSelftests = Collections
060: .unmodifiableList(Arrays.asList(tmp));
061: }
062:
063: /**
064: * Run all known tests in the selftest suite.
065: *
066: * Each unit test to run as part of selftest needs to be added here.
067: *
068: * @param selftestURL Base url to selftest webapp.
069: * @param job The completed selftest job.
070: * @param jobDir Job output directory. Has the seed file, the order file
071: * and logs.
072: * @param htdocs Expanded webapp directory location.
073: *
074: * @return Suite of all selftests.
075: */
076: public static Test suite(final String selftestURL,
077: final CrawlJob job, final File jobDir, final File htdocs) {
078: return suite(selftestURL, job, jobDir, htdocs,
079: AllSelfTestCases.allKnownSelftests);
080: }
081:
082: /**
083: * Run list of passed tests.
084: *
085: * This method is exposed so can run something less than all of the
086: * selftests.
087: *
088: * @param selftestURL Base url to selftest webapp.
089: * @param job The completed selftest job.
090: * @param jobDir Job output directory. Has the seed file, the order file
091: * and logs.
092: * @param htdocs Expanded webapp directory location.
093: * @param selftests List of selftests to run.
094: *
095: * @return Suite of all selftests.
096: */
097: public static Test suite(final String selftestURL,
098: final CrawlJob job, final File jobDir, final File htdocs,
099: final List selftests) {
100: TestSuite suite = new TestSuite(
101: "Test(s) for org.archive.crawler.selftest");
102: for (Iterator i = selftests.iterator(); i.hasNext();) {
103: suite.addTest(new AltTestSuite((Class) i.next(), "stest"));
104: }
105:
106: return new TestSetup(suite) {
107: protected void setUp() throws Exception {
108: SelfTestCase.initialize(selftestURL, job, jobDir,
109: htdocs);
110: }
111: };
112: }
113: }
|