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