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 import java.net.URL;
21
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.commons.logging.PathableClassLoader;
24 import org.apache.commons.logging.PathableTestSuite;
25
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class PriorityConfigTestCase extends TestCase {
48
49
50
51
52 public static Test suite() throws Exception {
53 final Class thisClass = PriorityConfigTestCase.class;
54
55
56
57
58
59 final PathableClassLoader dummy = new PathableClassLoader(null);
60 dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
61 dummy.addLogicalLib("testclasses");
62 dummy.addLogicalLib("commons-logging");
63
64 final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
65 final URL baseUrl = dummy.findResource(thisClassPath);
66
67
68
69
70
71
72
73
74 final PathableClassLoader containerLoader = new PathableClassLoader(null);
75 containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
76 containerLoader.addLogicalLib("commons-logging");
77
78 final URL pri10URL = new URL(baseUrl, "priority10/");
79 containerLoader.addURL(pri10URL);
80
81 final PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
82 webappLoader.setParentFirst(true);
83 webappLoader.addLogicalLib("testclasses");
84
85 final URL noPriorityURL = new URL(baseUrl, "nopriority/");
86 webappLoader.addURL(noPriorityURL);
87
88 final URL pri20URL = new URL(baseUrl, "priority20/");
89 webappLoader.addURL(pri20URL);
90
91 final URL pri20aURL = new URL(baseUrl, "priority20a/");
92 webappLoader.addURL(pri20aURL);
93
94
95
96 final Class testClass = webappLoader.loadClass(thisClass.getName());
97 return new PathableTestSuite(testClass, webappLoader);
98 }
99
100
101
102
103 @Override
104 public void setUp() throws Exception {
105 LogFactory.releaseAll();
106 }
107
108
109
110
111 @Override
112 public void tearDown() {
113 LogFactory.releaseAll();
114 }
115
116
117
118
119
120 public void testPriority() throws Exception {
121 final LogFactory instance = LogFactory.getFactory();
122 final String id = (String) instance.getAttribute("configId");
123 assertEquals("Correct config file loaded", "priority20", id );
124 }
125 }