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.access.servlet;
15  
16  import org.junit.Test;
17  
18  import java.util.Arrays;
19  
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertTrue;
22  import static org.junit.Assert.assertEquals;
23  
24  public class TeeFilterTest {
25  
26      @Test
27      public void extractNameList() {
28          assertEquals(Arrays.asList(new String[] { "a" }), TeeFilter.extractNameList("a"));
29          assertEquals(Arrays.asList(new String[] { "a", "b" }), TeeFilter.extractNameList("a, b"));
30          assertEquals(Arrays.asList(new String[] { "a", "b" }), TeeFilter.extractNameList("a; b"));
31          assertEquals(Arrays.asList(new String[] { "a", "b", "c" }), TeeFilter.extractNameList("a; b, c"));
32      }
33  
34      @Test
35      public void defaultCase() {
36          assertTrue(TeeFilter.computeActivation("somehost", "", ""));
37          assertTrue(TeeFilter.computeActivation("somehost", null, null));
38      }
39  
40      @Test
41      public void withIncludesOnly() {
42          assertTrue(TeeFilter.computeActivation("a", "a", null));
43          assertTrue(TeeFilter.computeActivation("a", "a, b", null));
44          assertFalse(TeeFilter.computeActivation("a", "b", null));
45          assertFalse(TeeFilter.computeActivation("a", "b, c", null));
46      }
47  
48      @Test
49      public void withExcludesOnly() {
50          assertFalse(TeeFilter.computeActivation("a", null, "a"));
51          assertFalse(TeeFilter.computeActivation("a", null, "a, b"));
52          assertTrue(TeeFilter.computeActivation("a", null, "b"));
53          assertTrue(TeeFilter.computeActivation("a", null, "b, c"));
54      }
55  
56      @Test
57      public void withIncludesAndExcludes() {
58          assertFalse(TeeFilter.computeActivation("a", "a", "a"));
59          assertTrue(TeeFilter.computeActivation("a", "a", "b"));
60          assertFalse(TeeFilter.computeActivation("a", "b", "a"));
61          assertFalse(TeeFilter.computeActivation("a", "b", "b"));
62  
63      }
64  
65  }