1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.logging.tccl.logfactory;
19
20 import junit.framework.Test;
21 import junit.framework.TestCase;
22
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.commons.logging.PathableClassLoader;
25 import org.apache.commons.logging.PathableTestSuite;
26 import org.apache.commons.logging.impl.Log4jApiLogFactory;
27
28
29
30
31
32 public class AdaptersTcclTestCase extends TestCase {
33
34
35
36
37 public static Test suite() throws Exception {
38
39 final PathableClassLoader classLoader = new PathableClassLoader(null);
40 classLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
41 classLoader.addLogicalLib("commons-logging");
42 classLoader.addLogicalLib("testclasses");
43
44
45 final PathableClassLoader tcclLoader = new PathableClassLoader(classLoader);
46 tcclLoader.addLogicalLib("commons-logging-adapters");
47 tcclLoader.addLogicalLib("log4j-api");
48 tcclLoader.setParentFirst(false);
49
50 final Class<?> testClass = classLoader.loadClass(AdaptersTcclTestCase.class.getName());
51 return new PathableTestSuite(testClass, tcclLoader);
52 }
53
54
55
56
57 @Override
58 public void setUp() throws Exception {
59 LogFactory.releaseAll();
60 }
61
62
63
64
65 @Override
66 public void tearDown() {
67 LogFactory.releaseAll();
68 }
69
70 public void testFactoryLoading() {
71 final LogFactory factory = LogFactory.getFactory();
72
73 assertEquals(Thread.currentThread().getContextClassLoader(), factory.getClass().getClassLoader());
74
75 assertEquals(Log4jApiLogFactory.class.getName(), factory.getClass().getName());
76 }
77 }