KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > logging > log4j > log4j12 > BasicServletTestCase


1 /*
2  * Copyright 2006 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 /**
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 JavaDoc {
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 classloader.
44

45         PathableClassLoader parent = new PathableClassLoader(null);
46         parent.useSystemLoader("junit.");
47         parent.addLogicalLib("commons-logging");
48         parent.addLogicalLib("servletapi");
49
50         PathableClassLoader child = new PathableClassLoader(parent);
51         child.setParentFirst(false);
52         child.addLogicalLib("commons-logging");
53         child.addLogicalLib("testclasses");
54
55         PathableClassLoader tccl = new PathableClassLoader(child);
56         tccl.setParentFirst(false);
57         tccl.addLogicalLib("commons-logging");
58
59         Class JavaDoc 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         ServletContextCleaner scc = new ServletContextCleaner();
69         scc.contextDestroyed(null);
70     }
71 }
72
Popular Tags