logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1582170 - /logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
Date Thu, 27 Mar 2014 03:13:24 GMT
Author: mattsicker
Date: Thu Mar 27 03:13:23 2014
New Revision: 1582170

URL: http://svn.apache.org/r1582170
Log:
Update to use InitialLoggerContext rule.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java?rev=1582170&r1=1582169&r2=1582170&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
Thu Mar 27 03:13:23 2014
@@ -27,49 +27,34 @@ import java.util.Map;
 import org.apache.logging.log4j.EventLogger;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
 import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
 
 /**
  *
  */
 public class RewriteAppenderTest {
-    private static final String CONFIG = "log4j-rewrite.xml";
-    private static Configuration config;
-    private static ListAppender app;
-    private static ListAppender app2;
-    private static LoggerContext ctx;
-
-    @BeforeClass
-    public static void setupClass() {
-        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
-        ctx = (LoggerContext) LogManager.getContext(false);
-        config = ctx.getConfiguration();
-        for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet())
{
-            if (entry.getKey().equals("List")) {
-                app = (ListAppender) entry.getValue();
-            } else if (entry.getKey().equals("List2")) {
-                app2 = (ListAppender) entry.getValue();
-            }
-        }
+    private ListAppender app;
+    private ListAppender app2;
+
+    @Rule
+    public InitialLoggerContext init = new InitialLoggerContext("log4j-rewrite.xml");
+
+    @Before
+    public void setUp() throws Exception {
+        app = (ListAppender) this.init.getAppender("List");
+        app2 = (ListAppender) this.init.getAppender("List2");
     }
 
-    @AfterClass
-    public static void cleanupClass() {
-        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
-        ctx.reconfigure();
-        StatusLogger.getLogger().reset();
+    @After
+    public void tearDown() throws Exception {
+        app.clear();
+        app2.clear();
     }
 
     @Test
@@ -90,7 +75,6 @@ public class RewriteAppenderTest {
         assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size()
== 3);
         final String value = map.get("Key1");
         assertEquals("Apache", value);
-        app.clear();
     }
 
 
@@ -119,6 +103,5 @@ public class RewriteAppenderTest {
 
         final List<LogEvent> list = app.getEvents();
         assertTrue("Events were generated", list == null || list.size() == 0);
-        app.clear();
     }
 }



Mime
View raw message