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