1 package ch.qos.logback.classic.spi;
2
3 import ch.qos.logback.classic.ClassicTestConstants;
4 import ch.qos.logback.classic.Logger;
5 import ch.qos.logback.classic.LoggerContext;
6 import ch.qos.logback.classic.joran.JoranConfigurator;
7 import ch.qos.logback.core.joran.spi.JoranException;
8 import ch.qos.logback.core.testUtil.RandomUtil;
9 import ch.qos.logback.core.status.testUtil.StatusChecker;
10 import org.junit.jupiter.api.Test;
11
12 import java.util.List;
13
14 import static org.junit.jupiter.api.Assertions.assertEquals;
15
16 public class LoggerContextLifeCycleTest {
17
18 LoggerContext loggerContext = new LoggerContext();
19 Logger logger = loggerContext.getLogger(this.getClass().getName());
20 Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
21 StatusChecker checker = new StatusChecker(loggerContext);
22 int diff = RandomUtil.getPositiveInt();
23
24 void configure(String file) throws JoranException {
25 JoranConfigurator jc = new JoranConfigurator();
26 jc.setContext(loggerContext);
27 loggerContext.putProperty("diff", "" + diff);
28 jc.doConfigure(file);
29 loggerContext.start();
30 }
31
32 @Test
33 public void smoke() throws JoranException {
34 configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "spi/contextListener.xml");
35
36 List<LoggerContextListener> listenerList = loggerContext.getCopyOfListenerList();
37 assertEquals(1, listenerList.size());
38
39 ListContextListener lcl = (ListContextListener) listenerList.get(0);
40
41 assertEquals(BasicContextListener.UpdateType.START, lcl.updateList.get(1));
42 }
43
44 @Test
45 public void smokeWithImports() throws JoranException {
46 configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "spi/contextListenerWithImports.xml");
47
48 List<LoggerContextListener> listenerList = loggerContext.getCopyOfListenerList();
49 assertEquals(1, listenerList.size());
50
51 ListContextListener lcl = (ListContextListener) listenerList.get(0);
52
53 assertEquals(BasicContextListener.UpdateType.START, lcl.updateList.get(1));
54 }
55
56 }