View Javadoc
1   package ch.qos.logback.core.joran.sanity;
2   
3   import ch.qos.logback.core.Context;
4   import ch.qos.logback.core.ContextBase;
5   import ch.qos.logback.core.model.AppenderModel;
6   import ch.qos.logback.core.model.TopModel;
7   import ch.qos.logback.core.status.Status;
8   import ch.qos.logback.core.status.testUtil.StatusChecker;
9   import org.junit.jupiter.api.BeforeEach;
10  import org.junit.jupiter.api.Test;
11  
12  import static ch.qos.logback.core.joran.sanity.AppenderWithinAppenderSanityChecker.NESTED_APPENDERS_WARNING;
13  
14  public class AppenderWithinAppenderSanityCheckerTest {
15  
16  
17      Context context = new ContextBase();
18      AppenderWithinAppenderSanityChecker awasc = new AppenderWithinAppenderSanityChecker();
19      StatusChecker statusChecker = new StatusChecker(context);
20  
21      @BeforeEach
22      public void setUp() throws Exception {
23          awasc.setContext(context);
24      }
25  
26      @Test
27      public void smoke() {
28  
29          TopModel topModel = new TopModel();
30          awasc.check(topModel);
31          statusChecker.assertIsWarningOrErrorFree();
32      }
33  
34  
35      @Test
36      public void singleAppender() {
37          TopModel topModel = new TopModel();
38          AppenderModel appenderModel0 = new AppenderModel();
39          appenderModel0.setLineNumber(1);
40          topModel.addSubModel(appenderModel0);
41          awasc.check(topModel);
42          statusChecker.assertIsWarningOrErrorFree();
43      }
44  
45      @Test
46      public void nestedAppender() {
47          TopModel topModel = new TopModel();
48          AppenderModel appenderModel0 = new AppenderModel();
49          appenderModel0.setLineNumber(1);
50          topModel.addSubModel(appenderModel0);
51  
52          AppenderModel appenderModel1 = new AppenderModel();
53          appenderModel1.setLineNumber(2);
54          appenderModel0.addSubModel(appenderModel1);
55  
56          awasc.check(topModel);
57  
58          statusChecker.assertContainsMatch(Status.WARN, NESTED_APPENDERS_WARNING);
59          statusChecker.assertContainsMatch(Status.WARN,"Appender at line 1");
60      }
61  
62  }