View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.util;
15  
16  import static org.junit.Assert.assertNotNull;
17  import static org.junit.Assert.assertTrue;
18  
19  import org.junit.After;
20  import org.junit.Before;
21  import org.junit.Ignore;
22  import org.junit.Test;
23  import org.slf4j.LoggerFactory;
24  
25  import ch.qos.logback.classic.ClassicConstants;
26  import ch.qos.logback.classic.Logger;
27  import ch.qos.logback.classic.LoggerContext;
28  import ch.qos.logback.classic.spi.ILoggingEvent;
29  import ch.qos.logback.core.Appender;
30  import ch.qos.logback.core.ConsoleAppender;
31  import ch.qos.logback.core.CoreConstants;
32  
33  public class ContextInitializerAutoConfigTest {
34  
35      org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
36      Logger root = (Logger) LoggerFactory.getLogger("root");
37  
38      @Before
39      public void setUp() throws Exception {
40          logger.debug("Hello-didily-odily");
41      }
42  
43      @After
44      public void tearDown() throws Exception {
45          System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
46          System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
47      }
48  
49      @Test
50      @Ignore
51      // this test works only if logback-test.xml or logback.xml files are on the classpath.
52      // However, this is something we try to avoid in order to simplify the life
53      // of users trying to follows the manual and logback-examples from an IDE
54      public void autoconfig() {
55          LoggerContext iLoggerFactory = (LoggerContext) LoggerFactory.getILoggerFactory();
56          iLoggerFactory.reset();
57          Appender<ILoggingEvent> appender = root.getAppender("STDOUT");
58          assertNotNull(appender);
59          assertTrue(appender instanceof ConsoleAppender);
60      }
61  }