1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j;
19
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22 import junit.framework.Test;
23
24 import org.apache.log4j.*;
25 import org.apache.log4j.util.*;
26 import org.apache.log4j.xml.XLevel;
27
28 /***
29 Test the configuration of the hierarchy-wide threshold.
30
31 @author Ceki Gülcü
32 */
33 public class HierarchyThresholdTestCase extends TestCase {
34
35 static String TEMP = "output/temp";
36 static Logger logger = Logger.getLogger(HierarchyThresholdTestCase.class);
37
38 public HierarchyThresholdTestCase(String name) {
39 super(name);
40 }
41
42 public void setUp() {
43 }
44
45 public void tearDown() {
46 System.out.println("Tearing down test case.");
47 logger.getLoggerRepository().resetConfiguration();
48 }
49
50 public void test1() throws Exception {
51 PropertyConfigurator.configure("input/hierarchyThreshold1.properties");
52 common();
53 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.1"));
54 }
55
56 public void test2() throws Exception {
57 PropertyConfigurator.configure("input/hierarchyThreshold2.properties");
58 common();
59 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.2"));
60 }
61
62 public void test3() throws Exception {
63 PropertyConfigurator.configure("input/hierarchyThreshold3.properties");
64 common();
65 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.3"));
66 }
67
68 public void test4() throws Exception {
69 PropertyConfigurator.configure("input/hierarchyThreshold4.properties");
70 common();
71 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.4"));
72 }
73
74 public void test5() throws Exception {
75 PropertyConfigurator.configure("input/hierarchyThreshold5.properties");
76 common();
77 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.5"));
78 }
79
80 public void test6() throws Exception {
81 PropertyConfigurator.configure("input/hierarchyThreshold6.properties");
82 common();
83 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.6"));
84 }
85
86 public void test7() throws Exception {
87 PropertyConfigurator.configure("input/hierarchyThreshold7.properties");
88 common();
89 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.7"));
90 }
91
92 public void test8() throws Exception {
93 PropertyConfigurator.configure("input/hierarchyThreshold8.properties");
94 common();
95 assertTrue(Compare.compare(TEMP, "witness/hierarchyThreshold.8"));
96 }
97
98
99 static
100 void common() {
101 String oldThreadName = Thread.currentThread().getName();
102 Thread.currentThread().setName("main");
103
104 logger.log(XLevel.TRACE, "m0");
105 logger.debug("m1");
106 logger.info("m2");
107 logger.warn("m3");
108 logger.error("m4");
109 logger.fatal("m5");
110
111 Thread.currentThread().setName(oldThreadName);
112 }
113
114 public static Test suite() {
115 TestSuite suite = new TestSuite();
116 suite.addTest(new HierarchyThresholdTestCase("test1"));
117 suite.addTest(new HierarchyThresholdTestCase("test2"));
118 suite.addTest(new HierarchyThresholdTestCase("test3"));
119 suite.addTest(new HierarchyThresholdTestCase("test4"));
120 suite.addTest(new HierarchyThresholdTestCase("test5"));
121 suite.addTest(new HierarchyThresholdTestCase("test6"));
122 suite.addTest(new HierarchyThresholdTestCase("test7"));
123 suite.addTest(new HierarchyThresholdTestCase("test8"));
124 return suite;
125 }
126 }