View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.logging.servlet;
19  
20  import org.apache.commons.logging.PathableClassLoader;
21  import org.apache.commons.logging.PathableTestSuite;
22  import org.apache.commons.logging.impl.ServletContextCleaner;
23  
24  import junit.framework.Test;
25  import junit.framework.TestCase;
26  
27  /**
28   * Tests for ServletContextCleaner utility class.
29   */
30  
31  public class BasicServletTestCase extends TestCase {
32  
33      /**
34       * Return the tests included in this test suite.
35       */
36      public static Test suite() throws Exception {
37          // LogFactory in parent
38          // LogFactory in child (loads test)
39          // LogFactory in tccl
40          //
41          // Having the test loaded via a loader above the tccl emulates the situation
42          // where a web.xml file specifies ServletContextCleaner as a listener, and
43          // that class is deployed via a shared class loader.
44  
45          final PathableClassLoader parent = new PathableClassLoader(null);
46          parent.useExplicitLoader("junit.", Test.class.getClassLoader());
47          parent.addLogicalLib("commons-logging");
48          parent.addLogicalLib("servlet-api");
49  
50          final PathableClassLoader child = new PathableClassLoader(parent);
51          child.setParentFirst(false);
52          child.addLogicalLib("commons-logging");
53          child.addLogicalLib("testclasses");
54  
55          final PathableClassLoader tccl = new PathableClassLoader(child);
56          tccl.setParentFirst(false);
57          tccl.addLogicalLib("commons-logging");
58  
59          final Class testClass = child.loadClass(BasicServletTestCase.class.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          final ServletContextCleaner scc = new ServletContextCleaner();
69          scc.contextDestroyed(null);
70      }
71  }