You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gr...@apache.org on 2012/06/02 13:41:11 UTC

svn commit: r1345492 [6/18] - in /logging/log4j/branches/log4j12modules: ./ contribs/ contribs/CekiGulcu/ contribs/EirikLygre/ contribs/JamesHouse/ contribs/Jamie Tsao/ contribs/JimMoore/ contribs/KevinSteppe/ contribs/KitchingSimon/ contribs/LeosLiter...

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/LoggingEventTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/LoggingEventTest.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/LoggingEventTest.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/LoggingEventTest.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.spi;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.MDC;
+import org.apache.log4j.NDC;
+import org.apache.log4j.util.SerializationTestHelper;
+import org.apache.log4j.Priority;
+import org.apache.log4j.Category;
+
+
+/**
+ * Tests LoggingEvent.
+ *
+ * @author Curt Arnold
+ */
+public class LoggingEventTest extends TestCase {
+
+  static final String FILE_PREFIX = "target/test-classes";
+  static final String INPUT_DIR = FILE_PREFIX + "/input";
+  static final String WITNESS_DIR = FILE_PREFIX + "/witness";
+  
+  /**
+   * Create LoggingEventTest.
+   *
+   * @param name test name.
+   */
+  public LoggingEventTest(final String name) {
+    super(name);
+  }
+
+  /**
+   * Serialize a simple logging event and check it against
+   * a witness.
+   * @throws Exception if exception during test.
+   */
+  public void testSerializationSimple() throws Exception {
+    Logger root = Logger.getRootLogger();
+    LoggingEvent event =
+      new LoggingEvent(
+        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
+//    event.prepareForDeferredProcessing();
+
+    int[] skip = new int[] { 352, 353, 354, 355, 356 };
+    SerializationTestHelper.assertSerializationEquals(
+      WITNESS_DIR + "/serialization/simple.bin", event, skip, 237);
+  }
+
+  /**
+   * Serialize a logging event with an exception and check it against
+   * a witness.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testSerializationWithException() throws Exception {
+    Logger root = Logger.getRootLogger();
+    Exception ex = new Exception("Don't panic");
+    LoggingEvent event =
+      new LoggingEvent(
+        root.getClass().getName(), root, Level.INFO, "Hello, world.", ex);
+//    event.prepareForDeferredProcessing();
+
+    int[] skip = new int[] { 352, 353, 354, 355, 356 };
+    SerializationTestHelper.assertSerializationEquals(
+      WITNESS_DIR + "/serialization/exception.bin", event, skip, 237);
+  }
+
+  /**
+   * Serialize a logging event with an exception and check it against
+   * a witness.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testSerializationWithLocation() throws Exception {
+    Logger root = Logger.getRootLogger();
+    LoggingEvent event =
+      new LoggingEvent(
+        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
+    event.getLocationInformation();
+//    event.prepareForDeferredProcessing();
+
+    int[] skip = new int[] { 352, 353, 354, 355, 356 };
+    SerializationTestHelper.assertSerializationEquals(
+      WITNESS_DIR + "/serialization/location.bin", event, skip, 237);
+  }
+
+  /**
+   * Serialize a logging event with ndc.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testSerializationNDC() throws Exception {
+    Logger root = Logger.getRootLogger();
+    NDC.push("ndc test");
+
+    LoggingEvent event =
+      new LoggingEvent(
+        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
+//    event.prepareForDeferredProcessing();
+
+    int[] skip = new int[] { 352, 353, 354, 355, 356 };
+    SerializationTestHelper.assertSerializationEquals(
+      WITNESS_DIR + "/serialization/ndc.bin", event, skip, 237);
+    }
+
+  /**
+   * Serialize a logging event with mdc.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testSerializationMDC() throws Exception {
+    Logger root = Logger.getRootLogger();
+    MDC.put("mdckey", "mdcvalue");
+
+    LoggingEvent event =
+      new LoggingEvent(
+        root.getClass().getName(), root, Level.INFO, "Hello, world.", null);
+//    event.prepareForDeferredProcessing();
+
+    int[] skip = new int[] { 352, 353, 354, 355, 356 };
+    SerializationTestHelper.assertSerializationEquals(
+      WITNESS_DIR + "/serialization/mdc.bin", event, skip, 237);
+  }
+
+  /**
+   * Deserialize a simple logging event.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testDeserializationSimple() throws Exception {
+    Object obj =
+      SerializationTestHelper.deserializeStream(
+        WITNESS_DIR + "/serialization/simple.bin");
+    assertTrue(obj instanceof LoggingEvent);
+
+    LoggingEvent event = (LoggingEvent) obj;
+    assertEquals("Hello, world.", event.getMessage());
+    assertEquals(Level.INFO, event.getLevel());
+  }
+
+  /**
+   * Deserialize a logging event with an exception.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testDeserializationWithException() throws Exception {
+    Object obj =
+      SerializationTestHelper.deserializeStream(
+        WITNESS_DIR + "/serialization/exception.bin");
+    assertTrue(obj instanceof LoggingEvent);
+
+    LoggingEvent event = (LoggingEvent) obj;
+    assertEquals("Hello, world.", event.getMessage());
+    assertEquals(Level.INFO, event.getLevel());
+  }
+
+  /**
+   * Deserialize a logging event with an exception.
+   * @throws Exception if exception during test.
+   *
+   */
+  public void testDeserializationWithLocation() throws Exception {
+    Object obj =
+      SerializationTestHelper.deserializeStream(
+        WITNESS_DIR + "/serialization/location.bin");
+    assertTrue(obj instanceof LoggingEvent);
+
+    LoggingEvent event = (LoggingEvent) obj;
+    assertEquals("Hello, world.", event.getMessage());
+    assertEquals(Level.INFO, event.getLevel());
+  }
+
+    /**
+     * Tests LoggingEvent.fqnOfCategoryClass.
+     */
+  public void testFQNOfCategoryClass() {
+      Category root = Logger.getRootLogger();
+      Priority info = Level.INFO;
+      String catName = Logger.class.toString();
+      LoggingEvent event =
+        new LoggingEvent(
+          catName, root, info, "Hello, world.", null);
+      assertEquals(catName, event.fqnOfCategoryClass);
+  }
+
+    /**
+     * Tests LoggingEvent.level.
+     * @deprecated
+     */
+  public void testLevel() {
+      Category root = Logger.getRootLogger();
+      Priority info = Level.INFO;
+      String catName = Logger.class.toString();
+      LoggingEvent event =
+        new LoggingEvent(
+          catName, root, 0L,  info, "Hello, world.", null);
+      Priority error = Level.ERROR;
+      event.level = error;
+      assertEquals(Level.ERROR, event.level);
+  }
+
+    /**
+     * Tests LoggingEvent.getLocationInfo() when no FQCN is specified.
+     * See bug 41186.
+     */
+  public void testLocationInfoNoFQCN() {
+      Category root = Logger.getRootLogger();
+	  Priority level = Level.INFO;
+      LoggingEvent event =
+        new LoggingEvent(
+          null, root, 0L,  level, "Hello, world.", null);
+      LocationInfo info = event.getLocationInformation();
+	  //
+	  //  log4j 1.2 returns an object, its layout doesn't check for nulls.
+	  //  log4j 1.3 returns a null.
+	  //
+	  assertNotNull(info);
+	  if (info != null) {
+	     assertEquals("?", info.getLineNumber());
+		 assertEquals("?", info.getClassName());
+		 assertEquals("?", info.getFileName());
+		 assertEquals("?", info.getMethodName());
+	  }
+  }
+
+    /**
+     * Message object that throws a RuntimeException on toString().
+     * See bug 37182.
+     */
+    private static class BadMessage {
+        public BadMessage() {
+        }
+
+        public String toString() {
+            throw new RuntimeException();
+        }
+    }
+
+    /**
+     * Tests that an runtime exception or error during toString
+     * on the message parameter does not propagate to caller.
+     * See bug 37182.
+     */
+    public void testBadMessage() {
+        Category root = Logger.getRootLogger();
+        Priority info = Level.INFO;
+        String catName = Logger.class.toString();
+        BadMessage msg = new BadMessage();
+        LoggingEvent event =
+          new LoggingEvent(
+            catName, root, 0L,  info, msg, null);
+        //  would result in exception in earlier versions
+        event.getRenderedMessage();
+    }
+
+
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/LoggingEventTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/ThrowableInformationTest.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/ThrowableInformationTest.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/ThrowableInformationTest.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/spi/ThrowableInformationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/stressCategory)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/stressCategory&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory.pl (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/stressCategory.pl)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory.pl?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory.pl&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/stressCategory.pl&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory.pl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/stressCategory.pl
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteDateAndTimeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/AbsoluteTimeFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/AbsoluteTimeFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/AbsoluteTimeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Compare.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Compare.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Compare.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Compare.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Compare.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Compare.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Compare.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ControlFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/ControlFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ControlFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ControlFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/ControlFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ControlFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ControlFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedJunitTestRunnerFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedLineNumberFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/EnhancedLineNumberFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedLineNumberFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedLineNumberFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/EnhancedLineNumberFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedLineNumberFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/EnhancedLineNumberFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Filter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Filter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Filter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Filter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Filter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Filter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Filter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ISO8601Filter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/ISO8601Filter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ISO8601Filter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ISO8601Filter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/ISO8601Filter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ISO8601Filter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/ISO8601Filter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/JunitTestRunnerFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/JunitTestRunnerFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/JunitTestRunnerFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/LineNumberFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/LineNumberFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/LineNumberFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/LineNumberFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/LineNumberFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/LineNumberFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/LineNumberFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/MDCOrderFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/MDCOrderFilter.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/MDCOrderFilter.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/MDCOrderFilter.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j;
+
+import org.apache.log4j.util.Filter;
+
+import org.apache.log4j.util.Filter;
+
+/**
+ * This class switches MDC values into the order
+ * (unreasonably) expected by the witness files.
+ */
+public class MDCOrderFilter implements Filter {
+
+    /**
+     * Unexpected orders of keys.
+     * Note expected values are "va-one-one" and "va-one-two".
+     */
+  private static final String[] patterns =
+          new String[] {
+                  "{key2,va12}{key1,va11}",
+                  "{key2,value2}{key1,value1}"
+          };
+
+    /**
+     * Replacement values.
+     */
+  private static final String[] replacements =
+            new String[] {
+                    "{key1,va11}{key2,va12}",
+                    "{key1,value1}{key2,value2}"
+            };
+
+  /**
+   *  Switch order of MDC keys when not in expected order.
+   */
+  public String filter(final String in) {
+    if (in == null) {
+      return null;
+    }
+
+    for(int i = 0; i < patterns.length; i++) {
+        int ipos = in.indexOf(patterns[i]);
+        if (ipos >= 1) {
+            return in.substring(0, ipos)
+                    + replacements[i]
+                    + in.substring(ipos + patterns[i].length());
+        }
+    }
+    return in;
+  }
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/MDCOrderFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/RelativeTimeFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/RelativeTimeFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/RelativeTimeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SerializationTestHelper.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/SerializationTestHelper.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SerializationTestHelper.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SerializationTestHelper.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/SerializationTestHelper.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SerializationTestHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SerializationTestHelper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SunReflectFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/SunReflectFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SunReflectFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SunReflectFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/SunReflectFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SunReflectFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/SunReflectFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Transformer.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Transformer.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Transformer.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Transformer.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/Transformer.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Transformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/Transformer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/UnexpectedFormatException.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/UnexpectedFormatException.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/UnexpectedFormatException.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/UnexpectedFormatException.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/UnexpectedFormatException.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/UnexpectedFormatException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/UnexpectedFormatException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/XMLLineAttributeFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/XMLLineAttributeFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLLineAttributeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/XMLTimestampFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/util/XMLTimestampFilter.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/util/XMLTimestampFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ERFATestCase.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/varia/ERFATestCase.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ERFATestCase.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ERFATestCase.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/varia/ERFATestCase.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ERFATestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ErrorHandlerTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ErrorHandlerTestCase.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ErrorHandlerTestCase.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ErrorHandlerTestCase.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.varia;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Appender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.ErrorHandler;
+import org.apache.log4j.util.Filter;
+import org.apache.log4j.util.Transformer;
+import org.apache.log4j.util.Compare;
+import org.apache.log4j.util.JunitTestRunnerFilter;
+import org.apache.log4j.util.SunReflectFilter;
+import org.apache.log4j.util.LineNumberFilter;
+import org.apache.log4j.util.ControlFilter;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.log4j.PropertyConfigurator;
+
+public class ErrorHandlerTestCase extends TestCase {
+
+  static String TEMP = "output/temp";
+  static String FILTERED = "output/filtered";
+
+
+  static String EXCEPTION1 = "java.lang.Exception: Just testing";
+  static String EXCEPTION2 = "\\s*at .*\\(.*\\)";
+  static String EXCEPTION3 = "\\s*at .*\\(Native Method\\)";
+
+  static String TEST1_PAT =
+                       "FALLBACK - (root|test) - Message \\d";
+
+
+  Logger root; 
+  Logger logger;
+
+  public ErrorHandlerTestCase(String name) {
+    super(name);
+  }
+
+  public void setUp() {
+    root = Logger.getRootLogger();
+    logger = Logger.getLogger("test");
+  }
+
+  public void tearDown() {  
+    root.getLoggerRepository().resetConfiguration();
+  }
+
+  public void test1() throws Exception {
+    DOMConfigurator.configure("target/test-classes/input/xml/fallback1.xml");
+    Appender primary = root.getAppender("PRIMARY");
+    ErrorHandler eh = primary.getErrorHandler();
+    assertNotNull(eh);
+
+    common();
+
+    ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT,
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3});
+
+    Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+                            new LineNumberFilter(),
+                            new JunitTestRunnerFilter(),
+                            new SunReflectFilter()});
+
+
+    assertTrue(Compare.compare(FILTERED, "target/test-classes/witness/fallback1"));
+  }
+  
+  public void test2() throws Exception {
+    PropertyConfigurator.configure("target/test-classes/input/fallback1.properties");
+    Appender primary = root.getAppender("PRIMARY");
+    ErrorHandler eh = primary.getErrorHandler();
+    assertNotNull(eh);
+
+    common();
+
+    ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT,
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3});
+
+    Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+                            new LineNumberFilter(),
+                            new JunitTestRunnerFilter(),
+                            new SunReflectFilter()});
+
+
+    assertTrue(Compare.compare(FILTERED, "target/test-classes/witness/fallback1"));
+  }
+
+  void common() {
+    int i = -1;
+ 
+    logger.debug("Message " + ++i);
+    root.debug("Message " + i);        
+
+    logger.info ("Message " + ++i);
+    root.info("Message " + i);        
+
+    logger.warn ("Message " + ++i);
+    root.warn("Message " + i);        
+
+    logger.error("Message " + ++i);
+    root.error("Message " + i);
+    
+    logger.log(Level.FATAL, "Message " + ++i);
+    root.log(Level.FATAL, "Message " + i);    
+    
+    Exception e = new Exception("Just testing");
+    logger.debug("Message " + ++i, e);
+    root.debug("Message " + i, e);
+    
+    logger.error("Message " + ++i, e);
+    root.error("Message " + i, e);    
+
+  }
+
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/ErrorHandlerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/LevelMatchFilterTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/LevelMatchFilterTestCase.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/LevelMatchFilterTestCase.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/LevelMatchFilterTestCase.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.varia;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.framework.Test;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import org.apache.log4j.Appender;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Layout;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.varia.LevelMatchFilter;
+import org.apache.log4j.varia.DenyAllFilter;
+
+import org.apache.log4j.util.Transformer;
+import org.apache.log4j.util.Compare;
+import org.apache.log4j.util.LineNumberFilter;
+
+/**
+   Test case for varia/LevelMatchFilter.java.
+ */
+public class LevelMatchFilterTestCase extends TestCase {
+  
+  static String ACCEPT_FILE     = "output/LevelMatchFilter_accept";
+  static String ACCEPT_FILTERED = "output/LevelMatchFilter_accept_filtered";
+  static String ACCEPT_WITNESS  = "target/test-classes/witness/LevelMatchFilter_accept";
+
+  static String DENY_FILE       = "output/LevelMatchFilter_deny";
+  static String DENY_FILTERED   = "output/LevelMatchFilter_deny_filtered";
+  static String DENY_WITNESS    = "target/test-classes/witness/LevelMatchFilter_deny";
+
+  Logger root; 
+  Logger logger;
+
+  public LevelMatchFilterTestCase(String name) {
+    super(name);
+  }
+
+  public void setUp() {
+    root = Logger.getRootLogger();
+    root.removeAllAppenders();
+  }
+
+  public void tearDown() {  
+    root.getLoggerRepository().resetConfiguration();
+  }
+
+  public void accept() throws Exception {
+    
+    // set up appender
+    Layout layout = new SimpleLayout();
+    Appender appender = new FileAppender(layout, ACCEPT_FILE, false);
+    
+    // create LevelMatchFilter
+    LevelMatchFilter matchFilter = new LevelMatchFilter();
+ 
+     // attach match filter to appender
+    appender.addFilter(matchFilter);
+   
+    // attach DenyAllFilter to end of filter chain to deny neutral
+    // (non matching) messages
+    appender.addFilter(new DenyAllFilter());
+        
+    // set appender on root and set level to debug
+    root.addAppender(appender);
+    root.setLevel(Level.TRACE);
+    
+    Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, 
+				      Level.ERROR, Level.FATAL};
+    for (int x = 0; x < levelArray.length; x++) {
+      // set the level to match
+      matchFilter.setLevelToMatch(levelArray[x].toString());
+      common("pass " + x + "; filter set to accept only " 
+	     + levelArray[x].toString() + " msgs");
+    }
+    
+    Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter());
+    assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS));
+  }
+
+  public void deny() throws Exception {
+    
+    // set up appender
+    Layout layout = new SimpleLayout();
+    Appender appender = new FileAppender(layout, DENY_FILE, false);
+    
+    // create LevelMatchFilter, set to deny matches
+    LevelMatchFilter matchFilter = new LevelMatchFilter();
+    matchFilter.setAcceptOnMatch(false);
+ 
+     // attach match filter to appender
+    appender.addFilter(matchFilter);
+           
+    // set appender on root and set level to debug
+    root.addAppender(appender);
+    root.setLevel(Level.TRACE);
+    
+    Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
+				      Level.ERROR, Level.FATAL};
+    for (int x = 0; x < levelArray.length; x++) {
+      // set the level to match
+      matchFilter.setLevelToMatch(levelArray[x].toString());
+      common("pass " + x + "; filter set to deny only " + levelArray[x].toString()
+              + " msgs");
+    }
+    
+    Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter());
+    assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS));
+  }
+
+
+  void common(String msg) {
+    Logger logger = Logger.getLogger("test");
+    logger.trace(msg);
+    logger.debug(msg);
+    logger.info(msg);
+    logger.warn(msg);
+    logger.error(msg);
+    logger.fatal(msg);
+  }
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new LevelMatchFilterTestCase("accept"));
+    suite.addTest(new LevelMatchFilterTestCase("deny"));
+    return suite;
+  }
+
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/varia/LevelMatchFilterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/CustomLevelTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/CustomLevelTestCase.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/CustomLevelTestCase.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/CustomLevelTestCase.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.xml;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.log4j.Logger;
+import org.apache.log4j.util.Compare;
+
+public class CustomLevelTestCase extends TestCase {
+
+  static final String FILE_PREFIX = "target/test-classes";
+  static final String INPUT_DIR = FILE_PREFIX + "/input";
+  static final String WITNESS_DIR = FILE_PREFIX + "/witness";
+  
+  static String TEMP = "output/temp";
+
+  Logger root; 
+  Logger logger;
+
+  public CustomLevelTestCase(String name) {
+    super(name);
+  }
+
+  public void setUp() {
+    root = Logger.getRootLogger();
+    logger = Logger.getLogger(CustomLevelTestCase.class);
+  }
+
+  public void tearDown() {  
+    root.getLoggerRepository().resetConfiguration();
+  }
+
+  public void test1() throws Exception {
+    DOMConfigurator.configure(INPUT_DIR + "/xml/customLevel1.xml");
+    common();
+    assertTrue(Compare.compare(TEMP, WITNESS_DIR + "/customLevel.1"));
+  }
+
+  public void test2() throws Exception {
+    DOMConfigurator.configure(INPUT_DIR + "/xml/customLevel2.xml");
+    common();
+    assertTrue(Compare.compare(TEMP, WITNESS_DIR + "/customLevel.2"));
+  }
+
+  public void test3() throws Exception {
+    DOMConfigurator.configure(INPUT_DIR + "/xml/customLevel3.xml");
+    common();
+    assertTrue(Compare.compare(TEMP, WITNESS_DIR + "/customLevel.3"));
+  }
+
+  public void test4() throws Exception {
+    DOMConfigurator.configure(INPUT_DIR + "/xml/customLevel4.xml");
+    common();
+    assertTrue(Compare.compare(TEMP, WITNESS_DIR + "/customLevel.4"));
+  }
+
+
+  void common() {
+    int i = 0;
+    logger.debug("Message " + ++i);
+    logger.info ("Message " + ++i);
+    logger.warn ("Message " + ++i);
+    logger.error("Message " + ++i);
+    logger.log(XLevel.TRACE, "Message " + ++i);
+  }
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new CustomLevelTestCase("test1"));
+    suite.addTest(new CustomLevelTestCase("test2"));
+    suite.addTest(new CustomLevelTestCase("test3"));
+    suite.addTest(new CustomLevelTestCase("test4"));
+    return suite;
+  }
+
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/CustomLevelTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/DOMTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/DOMTestCase.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/DOMTestCase.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/DOMTestCase.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.xml;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Appender;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.VectorAppender;
+import org.apache.log4j.spi.ErrorHandler;
+import org.apache.log4j.spi.LoggerFactory;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.ThrowableRenderer;
+import org.apache.log4j.spi.OptionHandler;
+import org.apache.log4j.spi.ThrowableRendererSupport;
+import org.apache.log4j.util.Compare;
+import org.apache.log4j.util.ControlFilter;
+import org.apache.log4j.util.Filter;
+import org.apache.log4j.util.ISO8601Filter;
+import org.apache.log4j.util.JunitTestRunnerFilter;
+import org.apache.log4j.util.LineNumberFilter;
+import org.apache.log4j.util.SunReflectFilter;
+import org.apache.log4j.util.Transformer;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class DOMTestCase extends TestCase {
+  static final String FILE_PREFIX = "target/test-classes/";
+  
+  static String TEMP_A1 = "output/temp.A1";
+  static String TEMP_A2 = "output/temp.A2";
+  static String FILTERED_A1 = "output/filtered.A1";
+  static String FILTERED_A2 = "output/filtered.A2";
+
+
+  static String EXCEPTION1 = "java.lang.Exception: Just testing";
+  static String EXCEPTION2 = "\\s*at .*\\(.*\\)";
+  static String EXCEPTION3 = "\\s*at .*\\(Native Method\\)";
+  static String EXCEPTION4 = "\\s*at .*\\(.*Compiled Code\\)";
+  static String EXCEPTION5 = "\\s*at .*\\(.*libgcj.*\\)";
+
+
+  static String TEST1_1A_PAT = 
+                       "(TRACE|DEBUG|INFO |WARN |ERROR|FATAL) \\w*\\.\\w* - Message \\d";
+
+  static String TEST1_1B_PAT = "(TRACE|DEBUG|INFO |WARN |ERROR|FATAL) root - Message \\d";
+
+  static String TEST1_2_PAT = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} "+
+                        "\\[main]\\ (TRACE|DEBUG|INFO|WARN|ERROR|FATAL) .* - Message \\d";
+
+
+
+  Logger root; 
+  Logger logger;
+
+  public DOMTestCase(String name) {
+    super(name);
+  }
+
+  public void setUp() {
+    root = Logger.getRootLogger();
+    logger = Logger.getLogger(DOMTestCase.class);
+  }
+
+  public void tearDown() {  
+    root.getLoggerRepository().resetConfiguration();
+  }
+
+  public void test1() throws Exception {
+    DOMConfigurator.configure(FILE_PREFIX + "input/xml/DOMTestCase1.xml");
+    common();
+
+    ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT, 
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
+
+    ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT, 
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
+
+    Transformer.transform(
+      TEMP_A1, FILTERED_A1,
+      new Filter[] {
+        cf1, new LineNumberFilter(), new SunReflectFilter(),
+        new JunitTestRunnerFilter()
+      });
+
+    Transformer.transform(
+      TEMP_A2, FILTERED_A2,
+      new Filter[] {
+        cf2, new LineNumberFilter(), new ISO8601Filter(),
+        new SunReflectFilter(), new JunitTestRunnerFilter()
+      });
+
+    assertTrue(Compare.compare(FILTERED_A1, FILE_PREFIX + "witness/dom.A1.1"));
+    assertTrue(Compare.compare(FILTERED_A2, FILE_PREFIX + "witness/dom.A2.1"));
+  }
+  
+  /**
+   *   Tests processing of external entities in XML file.
+   */
+  public void test4() throws Exception {
+    DOMConfigurator.configure(FILE_PREFIX + "input/xml/DOMTest4.xml");
+    common();
+
+    ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT, 
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
+
+    ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT, 
+					       EXCEPTION1, EXCEPTION2, EXCEPTION3, EXCEPTION4, EXCEPTION5});
+
+    Transformer.transform(
+      TEMP_A1 + ".4", FILTERED_A1 + ".4",
+      new Filter[] {
+        cf1, new LineNumberFilter(), new SunReflectFilter(),
+        new JunitTestRunnerFilter()
+      });
+
+    Transformer.transform(
+      TEMP_A2 + ".4", FILTERED_A2 + ".4",
+      new Filter[] {
+        cf2, new LineNumberFilter(), new ISO8601Filter(),
+        new SunReflectFilter(), new JunitTestRunnerFilter()
+      });
+
+    assertTrue(Compare.compare(FILTERED_A1 + ".4", FILE_PREFIX + "witness/dom.A1.4"));
+    assertTrue(Compare.compare(FILTERED_A2 + ".4", FILE_PREFIX + "witness/dom.A2.4"));
+  }
+
+  void common() {
+    String oldThreadName = Thread.currentThread().getName();
+    Thread.currentThread().setName("main");
+
+    int i = -1;
+ 
+    logger.trace("Message " + ++i);
+    root.trace("Message " + i);  
+ 
+    logger.debug("Message " + ++i);
+    root.debug("Message " + i);        
+
+    logger.info ("Message " + ++i);
+    root.info("Message " + i);        
+
+    logger.warn ("Message " + ++i);
+    root.warn("Message " + i);        
+
+    logger.error("Message " + ++i);
+    root.error("Message " + i);
+    
+    logger.log(Level.FATAL, "Message " + ++i);
+    root.log(Level.FATAL, "Message " + i);    
+    
+    Exception e = new Exception("Just testing");
+    logger.debug("Message " + ++i, e);
+    root.debug("Message " + i, e);
+    
+    logger.error("Message " + ++i, e);
+    root.error("Message " + i, e);    
+
+    Thread.currentThread().setName(oldThreadName);
+  }
+
+
+    /**
+     * CustomLogger implementation for testCategoryFactory1 and 2.
+     */
+  private static class CustomLogger extends Logger {
+        /**
+         * Creates new instance.
+         * @param name logger name.
+         */
+      public CustomLogger(final String name) {
+          super(name);
+      }
+  }
+
+    /**
+     * Creates new instances of CustomLogger.
+     */
+  public static class CustomLoggerFactory implements LoggerFactory {
+        /**
+         * Addivity, expected to be set false in configuration file.
+         */
+      private boolean additivity;
+
+        /**
+         * Create new instance of factory.
+         */
+      public CustomLoggerFactory() {
+          additivity = true;
+      }
+
+        /**
+         * Create new logger.
+         * @param name logger name.
+         * @return new logger.
+         */
+      public Logger makeNewLoggerInstance(final String name) {
+          Logger logger = new CustomLogger(name);
+          assertFalse(additivity);
+          return logger;
+      }
+
+        /**
+         * Set additivity.
+         * @param newVal new value of additivity.
+         */
+      public void setAdditivity(final boolean newVal) {
+          additivity = newVal;
+      }
+  }
+
+    /**
+     * CustomErrorHandler for testCategoryFactory2.
+     */
+  public static class CustomErrorHandler implements ErrorHandler {
+      public CustomErrorHandler() {}
+      public void activateOptions() {}
+      public void setLogger(final Logger logger) {}
+      public void error(String message, Exception e, int errorCode) {}
+      public void error(String message) {}
+      public void error(String message, Exception e, int errorCode, LoggingEvent event) {}
+      public void setAppender(Appender appender) {}
+      public void setBackupAppender(Appender appender) {}
+  }
+
+    /**
+     * Tests that loggers mentioned in logger elements
+     *    use the specified categoryFactory.  See bug 33708.
+     */
+  public void testCategoryFactory1() {
+      DOMConfigurator.configure(FILE_PREFIX + "input/xml/categoryfactory1.xml");
+      //
+      //   logger explicitly mentioned in configuration,
+      //         should be a CustomLogger
+      Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.1");
+      assertTrue(logger1 instanceof CustomLogger);
+      //
+      //   logger not explicitly mentioned in configuration,
+      //         should use default factory
+      Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.2");
+      assertFalse(logger2 instanceof CustomLogger);
+  }
+
+    /**
+     * Tests that loggers mentioned in logger-ref elements
+     *    use the specified categoryFactory.  See bug 33708.
+     */
+    public void testCategoryFactory2() {
+        DOMConfigurator.configure(FILE_PREFIX + "input/xml/categoryfactory2.xml");
+        //
+        //   logger explicitly mentioned in configuration,
+        //         should be a CustomLogger
+        Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.1");
+        assertTrue(logger1 instanceof CustomLogger);
+        //
+        //   logger not explicitly mentioned in configuration,
+        //         should use default factory
+        Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.2");
+        assertFalse(logger2 instanceof CustomLogger);
+    }
+
+    /**
+     * Tests that loggers mentioned in logger elements
+     *    use the specified loggerFactory.  See bug 33708.
+     */
+  public void testLoggerFactory1() {
+      DOMConfigurator.configure(FILE_PREFIX + "input/xml/loggerfactory1.xml");
+      //
+      //   logger explicitly mentioned in configuration,
+      //         should be a CustomLogger
+      Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.1");
+      assertTrue(logger1 instanceof CustomLogger);
+      //
+      //   logger not explicitly mentioned in configuration,
+      //         should use default factory
+      Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.2");
+      assertFalse(logger2 instanceof CustomLogger);
+  }
+
+    /**
+     * Tests that reset="true" on log4j:configuration element resets
+     * repository before configuration.
+     * @throws Exception thrown on error.
+     */
+  public void testReset() throws Exception {
+      VectorAppender appender = new VectorAppender();
+      appender.setName("V1");
+      Logger.getRootLogger().addAppender(appender);
+      DOMConfigurator.configure(FILE_PREFIX + "input/xml/testReset.xml");
+      assertNull(Logger.getRootLogger().getAppender("V1"));
+  }
+
+
+    /**
+     * Test checks that configureAndWatch does initial configuration, see bug 33502.
+      * @throws Exception if IO error.
+     */
+  public void testConfigureAndWatch() throws Exception {
+    DOMConfigurator.configureAndWatch(FILE_PREFIX + "input/xml/DOMTestCase1.xml");
+    assertNotNull(Logger.getRootLogger().getAppender("A1"));
+  }
+
+
+    /**
+     * This test checks that the subst method of an extending class
+     * is checked when evaluating parameters.  See bug 43325.
+     *
+     */
+  public void testOverrideSubst() {
+      DOMConfigurator configurator = new DOMConfigurator() {
+          protected String subst(final String value) {
+              if ("output/temp.A1".equals(value)) {
+                  return "output/subst-test.A1";
+              }
+              return value;
+          }
+      };
+      configurator.doConfigure(FILE_PREFIX + "input/xml/DOMTestCase1.xml", LogManager.getLoggerRepository());
+      FileAppender a1 = (FileAppender) Logger.getRootLogger().getAppender("A1");
+      String file = a1.getFile();
+      assertEquals("output/subst-test.A1", file);
+  }
+
+    /**
+     * Mock ThrowableRenderer for testThrowableRenderer.  See bug 45721.
+     */
+    public static class MockThrowableRenderer implements ThrowableRenderer, OptionHandler {
+        private boolean activated = false;
+        private boolean showVersion = true;
+
+        public MockThrowableRenderer() {
+        }
+
+        public void activateOptions() {
+            activated = true;
+        }
+
+        public boolean isActivated() {
+            return activated;
+        }
+
+        public String[] doRender(final Throwable t) {
+            return new String[0];
+        }
+
+        public void setShowVersion(boolean v) {
+            showVersion = v;
+        }
+
+        public boolean getShowVersion() {
+            return showVersion;
+        }
+    }
+
+    /**
+     * Test of log4j.throwableRenderer support.  See bug 45721.
+     */
+    public void testThrowableRenderer1() {
+        DOMConfigurator.configure(FILE_PREFIX + "input/xml/throwableRenderer1.xml");
+        ThrowableRendererSupport repo = (ThrowableRendererSupport) LogManager.getLoggerRepository();
+        MockThrowableRenderer renderer = (MockThrowableRenderer) repo.getThrowableRenderer();
+        LogManager.resetConfiguration();
+        assertNotNull(renderer);
+        assertEquals(true, renderer.isActivated());
+        assertEquals(false, renderer.getShowVersion());
+    }
+
+    /**
+     * Test for bug 47465.
+     * configure(URL) did not close opened JarURLConnection.
+     * @throws IOException if IOException creating properties jar.
+     */
+    public void testJarURL() throws IOException {
+        File input = new File(FILE_PREFIX + "input/xml/defaultInit.xml");
+        System.out.println(input.getAbsolutePath());
+        InputStream is = new FileInputStream(input);
+        File dir = new File("output");
+        dir.mkdirs();
+        File file = new File("output/xml.jar");
+        ZipOutputStream zos =
+            new ZipOutputStream(new FileOutputStream(file));
+        zos.putNextEntry(new ZipEntry("log4j.xml"));
+        int len;
+        byte[] buf = new byte[1024];
+        while ((len = is.read(buf)) > 0) {
+            zos.write(buf, 0, len);
+        }
+        zos.closeEntry();
+        zos.close();
+        URL url = new URL("jar:" + file.toURL() + "!/log4j.xml");
+        DOMConfigurator.configure(url);
+        assertTrue(file.delete());
+        assertFalse(file.exists());
+    }
+
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/DOMTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XLevel.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/xml/XLevel.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XLevel.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XLevel.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/xml/XLevel.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XLevel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XLevel.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTest.java (from r1345481, logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/xml/XMLLayoutTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTest.java?p2=logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTest.java&p1=logging/log4j/branches/log4j12modules/tests/src/java/org/apache/log4j/xml/XMLLayoutTest.java&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTestCase.java?rev=1345492&view=auto
==============================================================================
--- logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTestCase.java (added)
+++ logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTestCase.java Sat Jun  2 11:40:31 2012
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.xml;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.MDC;
+import org.apache.log4j.util.Compare;
+import org.apache.log4j.util.Filter;
+import org.apache.log4j.util.JunitTestRunnerFilter;
+import org.apache.log4j.util.LineNumberFilter;
+import org.apache.log4j.util.SunReflectFilter;
+import org.apache.log4j.util.Transformer;
+import org.apache.log4j.util.XMLLineAttributeFilter;
+import org.apache.log4j.util.XMLTimestampFilter;
+
+import java.util.Hashtable;
+
+public class XMLLayoutTestCase extends TestCase {
+
+  static final String FILE_PREFIX = "target/test-classes";
+  static final String INPUT_DIR = FILE_PREFIX + "/input";
+  static final String WITNESS_DIR = FILE_PREFIX + "/witness";
+  
+  static String TEMP = "output/temp";
+  static String FILTERED = "output/filtered";
+
+  Logger root; 
+  Logger logger;
+
+  public XMLLayoutTestCase(String name) {
+    super(name);
+  }
+
+  public void setUp() {
+    root = Logger.getRootLogger();
+    root.setLevel(Level.TRACE);
+    logger = Logger.getLogger(XMLLayoutTestCase.class);
+    logger.setLevel(Level.TRACE);
+  }
+
+  public void tearDown() {  
+    root.getLoggerRepository().resetConfiguration();
+  }
+
+  public void basic() throws Exception {
+    XMLLayout xmlLayout = new XMLLayout();
+    root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+    common();
+    Transformer.transform(
+      TEMP, FILTERED,
+      new Filter[] {
+        new LineNumberFilter(),
+        new XMLTimestampFilter(),
+        new JunitTestRunnerFilter(),
+        new SunReflectFilter()
+      });
+    assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.1"));
+  }
+
+  public void locationInfo() throws Exception {
+    XMLLayout xmlLayout = new XMLLayout();
+    xmlLayout.setLocationInfo(true);
+    root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+    common();
+    Transformer.transform(
+      TEMP, FILTERED,
+      new Filter[] {
+        new LineNumberFilter(),
+        new XMLTimestampFilter(), 
+        new XMLLineAttributeFilter(),
+        new JunitTestRunnerFilter(),
+        new SunReflectFilter()
+      });
+    assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.2"));
+  }
+
+  public void testCDATA() throws Exception {
+    XMLLayout xmlLayout = new XMLLayout();
+    xmlLayout.setLocationInfo(true);
+    root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+
+    String oldThreadName = Thread.currentThread().getName();
+    Thread.currentThread().setName("main");
+    
+    logger.trace("Message with embedded <![CDATA[<hello>hi</hello>]]>.");
+    logger.debug("Message with embedded <![CDATA[<hello>hi</hello>]]>.");
+
+    Thread.currentThread().setName(oldThreadName);
+
+    Transformer.transform(
+      TEMP, FILTERED,
+      new Filter[] {
+        new LineNumberFilter(), 
+        new XMLTimestampFilter(),
+        new XMLLineAttributeFilter(), 
+        new SunReflectFilter(),
+        new JunitTestRunnerFilter()
+
+      });
+    Transformer.transform(TEMP, FILTERED, new Filter[] {new LineNumberFilter(),
+    						  new XMLTimestampFilter(),
+    						  new XMLLineAttributeFilter()});
+    assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.3"));
+  }
+
+  public void testNull() throws Exception {
+    XMLLayout xmlLayout = new XMLLayout();
+    root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+
+    String oldThreadName = Thread.currentThread().getName();
+    Thread.currentThread().setName("main");
+
+    logger.debug("hi");
+    logger.debug(null);
+    Exception e = new Exception((String) null);
+    logger.debug("hi", e);
+
+    Thread.currentThread().setName(oldThreadName);
+
+    Transformer.transform(
+      TEMP, FILTERED,
+      new Filter[] { new LineNumberFilter(),
+          new XMLTimestampFilter(),  
+          new JunitTestRunnerFilter(),
+          new SunReflectFilter()});
+    assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.null"));
+  }
+
+    /**
+     * Tests the format of the MDC portion of the layout to ensure
+     * the key-value pairs we put in turn up in the output file.
+     * @throws Exception
+     */
+    public void testMDC() throws Exception {
+      XMLLayout xmlLayout = new XMLLayout();
+      xmlLayout.setProperties(true);
+      root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+
+      Hashtable context = MDC.getContext();
+      if (context != null) {
+          context.clear();
+      }
+      MDC.put("key1", "val1");
+      MDC.put("key2", "val2");
+
+      logger.debug("Hello");
+      Transformer.transform(
+        TEMP, FILTERED,
+        new Filter[] { new LineNumberFilter(),
+            new JunitTestRunnerFilter(),
+            new XMLTimestampFilter()});
+      assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.mdc.1"));
+    }
+
+    public void testMDCEscaped() throws Exception {
+      XMLLayout xmlLayout = new XMLLayout();
+      xmlLayout.setProperties(true);
+      root.addAppender(new FileAppender(xmlLayout, TEMP, false));
+
+      Hashtable context = MDC.getContext();
+      if (context != null) {
+          context.clear();
+      }
+      MDC.put("blahAttribute", "<blah value='blah'>");
+      MDC.put("<blahKey value='blah'/>", "blahValue");
+
+      logger.debug("Hello");
+      Transformer.transform(
+        TEMP, FILTERED,
+        new Filter[] { new LineNumberFilter(),
+            new JunitTestRunnerFilter(),
+            new XMLTimestampFilter() });
+      assertTrue(Compare.compare(FILTERED, WITNESS_DIR + "/xmlLayout.mdc.2"));
+    }
+
+  
+  void common() {
+    String oldThreadName = Thread.currentThread().getName();
+    Thread.currentThread().setName("main");
+
+    int i = -1;
+ 
+    new X();
+
+    logger.trace("Message " + ++i);
+    root.trace("Message " + i);    
+
+    logger.debug("Message " + ++i);
+    root.debug("Message " + i);        
+
+    logger.info("Message " + ++i);
+    root.info("Message " + i);        
+
+    logger.warn ("Message " + ++i);
+    root.warn("Message " + i);        
+ 
+    logger.error("Message " + ++i);
+    root.error("Message " + i);
+    
+    logger.log(Level.FATAL, "Message " + ++i);
+    root.log(Level.FATAL, "Message " + i);    
+    
+    Exception e = new Exception("Just testing");
+    logger.debug("Message " + ++i, e);
+    root.debug("Message " + i, e);
+    
+    logger.error("Message " + ++i, e);
+    root.error("Message " + i, e);    
+
+
+    Thread.currentThread().setName(oldThreadName);
+  }
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new XMLLayoutTestCase("basic"));
+    suite.addTest(new XMLLayoutTestCase("locationInfo"));
+    suite.addTest(new XMLLayoutTestCase("testCDATA"));
+    suite.addTest(new XMLLayoutTestCase("testNull"));
+    suite.addTest(new XMLLayoutTestCase("testMDC"));
+    suite.addTest(new XMLLayoutTestCase("testMDCEscaped"));
+    return suite;
+  }
+
+
+  class X {
+    Logger logger = Logger.getLogger(X.class);
+    public X() {
+      logger.info("in X() constructor");
+    }
+  }
+}

Propchange: logging/log4j/branches/log4j12modules/core/src/test/java/org/apache/log4j/xml/XMLLayoutTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/log4j-coding-convention.xml (from r1345481, logging/log4j/branches/log4j12modules/tests/log4j-coding-convention.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/log4j-coding-convention.xml?p2=logging/log4j/branches/log4j12modules/core/src/test/log4j-coding-convention.xml&p1=logging/log4j/branches/log4j12modules/tests/log4j-coding-convention.xml&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/log4j-coding-convention.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_en_US.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/resources/L7D_en_US.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_en_US.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_en_US.properties&p1=logging/log4j/branches/log4j12modules/tests/resources/L7D_en_US.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_en_US.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_en_US.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/resources/L7D_fr.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr.properties&p1=logging/log4j/branches/log4j12modules/tests/resources/L7D_fr.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr_CH.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/resources/L7D_fr_CH.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr_CH.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr_CH.properties&p1=logging/log4j/branches/log4j12modules/tests/resources/L7D_fr_CH.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr_CH.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/L7D_fr_CH.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/TestLogSFPatterns.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/resources/TestLogSFPatterns.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/TestLogSFPatterns.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/TestLogSFPatterns.properties&p1=logging/log4j/branches/log4j12modules/tests/resources/TestLogSFPatterns.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/TestLogSFPatterns.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/RFA1.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/RFA1.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/RFA1.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/RFA1.properties&p1=logging/log4j/branches/log4j12modules/tests/input/RFA1.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/RFA1.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/defaultInit3.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/defaultInit3.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/defaultInit3.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/defaultInit3.properties&p1=logging/log4j/branches/log4j12modules/tests/input/defaultInit3.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/defaultInit3.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/defaultInit3.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/fallback1.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/fallback1.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/fallback1.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/fallback1.properties&p1=logging/log4j/branches/log4j12modules/tests/input/fallback1.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/fallback1.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/filter1.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/filter1.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/filter1.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/filter1.properties&p1=logging/log4j/branches/log4j12modules/tests/input/filter1.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/filter1.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold1.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold1.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold1.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold1.properties&p1=logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold1.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold1.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold1.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold2.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold2.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold2.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold2.properties&p1=logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold2.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold2.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold2.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold3.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold3.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold3.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold3.properties&p1=logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold3.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold3.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold3.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold4.properties (from r1345481, logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold4.properties)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold4.properties?p2=logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold4.properties&p1=logging/log4j/branches/log4j12modules/tests/input/hierarchyThreshold4.properties&r1=1345481&r2=1345492&rev=1345492&view=diff
==============================================================================
    (empty)

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold4.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/branches/log4j12modules/core/src/test/resources/input/hierarchyThreshold4.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision