1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.log4j;
17
18 import org.apache.log4j.LogManager;
19 import org.junit.After;
20 import org.junit.AfterClass;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.BlockJUnit4ClassRunner;
26 import org.kuali.student.common.test.spring.log4j.KSLog4JConfigurer;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33
34
35
36 @RunWith (BlockJUnit4ClassRunner.class)
37 public class TestConfigureLog4jOverride {
38
39 private static Logger log;
40
41
42
43
44 public TestConfigureLog4jOverride() {
45
46 }
47
48 @AfterClass
49 public static void afterClass() {
50
51
52
53
54
55
56 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES);
57 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES_REFRESH);
58
59 LogManager.resetConfiguration();
60
61 System.setProperty(KSLog4JConfigurer.LOG4J_PROPERTIES, "classpath:log4j.properties");
62
63 log = KSLog4JConfigurer.getLogger(TestConfigureLog4jOverride.class);
64 }
65
66 @Test
67 public void testStandardOverride() {
68
69 LogManager.resetConfiguration();
70
71 System.setProperty("log4j.configuration,", "src/test/resources/override-log4j-test.properties");
72
73 log = LoggerFactory.getLogger(TestConfigureLog4jOverride.class);
74
75 Assert.assertTrue(log.isDebugEnabled());
76 }
77
78 @Test
79 public void testBasic() {
80
81 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES);
82 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES_REFRESH);
83
84 LogManager.resetConfiguration();
85
86
87
88 System.setProperty(KSLog4JConfigurer.LOG4J_PROPERTIES, "classpath:override-log4j-test.properties");
89
90 log = KSLog4JConfigurer.getLogger(TestConfigureLog4jOverride.class);
91
92 Assert.assertTrue("Failed to use override-log4j-test.properties to set the log level to debugging", log.isDebugEnabled());
93
94 log.debug ("at debug level");
95 }
96
97 @Test
98 public void testRefresh() {
99
100 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES);
101 System.getProperties().remove(KSLog4JConfigurer.LOG4J_PROPERTIES_REFRESH);
102
103 LogManager.resetConfiguration();
104
105
106
107 System.setProperty(KSLog4JConfigurer.LOG4J_PROPERTIES, "classpath:override-log4j-test.properties");
108
109 System.setProperty(KSLog4JConfigurer.LOG4J_PROPERTIES_REFRESH, "15");
110
111 log = KSLog4JConfigurer.getLogger(TestConfigureLog4jOverride.class);
112
113 Assert.assertTrue("Failed to use override-log4j-test.properties to set the log level to debugging", log.isDebugEnabled());
114
115 log.debug ("at debug level");
116 }
117 }