1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.internal.server.runner;
22
23 import junit.framework.AssertionFailedError;
24 import junit.framework.Test;
25 import junit.runner.BaseTestRunner;
26
27 /**
28 * JUnit Test Runner that can load test cases that are in the classpath of
29 * a webapp. This test runner is supposed to be executed from within the
30 * webapp.
31 *
32 * @version $Id: WebappTestRunner.java 238991 2004-05-22 11:34:50Z vmassol $
33 */
34 public class WebappTestRunner extends BaseTestRunner
35 {
36 /**
37 * Error message if the suite failed to load.
38 */
39 private String errorMessage;
40
41 /**
42 * Overridden from BaseTestRunner in order to use either the context
43 * class loader or the webapp one.
44 *
45 * @return a loader that loads classes using the context class loader or
46 * the webapp class loader.
47 */
48 //public TestSuiteLoader getLoader()
49 //{
50 // return new WebappTestSuiteLoader();
51 //}
52 /**
53 * Returns the loaded Class for a suite name.
54 */
55 public Class loadSuiteClass(String theSuiteClassName)
56 throws ClassNotFoundException
57 {
58 WebappTestSuiteLoader loader = new WebappTestSuiteLoader();
59 return loader.load(theSuiteClassName);
60 }
61
62 /**
63 * Event called by the base test runner when it fails to load a test suite.
64 *
65 * @param theMessage the message of the failure
66 */
67 protected void runFailed(String theMessage)
68 {
69 this.errorMessage = theMessage;
70 }
71
72 /**
73 * @return the error message provided by <code>BaseTestRunner</code> if it
74 * failed to load the test suite
75 */
76 public String getErrorMessage()
77 {
78 return this.errorMessage;
79 }
80
81 /**
82 * Event called by the base test runner when the test ends.
83 *
84 * @param theTestName the test case name
85 */
86 public void testEnded(String theTestName)
87 {
88 // not used
89 }
90
91 /**
92 * Event called by the base test runner when the test fails.
93 *
94 * @param theStatus the status code of the error
95 * @param theTest the test object that failed
96 * @param theThrowable the exception that was thrown
97 */
98 public void testFailed(int theStatus, Test theTest, Throwable theThrowable)
99 {
100 // not used
101 }
102
103 /**
104 * Event called by the base test runner when the test starts.
105 *
106 * @param theTestName the test case name
107 */
108 public void testStarted(String theTestName)
109 {
110 // not used
111 }
112
113 /**
114 * {@inheritDoc}
115 * @see BaseTestRunner#addError(Test, Throwable)
116 */
117 public void addError(Test theTest, Throwable theThrowable)
118 {
119 // not used
120 }
121
122 /**
123 * {@inheritDoc}
124 * @see BaseTestRunner#addFailure(Test, AssertionFailedError)
125 */
126 public void addFailure(Test theTest,
127 AssertionFailedError theAssertionFailedError)
128 {
129 // not used
130 }
131
132 /**
133 * {@inheritDoc}
134 * @see BaseTestRunner#endTest(Test)
135 */
136 public void endTest(Test theTest)
137 {
138 // not used
139 }
140
141 /**
142 * {@inheritDoc}
143 * @see BaseTestRunner#startTest(Test)
144 */
145 public void startTest(Test theTest)
146 {
147 // not used
148 }
149 }