01: /*
02: * Copyright 2006 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.logging.log4j.log4j12;
18:
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21:
22: import org.apache.commons.logging.PathableClassLoader;
23: import org.apache.commons.logging.PathableTestSuite;
24: import org.apache.commons.logging.impl.ServletContextCleaner;
25:
26: /**
27: * Tests for ServletContextCleaner utility class.
28: */
29:
30: public class BasicServletTestCase extends TestCase {
31:
32: /**
33: * Return the tests included in this test suite.
34: */
35: public static Test suite() throws Exception {
36: // LogFactory in parent
37: // LogFactory in child (loads test)
38: // LogFactory in tccl
39: //
40: // Having the test loaded via a loader above the tccl emulates the situation
41: // where a web.xml file specifies ServletContextCleaner as a listener, and
42: // that class is deployed via a shared classloader.
43:
44: PathableClassLoader parent = new PathableClassLoader(null);
45: parent.useSystemLoader("junit.");
46: parent.addLogicalLib("commons-logging");
47: parent.addLogicalLib("servletapi");
48:
49: PathableClassLoader child = new PathableClassLoader(parent);
50: child.setParentFirst(false);
51: child.addLogicalLib("commons-logging");
52: child.addLogicalLib("testclasses");
53:
54: PathableClassLoader tccl = new PathableClassLoader(child);
55: tccl.setParentFirst(false);
56: tccl.addLogicalLib("commons-logging");
57:
58: Class testClass = child.loadClass(BasicServletTestCase.class
59: .getName());
60: return new PathableTestSuite(testClass, tccl);
61: }
62:
63: /**
64: * Test that calling ServletContextCleaner.contextDestroyed doesn't crash.
65: * Testing anything else is rather difficult...
66: */
67: public void testBasics() {
68: ServletContextCleaner scc = new ServletContextCleaner();
69: scc.contextDestroyed(null);
70: }
71: }
|