[logback-dev] svn commit: r1947 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic main/java/ch/qos/logback/classic/jmx main/java/ch/qos/logback/classic/joran/action test/java/ch/qos/logback/classic test/java/ch/qos/logback/classic/jmx

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Nov 6 15:09:53 CET 2008


Author: ceki
Date: Thu Nov  6 15:09:53 2008
New Revision: 1947

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java
Removed:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java

Log:
This commit is related to:

 LBCLASSIC-83 (Logger.setLevel(null) may throw an NPE)

 LBCLASSIC-61 (configurable ObjectName)
 LBCLASSIC-24 (better error messages after reload)
 LBCLASSIC-33 (JMX configurator unregisters itself)
 LBCLASSIC-78 (NPE in JMXConfigurator getLoggerLevel)
 LBCLASSIC-79 (NPE in JMXConfigurator setLoggerLevel)
 

While testing LBCLASSIC 61,24 and 33, I wanted to correct LBCLASSIC-78
and LBCLASSIC-79 which are related to JMXConfigurator. It turns out
that LBCLASSIC-79 has a much deeper cause identified in LBCLASSIC-83.

Work on LBCLASSIC 61,24 and 33 is still ongoing. The present commit
reflects the nature of that ongoing and incomplete work.




Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	Thu Nov  6 15:09:53 2008
@@ -127,39 +127,8 @@
     return parent == null;
   }
 
-  /**
-   * Get a child by its suffix.
-   * 
-   * <p> IMPORTANT: Calls to this method must be within a synchronized block on
-   * this logger!
-   * 
-   * @param suffix
-   * @return
-   */
-  Logger getChildBySuffix(final String suffix) {
-    if (childrenList == null) {
-      return null;
-    } else {
-      int len = this.childrenList.size();
-      int childNameOffset;
-      if (isRootLogger()) {
-        childNameOffset = 0;
-      } else {
-        childNameOffset = this.name.length() + 1;
-      }
-
-      for (int i = 0; i < len; i++) {
-        final Logger childLogger = (Logger) childrenList.get(i);
-        final String childName = childLogger.getName();
-
-        if (suffix.equals(childName.substring(childNameOffset))) {
-          return childLogger;
-        }
-      }
-      // no child found
-      return null;
-    }
-  }
+  // Logger getChildBySuffix(final String suffix) method was here and got
+  // removed.
 
   Logger getChildByName(final String childName) {
     if (childrenList == null) {
@@ -185,7 +154,15 @@
       return;
     }
     level = newLevel;
-    effectiveLevelInt = newLevel.levelInt;
+    if (newLevel == null) {
+      if (isRootLogger()) {
+        throw new IllegalArgumentException("The level of the root logger cannot be set to null");
+      } else {
+        effectiveLevelInt = parent.effectiveLevelInt;
+      }
+    } else {
+      effectiveLevelInt = newLevel.levelInt;
+    }
     if (childrenList != null) {
       int len = childrenList.size();
       for (int i = 0; i < len; i++) {
@@ -390,8 +367,9 @@
       final Marker marker, final Level level, final String msg,
       final Object[] params, final Throwable t) {
 
-    final FilterReply decision = loggerContext.getTurboFilterChainDecision_0_3OrMore(
-        marker, this, level, msg, params, t);
+    final FilterReply decision = loggerContext
+        .getTurboFilterChainDecision_0_3OrMore(marker, this, level, msg,
+            params, t);
 
     if (decision == FilterReply.NEUTRAL) {
       if (effectiveLevelInt > level.levelInt) {
@@ -403,7 +381,7 @@
 
     buildLoggingEventAndAppend(localFQCN, marker, level, msg, params, t);
   }
-  
+
   private final void filterAndLog_1(final String localFQCN,
       final Marker marker, final Level level, final String msg,
       final Object param, final Throwable t) {
@@ -423,7 +401,6 @@
         new Object[] { param }, t);
   }
 
-
   private final void filterAndLog_2(final String localFQCN,
       final Marker marker, final Level level, final String msg,
       final Object param1, final Object param2, final Throwable t) {
@@ -443,8 +420,6 @@
         param1, param2 }, t);
   }
 
-
-
   private void buildLoggingEventAndAppend(final String localFQCN,
       final Marker marker, final Level level, final String msg,
       final Object[] params, final Throwable t) {
@@ -493,7 +468,7 @@
     filterAndLog_0_Or3Plus(FQCN, marker, Level.TRACE, msg, null, t);
   }
 
-  final public  boolean isDebugEnabled() {
+  final public boolean isDebugEnabled() {
     return isDebugEnabled(null);
   }
 
@@ -509,7 +484,7 @@
       throw new IllegalStateException("Unknown FilterReply value: " + decision);
     }
   }
-  
+
   final public void debug(String msg) {
     filterAndLog_0_Or3Plus(FQCN, null, Level.DEBUG, msg, null, null);
   }
@@ -593,7 +568,7 @@
   public boolean isInfoEnabled() {
     return isInfoEnabled(null);
   }
-  
+
   public boolean isInfoEnabled(Marker marker) {
     FilterReply decision = callTurboFilters(marker, Level.INFO);
     if (decision == FilterReply.NEUTRAL) {
@@ -606,7 +581,7 @@
       throw new IllegalStateException("Unknown FilterReply value: " + decision);
     }
   }
-  
+
   public void info(String msg) {
     filterAndLog_0_Or3Plus(FQCN, null, Level.INFO, msg, null, null);
   }
@@ -664,8 +639,6 @@
     }
   }
 
-
-
   public final boolean isErrorEnabled() {
     return isErrorEnabled(null);
   }
@@ -683,7 +656,6 @@
     }
   }
 
-
   public boolean isWarnEnabled() {
     return isWarnEnabled(null);
   }
@@ -783,8 +755,8 @@
    * @return the reply given by the TurboFilters
    */
   private FilterReply callTurboFilters(Marker marker, Level level) {
-    return loggerContext.getTurboFilterChainDecision_0_3OrMore(marker, this, level, null,
-        null, null);
+    return loggerContext.getTurboFilterChainDecision_0_3OrMore(marker, this,
+        level, null, null, null);
   }
 
   /**

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	Thu Nov  6 15:09:53 2008
@@ -65,6 +65,7 @@
 
   public LoggerContext() {
     super();
+    System.out.println(" LoggerContext()=============================================================");
     this.loggerCache = new Hashtable<String, Logger>();
     this.loggerContextRemoteView = new LoggerContextRemoteView(this);
     this.root = new Logger(ROOT_NAME, null, this);
@@ -128,7 +129,7 @@
     // in between as well (if they don't already exist)
     String childName;
     while (true) {
-      int h = name.indexOf('.', i);
+      int h = name.indexOf(ClassicGlobal.LOGGER_SEPARATOR, i);
       if (h == -1) {
         childName = name;
       } else {
@@ -189,6 +190,10 @@
     return loggerContextRemoteView;
   }
 
+  @Override
+  protected void finalize() {
+    System.out.println("**************** LoggerContext finalized");
+  }
   public void reset() {
     root.recursiveReset();
     clearAllTurboFilters();
@@ -300,8 +305,8 @@
     started = false;
   }
 
-  @Override
-  public String toString() {
-    return this.getClass().getName() + "[" + getName() + "]";
-  }
+//  @Override
+//  public String toString() {
+//    return this.getClass().getName() + "[" + getName() + "]";
+//  }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/JMXConfigurator.java	Thu Nov  6 15:09:53 2008
@@ -31,6 +31,7 @@
 import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.spi.ContextAwareBase;
 import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusListener;
 import ch.qos.logback.core.status.StatusListenerAsList;
 import ch.qos.logback.core.status.StatusManager;
 import ch.qos.logback.core.util.StatusPrinter;
@@ -55,6 +56,12 @@
   final MBeanServer mbs;
   final ObjectName objectName;
 
+
+  @Override
+  protected void finalize() {
+    System.out.println("**************** JMXConfigurator finalized");
+  }
+  
   public JMXConfigurator(LoggerContext loggerContext, MBeanServer mbs,
       ObjectName objectName) {
     this.context = loggerContext;
@@ -105,20 +112,27 @@
     }
   }
 
+  void addStatusListener(StatusListener statusListener) {
+    StatusManager sm = loggerContext.getStatusManager();
+    sm.add(statusListener);
+  }
+  
   public void reloadByURL(URL url) throws JoranException {
     StatusListenerAsList statusListenerAsList = new StatusListenerAsList();
-    StatusManager sm = loggerContext.getStatusManager();
-    sm.add(statusListenerAsList);
 
+    addStatusListener(statusListenerAsList);
     addInfo("Resetting context: " + loggerContext.getName());
     loggerContext.reset();
+    addStatusListener(statusListenerAsList);
 
+    
     try {
       JoranConfigurator configurator = new JoranConfigurator();
       configurator.setContext(loggerContext);
       configurator.doConfigure(url);
       addInfo("Context: " + loggerContext.getName() + " reloaded.");
     } finally {
+      System.out.println("*************** printing");
       StatusPrinter.print(statusListenerAsList.getStatusList());
     }
   }
@@ -156,7 +170,7 @@
 
     LoggerContext lc = (LoggerContext) context;
     Logger logger = lc.exists(loggerName);
-    if (logger != null) {
+    if (logger != null && logger.getLevel() != null) {
       return logger.getLevel().toString();
     } else {
       return EMPTY;
@@ -205,6 +219,7 @@
    * unregistered
    */
   public void onReset(LoggerContext context) {
+    System.out.println("Unregistering JMXConfigurator");
     if (mbs.isRegistered(objectName)) {
       try {
         addInfo("Unregistering mbean [" + objectName + "]");

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/JMXConfiguratorAction.java	Thu Nov  6 15:09:53 2008
@@ -34,7 +34,7 @@
     ObjectName objectName = MBeanUtil.string2ObjectName(context, this,
         objectNameAsStr);
 
-    if (objectName == null) {
+    if (objectName != null) {
       MBeanUtil.register((LoggerContext) context, objectName, this);
     }
 

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/LoggerTest.java	Thu Nov  6 15:09:53 2008
@@ -9,54 +9,66 @@
  */
 package ch.qos.logback.classic;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
+import java.util.List;
+
+import org.junit.Test;
 import org.slf4j.LoggerFactory;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.read.ListAppender;
-import ch.qos.logback.core.util.StatusPrinter;
+import ch.qos.logback.core.status.Status;
+
+public class LoggerTest {
 
-public class BasicLoggerTest extends TestCase {
+  LoggerContext lc = new LoggerContext();
+  Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+  Logger loggerTest = lc.getLogger(LoggerTest.class);
 
-  public void testBasic() {
-    LoggerContext lc = new LoggerContext();
+  ListAppender<LoggingEvent> listAppender = new ListAppender<LoggingEvent>();
+
+  @Test
+  public void smoke() {
     ListAppender<LoggingEvent> listAppender = new ListAppender<LoggingEvent>();
     listAppender.start();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.addAppender(listAppender);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
+    Logger logger = lc.getLogger(LoggerTest.class);
     assertEquals(0, listAppender.list.size());
     logger.debug("hello");
     assertEquals(1, listAppender.list.size());
   }
 
+  @Test
   public void testNoStart() {
-    LoggerContext lc = new LoggerContext();
-    ListAppender<LoggingEvent> listAppender = new ListAppender<LoggingEvent>();
     // listAppender.start();
     listAppender.setContext(lc);
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.addAppender(listAppender);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
+    Logger logger = lc.getLogger(LoggerTest.class);
     logger.debug("hello");
-    StatusPrinter.print(lc.getStatusManager());
+
+    List<Status> statusList = lc.getStatusManager().getCopyOfStatusList();
+    Status s0 = statusList.get(0);
+    assertEquals(Status.WARN, s0.getLevel());
+    assertTrue(s0.getMessage().startsWith("Attempted to append to non started"));
   }
 
+  @Test
   public void testAdditive() {
-    LoggerContext lc = new LoggerContext();
-    ListAppender<LoggingEvent> listAppender = new ListAppender<LoggingEvent>();
     listAppender.start();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.addAppender(listAppender);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    logger.addAppender(listAppender);
-    logger.setAdditive(false);
-    logger.debug("hello");
+    loggerTest.addAppender(listAppender);
+    loggerTest.setAdditive(false);
+    loggerTest.debug("hello");
     // 1 instead of two, since logger is not additive
     assertEquals(1, listAppender.list.size());
   }
 
+  @Test
   public void testRootLogger() {
     Logger logger = (Logger) LoggerFactory.getLogger(LoggerContext.ROOT_NAME);
     LoggerContext lc = logger.getLoggerContext();
@@ -66,112 +78,115 @@
         LoggerContext.ROOT_NAME);
     assertTrue("logger instances should be indentical", logger == lc.root);
   }
-  
+
+  @Test
   public void testBasicFiltering() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    ListAppender<LoggingEvent> listAppender = new ListAppender<LoggingEvent>();
     listAppender.start();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.addAppender(listAppender);
     root.setLevel(Level.INFO);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    logger.debug("x");
+    loggerTest.debug("x");
     assertEquals(0, listAppender.list.size());
-    logger.info("x");
-    logger.warn("x");
-    logger.error("x");
+    loggerTest.info("x");
+    loggerTest.warn("x");
+    loggerTest.error("x");
     assertEquals(3, listAppender.list.size());
   }
 
-  public void testEnabledX_All() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+  void checkLevelThreshold(Logger logger, Level threshold) {
+
+    if (Level.ERROR_INT >= threshold.levelInt) {
+      assertTrue(logger.isErrorEnabled());
+      assertTrue(logger.isEnabledFor(Level.ERROR));
+    } else {
+      assertFalse(logger.isErrorEnabled());
+      assertFalse(logger.isEnabledFor(Level.ERROR));
+    }
+
+    if (Level.WARN_INT >= threshold.levelInt) {
+      assertTrue(logger.isWarnEnabled());
+      assertTrue(logger.isEnabledFor(Level.WARN));
+    } else {
+      assertFalse(logger.isWarnEnabled());
+      assertFalse(logger.isEnabledFor(Level.WARN));
+    }
+    if (Level.INFO_INT >= threshold.levelInt) {
+      assertTrue(logger.isInfoEnabled());
+      assertTrue(logger.isEnabledFor(Level.INFO));
+    } else {
+      assertFalse(logger.isInfoEnabled());
+      assertFalse(logger.isEnabledFor(Level.INFO));
+    }
+    if (Level.DEBUG_INT >= threshold.levelInt) {
+      assertTrue(logger.isDebugEnabled());
+      assertTrue(logger.isEnabledFor(Level.DEBUG));
+    } else {
+      assertFalse(logger.isDebugEnabled());
+      assertFalse(logger.isEnabledFor(Level.DEBUG));
+    }
+    if (Level.TRACE_INT >= threshold.levelInt) {
+      assertTrue(logger.isTraceEnabled());
+      assertTrue(logger.isEnabledFor(Level.TRACE));
+    } else {
+      assertFalse(logger.isTraceEnabled());
+      assertFalse(logger.isEnabledFor(Level.TRACE));
+    }
+
+  }
+
+  @Test
+  public void testEnabled_All() throws Exception {
     root.setLevel(Level.ALL);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertTrue(logger.isDebugEnabled());
-    assertTrue(logger.isInfoEnabled());
-    assertTrue(logger.isWarnEnabled());
-    assertTrue(logger.isErrorEnabled());
-    assertTrue(logger.isEnabledFor(Level.DEBUG));
-    assertTrue(logger.isEnabledFor(Level.INFO));
-    assertTrue(logger.isEnabledFor(Level.WARN));    
-    assertTrue(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.ALL);
   }
-  
-  public void testEnabledX_Debug() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+
+  @Test
+  public void testEnabled_Debug() throws Exception {
     root.setLevel(Level.DEBUG);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertTrue(logger.isDebugEnabled());
-    assertTrue(logger.isInfoEnabled());
-    assertTrue(logger.isWarnEnabled());
-    assertTrue(logger.isErrorEnabled());
-    assertTrue(logger.isEnabledFor(Level.DEBUG));
-    assertTrue(logger.isEnabledFor(Level.INFO));
-    assertTrue(logger.isEnabledFor(Level.WARN));    
-    assertTrue(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.DEBUG);
   }
-  
-  
-  
-  public void testEnabledX_Info() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
+
+  @Test
+  public void testEnabled_Info() throws Exception {
     root.setLevel(Level.INFO);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertFalse(logger.isDebugEnabled());
-    assertTrue(logger.isInfoEnabled());
-    assertTrue(logger.isWarnEnabled());
-    assertTrue(logger.isErrorEnabled());
-    assertFalse(logger.isEnabledFor(Level.DEBUG));
-    assertTrue(logger.isEnabledFor(Level.INFO));
-    assertTrue(logger.isEnabledFor(Level.WARN));    
-    assertTrue(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.INFO);
   }
-  
+
+  @Test
   public void testEnabledX_Warn() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.setLevel(Level.WARN);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertFalse(logger.isDebugEnabled());
-    assertFalse(logger.isInfoEnabled());
-    assertTrue(logger.isWarnEnabled());
-    assertTrue(logger.isErrorEnabled());
-    assertFalse(logger.isEnabledFor(Level.DEBUG));
-    assertFalse(logger.isEnabledFor(Level.INFO));
-    assertTrue(logger.isEnabledFor(Level.WARN));    
-    assertTrue(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.WARN);
   }
-  
+
   public void testEnabledX_Errror() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.setLevel(Level.ERROR);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertFalse(logger.isDebugEnabled());
-    assertFalse(logger.isInfoEnabled());
-    assertFalse(logger.isWarnEnabled());
-    assertTrue(logger.isErrorEnabled());
-    assertFalse(logger.isEnabledFor(Level.DEBUG));
-    assertFalse(logger.isEnabledFor(Level.INFO));
-    assertFalse(logger.isEnabledFor(Level.WARN));    
-    assertTrue(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.ERROR);
   }
 
+  @Test
   public void testEnabledX_Off() throws Exception {
-    LoggerContext lc = new LoggerContext();
-    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
     root.setLevel(Level.OFF);
-    Logger logger = lc.getLogger(BasicLoggerTest.class);
-    assertFalse(logger.isDebugEnabled());
-    assertFalse(logger.isInfoEnabled());
-    assertFalse(logger.isWarnEnabled());
-    assertFalse(logger.isErrorEnabled());
-    assertFalse(logger.isEnabledFor(Level.DEBUG));
-    assertFalse(logger.isEnabledFor(Level.INFO));
-    assertFalse(logger.isEnabledFor(Level.WARN));    
-    assertFalse(logger.isEnabledFor(Level.ERROR));
+    checkLevelThreshold(loggerTest, Level.OFF);
+  }
+
+  @Test
+  public void setRootLevelToNull() {
+    try {
+      root.setLevel(null);
+      fail("The level of the root logger should not be settable to null");
+    } catch (IllegalArgumentException e) {
+    }
+  }
+
+  @Test
+  public void setLevelToNull_A() {
+    loggerTest.setLevel(null);
+    assertEquals(root.getEffectiveLevel(), loggerTest.getEffectiveLevel());
+  }
+  
+  @Test
+  public void setLevelToNull_B() {
+    loggerTest.setLevel(Level.DEBUG);
+    loggerTest.setLevel(null);
+    assertEquals(root.getEffectiveLevel(), loggerTest.getEffectiveLevel());
   }
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PackageTest.java	Thu Nov  6 15:09:53 2008
@@ -19,7 +19,7 @@
     suite.addTest(new JUnit4TestAdapter(LoggerPerfTest.class));
     suite.addTest(new JUnit4TestAdapter(DynamicLoggerContextTest.class));
     suite.addTest(new JUnit4TestAdapter(PatternLayoutTest.class));
-    suite.addTestSuite(BasicLoggerTest.class);
+    suite.addTest(new JUnit4TestAdapter(LoggerTest.class));
     suite.addTest(new JUnit4TestAdapter(LoggerSerializationTest.class));
     suite.addTestSuite(MessageFormattingTest.class);
     suite.addTestSuite(MDCTest.class);

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/JMXConfiguratorTest.java	Thu Nov  6 15:09:53 2008
@@ -0,0 +1,98 @@
+package ch.qos.logback.classic.jmx;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggerContextListener;
+import ch.qos.logback.core.testUtil.RandomUtil;
+
+public class JMXConfiguratorTest {
+
+  static MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+  LoggerContext lc = new LoggerContext();
+  Logger testLogger  = lc.getLogger(this.getClass());
+
+  List<LoggerContextListener> listenerList;
+  int diff = RandomUtil.getPositiveInt();
+
+  @Before
+  public void setUp() throws Exception {
+    lc.setName("context-" + diff);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    lc.reset();
+  }
+
+  @Override
+  public String toString() {
+    return this.getClass().getName() + "(" + lc.getName() + ")";
+  }
+
+  @Test
+  public void contextListening() {
+    String objectNameAsStr = "ch.qos.logback.toto" + ":Name=" + lc.getName()
+        + ",Type=" + this.getClass().getName();
+    ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+
+    MBeanUtil.register(lc, on, this);
+    listenerList = lc.getCopyOfListenerList();
+    assertEquals(1, listenerList.size());
+    lc.reset();
+    listenerList = lc.getCopyOfListenerList();
+    assertEquals(0, listenerList.size());
+
+    MBeanUtil.register(lc, on, this);
+    listenerList = lc.getCopyOfListenerList();
+    assertEquals(1, listenerList.size());
+
+  }
+
+  @Test
+  public void testRemovalOfPreviousIntanceFromTheContextListenerList() {
+    String objectNameAsStr = "ch.qos.logback.toto" + ":Name=" + lc.getName()
+        + ",Type=" + this.getClass().getName();
+
+    ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+    JMXConfigurator jmxConfigurator0 = MBeanUtil.register(lc, on, this);
+
+    listenerList = lc.getCopyOfListenerList();
+    assertEquals(1, listenerList.size());
+    assertTrue(listenerList.contains(jmxConfigurator0));
+
+    JMXConfigurator jmxConfigurator1 = MBeanUtil.register(lc, on, this);
+    listenerList = lc.getCopyOfListenerList();
+    assertEquals(1, listenerList.size());
+    assertFalse("old configurator should be absent", listenerList
+        .contains(jmxConfigurator0));
+    assertTrue("new configurator should be present", listenerList
+        .contains(jmxConfigurator1));
+
+    // StatusPrinter.print(lc);
+  }
+
+  @Test
+  public void getLoggerLevel() {
+    String objectNameAsStr = "ch.qos"+diff + ":Name=" + lc.getName()
+        + ",Type=" + this.getClass().getName();
+
+    ObjectName on = MBeanUtil.string2ObjectName(lc, this, objectNameAsStr);
+    JMXConfigurator configurator = new JMXConfigurator(lc, mbs, on);
+    configurator.getLoggerLevel(testLogger.getName());
+  }
+
+}


More information about the logback-dev mailing list