logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r360145 - in /logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j: CategoryTest.java CoreTestSuite.java FileAppenderTest.java LevelTest.java PriorityTest.java spi/LoggingEventTest.java
Date Fri, 30 Dec 2005 19:06:01 GMT
Author: carnold
Date: Fri Dec 30 11:05:58 2005
New Revision: 360145

URL: http://svn.apache.org/viewcvs?rev=360145&view=rev
Log:
Bug 35452: Unit tests for Priority and Level 1.2/1.3 compatibility

Added:
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CategoryTest.java
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/PriorityTest.java
Modified:
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/FileAppenderTest.java
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/LevelTest.java
    logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LoggingEventTest.java

Added: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CategoryTest.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CategoryTest.java?rev=360145&view=auto
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CategoryTest.java (added)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CategoryTest.java Fri
Dec 30 11:05:58 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 junit.framework.TestCase;
+
+import java.lang.reflect.Method;
+
+
+/**
+ * Tests of Category.
+ *
+ * @author Curt Arnold
+ * @since 1.2.14
+ */
+public class CategoryTest extends TestCase {
+  /**
+   * Constructs new instance of test.
+   * @param name test name.
+   */
+  public CategoryTest(final String name) {
+    super(name);
+  }
+
+  /**
+   * Tests Category.forcedLog.
+   */
+  public void testForcedLog() {
+    MockCategory category = new MockCategory("org.example.foo");
+    category.setAdditivity(false);
+    category.addAppender(new VectorAppender());
+    category.info("Hello, World");
+  }
+
+  /**
+   * Tests that the return type of getChainedPriority is Priority.
+   * @throws Exception thrown if Category.getChainedPriority can not be found.
+   */
+  public void testGetChainedPriorityReturnType() throws Exception {
+    Method method = Category.class.getMethod("getChainedPriority", null);
+    assertTrue(method.getReturnType() == Priority.class);
+  }
+
+  /**
+   * Tests l7dlog(Priority, String, Throwable).
+   */
+  public void testL7dlog() {
+    Logger logger = Logger.getLogger("org.example.foo");
+    logger.setLevel(Level.ERROR);
+    Priority debug = Level.DEBUG;
+    logger.l7dlog(debug, "Hello, World", null);
+  }
+
+  /**
+   * Tests l7dlog(Priority, String, Object[], Throwable).
+   */
+  public void testL7dlog4Param() {
+    Logger logger = Logger.getLogger("org.example.foo");
+    logger.setLevel(Level.ERROR);
+    Priority debug = Level.DEBUG;
+    logger.l7dlog(debug, "Hello, World", new Object[0], null);
+  }
+
+  /**
+   * Tests setPriority(Priority).
+   * @deprecated
+   */
+  public void testSetPriority() {
+    Logger logger = Logger.getLogger("org.example.foo");
+    Priority debug = Level.DEBUG;
+    logger.setPriority(debug);
+  }
+
+  /**
+   * Derived category to check method signature of forcedLog.
+   */
+  private static class MockCategory extends Logger {
+    /**
+     * Create new instance of MockCategory.
+     * @param name category name
+     */
+    public MockCategory(final String name) {
+      super(name);
+      repository = new Hierarchy(this);
+    }
+
+    /**
+     * Request an info level message.
+     * @param msg message
+     */
+    public void info(final String msg) {
+      Priority info = Level.INFO;
+      forcedLog(MockCategory.class.toString(), info, msg, null);
+    }
+  }
+}

Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java?rev=360145&r1=360144&r2=360145&view=diff
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
(original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
Fri Dec 30 11:05:58 2005
@@ -34,6 +34,8 @@
         TestSuite s = new TestSuite();
         s.addTestSuite(LoggingEventTest.class);
         s.addTestSuite(org.apache.log4j.LevelTest.class);
+        s.addTestSuite(org.apache.log4j.PriorityTest.class);
+        s.addTestSuite(org.apache.log4j.CategoryTest.class);
         s.addTestSuite(org.apache.log4j.FileAppenderTest.class);
         s.addTestSuite(org.apache.log4j.LogManagerTest.class);
         s.addTestSuite(org.apache.log4j.helpers.LogLogTest.class);
@@ -43,6 +45,7 @@
         s.addTestSuite(org.apache.log4j.xml.XMLLayoutTest.class);
         s.addTestSuite(org.apache.log4j.HTMLLayoutTest.class);
         s.addTestSuite(org.apache.log4j.PatternLayoutTest.class);
+        s.addTestSuite(org.apache.log4j.spi.LoggingEventTest.class);
         return s;
     }
 }

Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/FileAppenderTest.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/FileAppenderTest.java?rev=360145&r1=360144&r2=360145&view=diff
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/FileAppenderTest.java
(original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/FileAppenderTest.java
Fri Dec 30 11:05:58 2005
@@ -15,9 +15,13 @@
  */
 
 package org.apache.log4j;
-import java.io.File;
+
 import junit.framework.TestCase;
 
+import java.io.File;
+
+import java.lang.reflect.Method;
+
 
 /**
  *
@@ -32,20 +36,51 @@
    *
    */
   public void testDirectoryCreation() {
-      //
-      //   known to fail on JDK 1.1
-      if (!System.getProperty("java.version").startsWith("1.1.")) {
-          File newFile = new File("output/newdir/temp.log");
-          newFile.delete();
-          File newDir = new File("output/newdir");
-          newDir.delete();
-
-          org.apache.log4j.FileAppender wa = new org.apache.log4j.FileAppender();
-          wa.setFile("output/newdir/temp.log");
-          wa.setLayout(new PatternLayout("%m%n"));
-          wa.activateOptions();
+    //
+    //   known to fail on JDK 1.1
+    if (!System.getProperty("java.version").startsWith("1.1.")) {
+      File newFile = new File("output/newdir/temp.log");
+      newFile.delete();
+
+      File newDir = new File("output/newdir");
+      newDir.delete();
+
+      org.apache.log4j.FileAppender wa = new org.apache.log4j.FileAppender();
+      wa.setFile("output/newdir/temp.log");
+      wa.setLayout(new PatternLayout("%m%n"));
+      wa.activateOptions();
+
+      assertTrue(new File("output/newdir/temp.log").exists());
+    }
+  }
 
-          assertTrue(new File("output/newdir/temp.log").exists());
-      }
+  /**
+   * Tests that the return type of getThreshold is Priority.
+   * @throws Exception
+   */
+  public void testGetThresholdReturnType() throws Exception {
+    Method method = FileAppender.class.getMethod("getThreshold", null);
+    assertTrue(method.getReturnType() == Priority.class);
+  }
+
+  /**
+   * Tests getThreshold and setThreshold.
+   */
+  public void testgetSetThreshold() {
+    FileAppender appender = new FileAppender();
+    Priority debug = Level.DEBUG;
+    Priority all = Level.ALL;
+    assertNull(appender.getThreshold());
+    appender.setThreshold(debug);
+    assertTrue(appender.getThreshold() == debug);
+  }
+
+  /**
+   * Tests isAsSevereAsThreshold.
+   */
+  public void testIsAsSevereAsThreshold() {
+    FileAppender appender = new FileAppender();
+    Priority debug = Level.DEBUG;
+    assertTrue(appender.isAsSevereAsThreshold(debug));
   }
 }

Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/LevelTest.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/LevelTest.java?rev=360145&r1=360144&r2=360145&view=diff
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/LevelTest.java (original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/LevelTest.java Fri
Dec 30 11:05:58 2005
@@ -96,24 +96,147 @@
     }
   }
 
+    /**
+     * Tests Level.TRACE_INT.
+     */
   public void testTraceInt() {
       assertEquals(5000, Level.TRACE_INT);
   }
 
+    /**
+     * Tests Level.TRACE.
+     */
   public void testTrace() {
       assertEquals("TRACE", Level.TRACE.toString());
       assertEquals(5000, Level.TRACE.toInt());
       assertEquals(7, Level.TRACE.getSyslogEquivalent());
   }
 
+    /**
+     * Tests Level.toLevel(Level.TRACE_INT).
+     */
   public void testIntToTrace() {
       Level trace = Level.toLevel(5000);
       assertEquals("TRACE", trace.toString());
   }
 
+    /**
+     * Tests Level.toLevel("TRACE");
+     */
   public void testStringToTrace() {
         Level trace = Level.toLevel("TRACE");
         assertEquals("TRACE", trace.toString());
+  }
+
+    /**
+     * Tests that Level extends Priority.
+     */
+  public void testLevelExtendsPriority() {
+      assertTrue(Priority.class.isAssignableFrom(Level.class));
+  }
+
+    /**
+     * Tests Level.OFF.
+     */
+  public void testOFF() {
+    assertTrue(Level.OFF instanceof Level);
+  }
+
+    /**
+     * Tests Level.FATAL.
+     */
+    public void testFATAL() {
+      assertTrue(Level.FATAL instanceof Level);
+    }
+
+    /**
+     * Tests Level.ERROR.
+     */
+    public void testERROR() {
+      assertTrue(Level.ERROR instanceof Level);
+    }
+
+    /**
+     * Tests Level.WARN.
+     */
+    public void testWARN() {
+      assertTrue(Level.WARN instanceof Level);
+    }
+
+    /**
+     * Tests Level.INFO.
+     */
+    public void testINFO() {
+      assertTrue(Level.INFO instanceof Level);
+    }
+
+    /**
+     * Tests Level.DEBUG.
+     */
+    public void testDEBUG() {
+      assertTrue(Level.DEBUG instanceof Level);
+    }
+
+    /**
+     * Tests Level.TRACE.
+     */
+    public void testTRACE() {
+      assertTrue(Level.TRACE instanceof Level);
+    }
+
+    /**
+     * Tests Level.ALL.
+     */
+    public void testALL() {
+      assertTrue(Level.ALL instanceof Level);
+    }
+
+    /**
+     * Tests Level.serialVersionUID.
+     */
+    public void testSerialVersionUID() {
+      assertEquals(3491141966387921974L, Level.serialVersionUID);
+    }
+
+    /**
+     * Tests Level.toLevel(Level.All_INT).
+     */
+  public void testIntToAll() {
+      Level level = Level.toLevel(Level.ALL_INT);
+      assertEquals("ALL", level.toString());
+  }
+
+    /**
+     * Tests Level.toLevel(Level.FATAL_INT).
+     */
+  public void testIntToFatal() {
+      Level level = Level.toLevel(Level.FATAL_INT);
+      assertEquals("FATAL", level.toString());
+  }
+
+
+    /**
+     * Tests Level.toLevel(Level.OFF_INT).
+     */
+  public void testIntToOff() {
+      Level level = Level.toLevel(Level.OFF_INT);
+      assertEquals("OFF", level.toString());
+  }
+
+    /**
+     * Tests Level.toLevel(17, Level.FATAL).
+     */
+  public void testToLevelUnrecognizedInt() {
+      Level level = Level.toLevel(17, Level.FATAL);
+      assertEquals("FATAL", level.toString());
+  }
+
+    /**
+     * Tests Level.toLevel(null, Level.FATAL).
+     */
+  public void testToLevelNull() {
+      Level level = Level.toLevel(null, Level.FATAL);
+      assertEquals("FATAL", level.toString());
   }
 
 }

Added: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/PriorityTest.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/PriorityTest.java?rev=360145&view=auto
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/PriorityTest.java (added)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/PriorityTest.java Fri
Dec 30 11:05:58 2005
@@ -0,0 +1,185 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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 junit.framework.TestCase;
+
+
+/**
+ * Tests of Priority.
+ *
+ * @author Curt Arnold
+ * @since 1.2.14
+ */
+public class PriorityTest extends TestCase {
+  /**
+   * Constructs new instance of test.
+   * @param name test name.
+   */
+  public PriorityTest(final String name) {
+    super(name);
+  }
+
+  /**
+   * Tests Priority.OFF_INT.
+   */
+  public void testOffInt() {
+    assertEquals(Integer.MAX_VALUE, Priority.OFF_INT);
+  }
+
+  /**
+   * Tests Priority.FATAL_INT.
+   */
+  public void testFatalInt() {
+    assertEquals(50000, Priority.FATAL_INT);
+  }
+
+  /**
+   * Tests Priority.ERROR_INT.
+   */
+  public void testErrorInt() {
+    assertEquals(40000, Priority.ERROR_INT);
+  }
+
+  /**
+   * Tests Priority.WARN_INT.
+   */
+  public void testWarnInt() {
+    assertEquals(30000, Priority.WARN_INT);
+  }
+
+  /**
+   * Tests Priority.INFO_INT.
+   */
+  public void testInfoInt() {
+    assertEquals(20000, Priority.INFO_INT);
+  }
+
+  /**
+   * Tests Priority.DEBUG_INT.
+   */
+  public void testDebugInt() {
+    assertEquals(10000, Priority.DEBUG_INT);
+  }
+
+  /**
+   * Tests Priority.ALL_INT.
+   */
+  public void testAllInt() {
+    assertEquals(Integer.MIN_VALUE, Priority.ALL_INT);
+  }
+
+  /**
+   * Tests Priority.FATAL.
+   * @deprecated
+   */
+  public void testFatal() {
+    assertTrue(Priority.FATAL instanceof Level);
+  }
+
+  /**
+   * Tests Priority.ERROR.
+   * @deprecated
+   */
+  public void testERROR() {
+    assertTrue(Priority.ERROR instanceof Level);
+  }
+
+  /**
+   * Tests Priority.WARN.
+   * @deprecated
+   */
+  public void testWARN() {
+    assertTrue(Priority.WARN instanceof Level);
+  }
+
+  /**
+   * Tests Priority.INFO.
+   * @deprecated
+   */
+  public void testINFO() {
+    assertTrue(Priority.INFO instanceof Level);
+  }
+
+  /**
+   * Tests Priority.DEBUG.
+   * @deprecated
+   */
+  public void testDEBUG() {
+    assertTrue(Priority.DEBUG instanceof Level);
+  }
+
+  /**
+   * Tests Priority.equals(null).
+   * @deprecated
+   */
+  public void testEqualsNull() {
+    assertFalse(Priority.DEBUG.equals(null));
+  }
+
+  /**
+   * Tests Priority.equals(Level.DEBUG).
+   * @deprecated
+   */
+  public void testEqualsLevel() {
+    //
+    //   this behavior violates the equals contract.
+    //
+    assertTrue(Priority.DEBUG.equals(Level.DEBUG));
+  }
+
+  /**
+   * Tests getAllPossiblePriorities().
+   * @deprecated
+   */
+  public void testGetAllPossiblePriorities() {
+    Priority[] priorities = Priority.getAllPossiblePriorities();
+    assertEquals(5, priorities.length);
+  }
+
+  /**
+   * Tests toPriority(String).
+   * @deprecated
+   */
+  public void testToPriorityString() {
+    assertTrue(Priority.toPriority("DEBUG") == Level.DEBUG);
+  }
+
+  /**
+   * Tests toPriority(int).
+   * @deprecated
+   */
+  public void testToPriorityInt() {
+    assertTrue(Priority.toPriority(Priority.DEBUG_INT) == Level.DEBUG);
+  }
+
+  /**
+   * Tests toPriority(String, Priority).
+   * @deprecated
+   */
+  public void testToPriorityStringPriority() {
+    assertTrue(Priority.toPriority("foo", Priority.DEBUG) == Priority.DEBUG);
+  }
+
+  /**
+   * Tests toPriority(int, Priority).
+   * @deprecated
+   */
+  public void testToPriorityIntPriority() {
+    assertTrue(Priority.toPriority(17, Priority.DEBUG) == Priority.DEBUG);
+  }
+}

Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LoggingEventTest.java
URL: http://svn.apache.org/viewcvs/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LoggingEventTest.java?rev=360145&r1=360144&r2=360145&view=diff
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LoggingEventTest.java
(original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LoggingEventTest.java
Fri Dec 30 11:05:58 2005
@@ -24,6 +24,8 @@
 import org.apache.log4j.NDC;
 import org.apache.log4j.spi.LocationInfo;
 import org.apache.log4j.util.SerializationTestHelper;
+import org.apache.log4j.Priority;
+import org.apache.log4j.Category;
 
 
 /**
@@ -182,4 +184,35 @@
     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);
+  }
+
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message