001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    
018    package org.apache.commons.logging.servlet;
019    
020    import junit.framework.Test;
021    import junit.framework.TestCase;
022    
023    import org.apache.commons.logging.PathableClassLoader;
024    import org.apache.commons.logging.PathableTestSuite;
025    import org.apache.commons.logging.impl.ServletContextCleaner;
026    
027    
028    /**
029     * Tests for ServletContextCleaner utility class.
030     */
031    
032    public class BasicServletTestCase extends TestCase {
033    
034        /**
035         * Return the tests included in this test suite.
036         */
037        public static Test suite() throws Exception {
038            // LogFactory in parent
039            // LogFactory in child (loads test)
040            // LogFactory in tccl
041            //
042            // Having the test loaded via a loader above the tccl emulates the situation
043            // where a web.xml file specifies ServletContextCleaner as a listener, and
044            // that class is deployed via a shared classloader.
045    
046            PathableClassLoader parent = new PathableClassLoader(null);
047            parent.useExplicitLoader("junit.", Test.class.getClassLoader());
048            parent.addLogicalLib("commons-logging");
049            parent.addLogicalLib("servlet-api");
050    
051            PathableClassLoader child = new PathableClassLoader(parent);
052            child.setParentFirst(false);
053            child.addLogicalLib("commons-logging");
054            child.addLogicalLib("testclasses");
055    
056            PathableClassLoader tccl = new PathableClassLoader(child);
057            tccl.setParentFirst(false);
058            tccl.addLogicalLib("commons-logging");
059    
060            Class testClass = child.loadClass(BasicServletTestCase.class.getName());
061            return new PathableTestSuite(testClass, tccl);
062        }
063        
064        /**
065         * Test that calling ServletContextCleaner.contextDestroyed doesn't crash.
066         * Testing anything else is rather difficult...
067         */
068        public void testBasics() {
069            ServletContextCleaner scc = new ServletContextCleaner();
070            scc.contextDestroyed(null);
071        }
072    }