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.boolex;
015
016import ch.qos.logback.classic.ClassicTestConstants;
017import ch.qos.logback.classic.Level;
018import ch.qos.logback.classic.Logger;
019import ch.qos.logback.classic.LoggerContext;
020import ch.qos.logback.classic.joran.JoranConfigurator;
021import ch.qos.logback.core.joran.conditional.IfAction;
022import ch.qos.logback.core.joran.spi.JoranException;
023import ch.qos.logback.core.testUtil.StatusChecker;
024import ch.qos.logback.core.util.StatusPrinter;
025import org.junit.Test;
026
027import static org.junit.Assert.*;
028
029/**
030 * @author Ceki Gülcü
031 */
032public class ConditionalWithoutJanino {
033
034    LoggerContext loggerContext = new LoggerContext();
035    Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
036
037    void configure(String file) throws JoranException {
038        JoranConfigurator jc = new JoranConfigurator();
039        jc.setContext(loggerContext);
040        jc.doConfigure(file);
041    }
042
043    // assume that janino.jar ia NOT on the classpath
044    @Test
045    public void conditionalWithoutJanino() throws JoranException {
046        String configFile = ClassicTestConstants.JORAN_INPUT_PREFIX + "conditional/withoutJanino.xml";
047        String currentDir = System.getProperty("user.dir");
048        if (!currentDir.contains("logback-classic")) {
049            configFile = "logback-classic/" + configFile;
050        }
051        configure(configFile);
052        StatusPrinter.print(loggerContext);
053        StatusChecker checker = new StatusChecker(loggerContext);
054        checker.assertContainsMatch(IfAction.MISSING_JANINO_MSG);
055
056        assertSame(Level.WARN, loggerContext.getLogger("a").getLevel());
057        assertSame(Level.WARN, root.getLevel());
058    }
059
060}