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.turbo;
15  
16  import ch.qos.logback.core.spi.FilterReply;
17  import org.junit.jupiter.api.Test;
18  import org.slf4j.Marker;
19  import org.slf4j.MarkerFactory;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertFalse;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  public class MarkerFilterTest {
26  
27      static String TOTO = "TOTO";
28      static String COMPOSITE = "COMPOSITE";
29  
30      Marker totoMarker = MarkerFactory.getMarker(TOTO);
31  
32      @Test
33      public void testNoMarker() {
34          MarkerFilter mkt = new MarkerFilter();
35          mkt.start();
36          assertFalse(mkt.isStarted());
37          assertEquals(FilterReply.NEUTRAL, mkt.decide(totoMarker, null, null, null, null, null));
38          assertEquals(FilterReply.NEUTRAL, mkt.decide(null, null, null, null, null, null));
39  
40      }
41  
42      @Test
43      public void testBasic() {
44          MarkerFilter mkt = new MarkerFilter();
45          mkt.setMarker(TOTO);
46          mkt.setOnMatch("ACCEPT");
47          mkt.setOnMismatch("DENY");
48  
49          mkt.start();
50          assertTrue(mkt.isStarted());
51          assertEquals(FilterReply.DENY, mkt.decide(null, null, null, null, null, null));
52          assertEquals(FilterReply.ACCEPT, mkt.decide(totoMarker, null, null, null, null, null));
53      }
54  
55      @Test
56      public void testComposite() {
57          String compositeMarkerName = COMPOSITE;
58          Marker compositeMarker = MarkerFactory.getMarker(compositeMarkerName);
59          compositeMarker.add(totoMarker);
60  
61          MarkerFilter mkt = new MarkerFilter();
62          mkt.setMarker(TOTO);
63          mkt.setOnMatch("ACCEPT");
64          mkt.setOnMismatch("DENY");
65  
66          mkt.start();
67  
68          assertTrue(mkt.isStarted());
69          assertEquals(FilterReply.DENY, mkt.decide(null, null, null, null, null, null));
70          assertEquals(FilterReply.ACCEPT, mkt.decide(totoMarker, null, null, null, null, null));
71          assertEquals(FilterReply.ACCEPT, mkt.decide(compositeMarker, null, null, null, null, null));
72      }
73  
74  }