001: /*
002: * ========================================================================
003: *
004: * Copyright 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;
021:
022: import junit.framework.TestCase;
023: import org.apache.cactus.internal.AbstractCactusTestCase;
024: import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
025: import org.apache.cactus.internal.configuration.BaseConfiguration;
026: import org.apache.cactus.internal.configuration.DefaultServletConfiguration;
027: import org.apache.cactus.internal.util.TestCaseImplementError;
028: import org.apache.cactus.spi.client.connector.ProtocolHandler;
029:
030: /**
031: * Unit tests of the <code>AbstractTestCase</code> class and its subclasses.
032: *
033: * @version $Id: TestNoNameTestCase.java 238991 2004-05-22 11:34:50Z vmassol $
034: */
035: public class TestNoNameTestCase extends TestCase {
036: /**
037: * Sample subclass of AbstractCactusTestCase of which the constructor
038: * and setName() don't set test name.
039: */
040: class NoNameTestCase extends AbstractCactusTestCase {
041: /**
042: * default constructor
043: */
044: public NoNameTestCase() {
045: }
046:
047: /**
048: * Construct without super(theName)
049: * @param theName name of the test
050: */
051: public NoNameTestCase(String theName) {
052: }
053:
054: /**
055: * override junit.framework.TestCase#setName(String).
056: * @param theName name of the test
057: */
058: public void setName(String theName) {
059: }
060:
061: /**
062: * dummy implementation
063: * @return ProtocolHandler always return null
064: */
065: protected ProtocolHandler createProtocolHandler() {
066: return new HttpProtocolHandler(
067: new DefaultServletConfiguration());
068: }
069:
070: /**
071: * dummy test entry
072: */
073: public void testNoName() {
074: }
075: }
076:
077: /**
078: * Sample subclass of ServletTestCase of which the constructor
079: * and setName() don't set test name.
080: */
081: class NoNameServletTestCase extends ServletTestCase {
082: /**
083: * default constructor
084: */
085: public NoNameServletTestCase() {
086: }
087:
088: /**
089: * Construct without super(theName)
090: * @param theName name of the test
091: */
092: public NoNameServletTestCase(String theName) {
093: }
094:
095: /**
096: * override junit.framework.TestCase#setName(String).
097: * @param theName name of the test
098: */
099: public void setName(String theName) {
100: }
101:
102: /**
103: * dummy test entry
104: */
105: public void testNoName() {
106: }
107: }
108:
109: /**
110: * Sample subclass of JspTestCase of which the constructor
111: * and setName() don't set test name.
112: */
113: class NoNameJspTestCase extends JspTestCase {
114: /**
115: * default constructor
116: */
117: public NoNameJspTestCase() {
118: }
119:
120: /**
121: * Construct without super(theName)
122: * @param theName name of the test
123: */
124: public NoNameJspTestCase(String theName) {
125: }
126:
127: /**
128: * override junit.framework.TestCase#setName(String).
129: * @param theName name of the test
130: */
131: public void setName(String theName) {
132: }
133:
134: /**
135: * dummy test entry
136: */
137: public void testNoName() {
138: }
139: }
140:
141: /**
142: * set cactus.contextURL as a system property.
143: */
144: public void setUp() {
145: System.setProperty(
146: BaseConfiguration.CACTUS_CONTEXT_URL_PROPERTY,
147: "http://localhost/dummy");
148: }
149:
150: /**
151: * @param theName name of the test
152: */
153: public TestNoNameTestCase(String theName) {
154: super (theName);
155: }
156:
157: /**
158: * @param theTest the test to test
159: */
160: private void executeRunBare(TestCase theTest) {
161: try {
162: theTest.runBare();
163: fail("test should fail");
164: } catch (Throwable t) {
165: assertEquals(TestCaseImplementError.class.getName(), t
166: .getClass().getName());
167: String message = t.getMessage();
168: assertNotNull("no message", message);
169: assertEquals("No test name found. " + "The test ["
170: + theTest.getClass().getName()
171: + "] is not properly implemented.", message);
172: }
173: }
174:
175: /**
176: * Test subclass of AbstractCactusTestCase.
177: * Set the test name by constructor NoNameTestCase(String).
178: */
179: public void testNoNameTestCase() {
180: TestCase test;
181: test = new NoNameTestCase("testNoName");
182: executeRunBare(test);
183: }
184:
185: /**
186: * Test subclass of AbstractCactusTestCase.
187: * Set the test name by TestCase#setName(String).
188: */
189: public void testNoNameTestCaseWithSetName() {
190: TestCase test;
191: test = new NoNameTestCase();
192: test.setName("testNoName");
193: executeRunBare(test);
194: }
195:
196: /**
197: * Test subclass of ServletTestCase.
198: * Set the test name by constructor NoNameTestCase(String).
199: */
200: public void testNoNameServletTestCase() {
201: TestCase test;
202: test = new NoNameServletTestCase("testNoName");
203: executeRunBare(test);
204: }
205:
206: /**
207: * Test subclass of ServletTestCase.
208: * Set the test name by TestCase#setName(String).
209: */
210: public void testNoNameServletTestCaseWithSetName() {
211: TestCase test;
212: test = new NoNameServletTestCase();
213: test.setName("testNoName");
214: executeRunBare(test);
215: }
216:
217: /**
218: * Test subclass of JspTestCase.
219: * Set the test name by constructor NoNameTestCase(String).
220: */
221: public void testNoNameJspTestCase() {
222: TestCase test;
223: test = new NoNameJspTestCase("testNoName");
224: executeRunBare(test);
225: }
226:
227: /**
228: * Test subclass of JspTestCase.
229: * Set the test name by TestCase#setName(String).
230: */
231: public void testNoNameJspTestCaseWithSetName() {
232: TestCase test;
233: test = new NoNameJspTestCase();
234: test.setName("testNoName");
235: executeRunBare(test);
236: }
237: }
|