001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.util;
015
016import static org.junit.Assert.assertNotNull;
017import static org.junit.Assert.assertTrue;
018
019import org.junit.After;
020import org.junit.Before;
021import org.junit.Ignore;
022import org.junit.Test;
023import org.slf4j.LoggerFactory;
024
025import ch.qos.logback.classic.ClassicConstants;
026import ch.qos.logback.classic.Logger;
027import ch.qos.logback.classic.LoggerContext;
028import ch.qos.logback.classic.spi.ILoggingEvent;
029import ch.qos.logback.core.Appender;
030import ch.qos.logback.core.ConsoleAppender;
031import ch.qos.logback.core.CoreConstants;
032
033public class ContextInitializerAutoConfigTest {
034
035    org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
036    Logger root = (Logger) LoggerFactory.getLogger("root");
037
038    @Before
039    public void setUp() throws Exception {
040        logger.debug("Hello-didily-odily");
041    }
042
043    @After
044    public void tearDown() throws Exception {
045        System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
046        System.clearProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY);
047    }
048
049    @Test
050    @Ignore
051    // this test works only if logback-test.xml or logback.xml files are on the classpath.
052    // However, this is something we try to avoid in order to simplify the life
053    // of users trying to follows the manual and logback-examples from an IDE
054    public void autoconfig() {
055        LoggerContext iLoggerFactory = (LoggerContext) LoggerFactory.getILoggerFactory();
056        iLoggerFactory.reset();
057        Appender<ILoggingEvent> appender = root.getAppender("STDOUT");
058        assertNotNull(appender);
059        assertTrue(appender instanceof ConsoleAppender);
060    }
061}