001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2004 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.internal.server.runner;
021:
022: import junit.framework.AssertionFailedError;
023: import junit.framework.Test;
024: import junit.runner.BaseTestRunner;
025: import junit.runner.TestSuiteLoader;
026:
027: /**
028: * JUnit Test Runner that can load test cases that are in the classpath of
029: * a webapp. This test runner is supposed to be executed from within the
030: * webapp.
031: *
032: * @version $Id: WebappTestRunner.java 238991 2004-05-22 11:34:50Z vmassol $
033: */
034: public class WebappTestRunner extends BaseTestRunner {
035: /**
036: * Error message if the suite failed to load.
037: */
038: private String errorMessage;
039:
040: /**
041: * Overridden from BaseTestRunner in order to use either the context
042: * class loader or the webapp one.
043: *
044: * @return a loader that loads classes using the context class loader or
045: * the webapp class loader.
046: */
047: public TestSuiteLoader getLoader() {
048: return new WebappTestSuiteLoader();
049: }
050:
051: /**
052: * Event called by the base test runner when it fails to load a test suite.
053: *
054: * @param theMessage the message of the failure
055: */
056: protected void runFailed(String theMessage) {
057: this .errorMessage = theMessage;
058: }
059:
060: /**
061: * @return the error message provided by <code>BaseTestRunner</code> if it
062: * failed to load the test suite
063: */
064: public String getErrorMessage() {
065: return this .errorMessage;
066: }
067:
068: /**
069: * Event called by the base test runner when the test ends.
070: *
071: * @param theTestName the test case name
072: */
073: public void testEnded(String theTestName) {
074: // not used
075: }
076:
077: /**
078: * Event called by the base test runner when the test fails.
079: *
080: * @param theStatus the status code of the error
081: * @param theTest the test object that failed
082: * @param theThrowable the exception that was thrown
083: */
084: public void testFailed(int theStatus, Test theTest,
085: Throwable theThrowable) {
086: // not used
087: }
088:
089: /**
090: * Event called by the base test runner when the test starts.
091: *
092: * @param theTestName the test case name
093: */
094: public void testStarted(String theTestName) {
095: // not used
096: }
097:
098: /**
099: * @see BaseTestRunner#addError(Test, Throwable)
100: */
101: public void addError(Test theTest, Throwable theThrowable) {
102: // not used
103: }
104:
105: /**
106: * @see BaseTestRunner#addFailure(Test, AssertionFailedError)
107: */
108: public void addFailure(Test theTest,
109: AssertionFailedError theAssertionFailedError) {
110: // not used
111: }
112:
113: /**
114: * @see BaseTestRunner#endTest(Test)
115: */
116: public void endTest(Test theTest) {
117: // not used
118: }
119:
120: /**
121: * @see BaseTestRunner#startTest(Test)
122: */
123: public void startTest(Test theTest) {
124: // not used
125: }
126: }
|