1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.logging.config;
19
20
21 import java.net.URL;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.commons.logging.PathableClassLoader;
28 import org.apache.commons.logging.PathableTestSuite;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class FirstPriorityConfigTestCase extends TestCase {
43
44
45
46
47
48
49
50 public static Test suite() throws Exception {
51 Class thisClass = FirstPriorityConfigTestCase.class;
52
53
54
55
56
57 PathableClassLoader dummy = new PathableClassLoader(null);
58 dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
59 dummy.addLogicalLib("testclasses");
60 dummy.addLogicalLib("commons-logging");
61
62 String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
63 URL baseUrl = dummy.findResource(thisClassPath);
64
65
66
67
68 PathableClassLoader containerLoader = new PathableClassLoader(null);
69 containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
70 containerLoader.addLogicalLib("commons-logging");
71
72 PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
73 webappLoader.addLogicalLib("testclasses");
74
75 URL pri20URL = new URL(baseUrl, "priority20/");
76 webappLoader.addURL(pri20URL);
77
78 URL pri10URL = new URL(baseUrl, "priority10/");
79 webappLoader.addURL(pri10URL);
80
81
82
83 Class testClass = webappLoader.loadClass(thisClass.getName());
84 return new PathableTestSuite(testClass, webappLoader);
85 }
86
87
88
89
90 public void setUp() throws Exception {
91 LogFactory.releaseAll();
92 }
93
94
95
96
97 public void tearDown() {
98 LogFactory.releaseAll();
99 }
100
101
102
103
104
105
106
107 public void testPriority() throws Exception {
108 LogFactory instance = LogFactory.getFactory();
109
110 ClassLoader thisClassLoader = this.getClass().getClassLoader();
111 ClassLoader lfClassLoader = instance.getClass().getClassLoader();
112 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
113
114
115 assertEquals(thisClassLoader, contextClassLoader);
116
117
118 assertEquals(lfClassLoader, thisClassLoader.getParent());
119 assertEquals(PathableClassLoader.class.getName(),
120 lfClassLoader.getClass().getName());
121
122 String id = (String) instance.getAttribute("configId");
123 assertEquals("Correct config file loaded", "priority20", id );
124 }
125 }