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.boolex;
15  
16  import ch.qos.logback.classic.ClassicTestConstants;
17  import ch.qos.logback.classic.Level;
18  import ch.qos.logback.classic.Logger;
19  import ch.qos.logback.classic.LoggerContext;
20  import ch.qos.logback.classic.joran.JoranConfigurator;
21  import ch.qos.logback.core.joran.conditional.IfAction;
22  import ch.qos.logback.core.joran.spi.JoranException;
23  import ch.qos.logback.core.testUtil.StatusChecker;
24  import ch.qos.logback.core.util.StatusPrinter;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.*;
28  
29  /**
30   * @author Ceki Gülcü
31   */
32  public class ConditionalWithoutJanino {
33  
34      LoggerContext loggerContext = new LoggerContext();
35      Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
36  
37      void configure(String file) throws JoranException {
38          JoranConfigurator jc = new JoranConfigurator();
39          jc.setContext(loggerContext);
40          jc.doConfigure(file);
41      }
42  
43      // assume that janino.jar ia NOT on the classpath
44      @Test
45      public void conditionalWithoutJanino() throws JoranException {
46          String configFile = ClassicTestConstants.JORAN_INPUT_PREFIX + "conditional/withoutJanino.xml";
47          String currentDir = System.getProperty("user.dir");
48          if (!currentDir.contains("logback-classic")) {
49              configFile = "logback-classic/" + configFile;
50          }
51          configure(configFile);
52          StatusPrinter.print(loggerContext);
53          StatusChecker checker = new StatusChecker(loggerContext);
54          checker.assertContainsMatch(IfAction.MISSING_JANINO_MSG);
55  
56          assertSame(Level.WARN, loggerContext.getLogger("a").getLevel());
57          assertSame(Level.WARN, root.getLevel());
58      }
59  
60  }