01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
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: // Created on Feb 21, 2006
18: package edu.iu.uis.eden.plugin;
19:
20: import java.net.URL;
21: import java.net.URLClassLoader;
22:
23: import junit.framework.AssertionFailedError;
24: import junit.framework.TestCase;
25:
26: import org.junit.Test;
27: import org.kuali.rice.resourceloader.ContextClassLoaderBinder;
28:
29: /**
30: * Tests the ContextClassLoaderBinder
31: * @author Aaron Hamid
32: */
33: public class ContextClassLoaderBinderTest extends TestCase {
34:
35: @Test
36: public void testBinding() {
37: try {
38: ContextClassLoaderBinder.unbind();
39: throw new AssertionFailedError(
40: "unbind succeeded without any prior bind");
41: } catch (IllegalStateException ise) {
42: // expect illegal state
43: }
44:
45: ClassLoader cl0 = new URLClassLoader(new URL[] {});
46: ClassLoader cl1 = new URLClassLoader(new URL[] {});
47: ClassLoader cl2 = new URLClassLoader(new URL[] {});
48:
49: ClassLoader original = Thread.currentThread()
50: .getContextClassLoader();
51: ContextClassLoaderBinder.bind(cl0);
52: assertEquals(cl0, Thread.currentThread()
53: .getContextClassLoader());
54: ContextClassLoaderBinder.unbind();
55: assertEquals(original, Thread.currentThread()
56: .getContextClassLoader());
57:
58: ContextClassLoaderBinder.bind(cl0);
59: assertEquals(cl0, Thread.currentThread()
60: .getContextClassLoader());
61: ContextClassLoaderBinder.bind(cl1);
62: assertEquals(cl1, Thread.currentThread()
63: .getContextClassLoader());
64: ContextClassLoaderBinder.unbind();
65: assertEquals(cl0, Thread.currentThread()
66: .getContextClassLoader());
67: ContextClassLoaderBinder.unbind();
68: assertEquals(original, Thread.currentThread()
69: .getContextClassLoader());
70:
71: ContextClassLoaderBinder.bind(cl0);
72: assertEquals(cl0, Thread.currentThread()
73: .getContextClassLoader());
74: ContextClassLoaderBinder.bind(cl1);
75: assertEquals(cl1, Thread.currentThread()
76: .getContextClassLoader());
77: ContextClassLoaderBinder.bind(cl2);
78: assertEquals(cl2, Thread.currentThread()
79: .getContextClassLoader());
80: ContextClassLoaderBinder.unbind();
81: assertEquals(cl1, Thread.currentThread()
82: .getContextClassLoader());
83: ContextClassLoaderBinder.unbind();
84: assertEquals(cl0, Thread.currentThread()
85: .getContextClassLoader());
86: ContextClassLoaderBinder.unbind();
87: assertEquals(original, Thread.currentThread()
88: .getContextClassLoader());
89: }
90: }
|