1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.test; |
17 | |
|
18 | |
import org.apache.log4j.Level; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.junit.After; |
21 | |
import org.junit.Before; |
22 | |
import org.junit.runner.RunWith; |
23 | |
import org.kuali.rice.test.lifecycles.PerTestDataLoaderLifecycle; |
24 | |
import org.kuali.rice.test.runners.RiceUnitTestClassRunner; |
25 | |
|
26 | |
import java.lang.reflect.Method; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.Iterator; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@RunWith(RiceUnitTestClassRunner.class) |
43 | |
public abstract class BaseRiceTestCase implements MethodAware { |
44 | |
|
45 | 0 | protected final Logger log = Logger.getLogger(getClass()); |
46 | |
|
47 | 0 | private static final Map<String, Level> changedLogLevels = new HashMap<String, Level>(); |
48 | |
|
49 | |
private String name; |
50 | |
private PerTestDataLoaderLifecycle perTestDataLoaderLifecycle; |
51 | |
protected Method method; |
52 | |
|
53 | |
public BaseRiceTestCase() { |
54 | 0 | super(); |
55 | 0 | } |
56 | |
|
57 | |
public String getName() { |
58 | 0 | return this.name; |
59 | |
} |
60 | |
|
61 | |
public void setName(String name) { |
62 | 0 | this.name = name; |
63 | 0 | } |
64 | |
|
65 | |
@Before |
66 | |
public void setUp() throws Exception { |
67 | 0 | } |
68 | |
|
69 | |
@After |
70 | |
public void tearDown() throws Exception { |
71 | 0 | resetLogLevels(); |
72 | 0 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
protected void setLogLevel(String loggerName, Level newLevel) { |
85 | 0 | Logger logger = Logger.getLogger(loggerName); |
86 | |
|
87 | 0 | if (!changedLogLevels.containsKey(loggerName)) { |
88 | 0 | Level originalLevel = logger.getLevel(); |
89 | 0 | changedLogLevels.put(loggerName, originalLevel); |
90 | |
} |
91 | |
|
92 | 0 | logger.setLevel(newLevel); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
protected void resetLogLevels() { |
100 | 0 | for (Iterator i = changedLogLevels.entrySet().iterator(); i.hasNext();) { |
101 | 0 | Map.Entry e = (Map.Entry) i.next(); |
102 | |
|
103 | 0 | String loggerName = (String) e.getKey(); |
104 | 0 | Level originalLevel = (Level) e.getValue(); |
105 | |
|
106 | 0 | Logger.getLogger(loggerName).setLevel(originalLevel); |
107 | 0 | } |
108 | 0 | changedLogLevels.clear(); |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void setTestMethod(Method testMethod) { |
115 | 0 | this.method = testMethod; |
116 | |
|
117 | 0 | perTestDataLoaderLifecycle = new PerTestDataLoaderLifecycle(method); |
118 | 0 | } |
119 | |
|
120 | |
protected PerTestDataLoaderLifecycle getPerTestDataLoaderLifecycle() { |
121 | 0 | return this.perTestDataLoaderLifecycle; |
122 | |
} |
123 | |
} |