001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.access.servlet;
015
016import org.junit.Test;
017
018import java.util.Arrays;
019
020import static org.junit.Assert.assertFalse;
021import static org.junit.Assert.assertTrue;
022import static org.junit.Assert.assertEquals;
023
024public class TeeFilterTest {
025
026    @Test
027    public void extractNameList() {
028        assertEquals(Arrays.asList(new String[] { "a" }), TeeFilter.extractNameList("a"));
029        assertEquals(Arrays.asList(new String[] { "a", "b" }), TeeFilter.extractNameList("a, b"));
030        assertEquals(Arrays.asList(new String[] { "a", "b" }), TeeFilter.extractNameList("a; b"));
031        assertEquals(Arrays.asList(new String[] { "a", "b", "c" }), TeeFilter.extractNameList("a; b, c"));
032    }
033
034    @Test
035    public void defaultCase() {
036        assertTrue(TeeFilter.computeActivation("somehost", "", ""));
037        assertTrue(TeeFilter.computeActivation("somehost", null, null));
038    }
039
040    @Test
041    public void withIncludesOnly() {
042        assertTrue(TeeFilter.computeActivation("a", "a", null));
043        assertTrue(TeeFilter.computeActivation("a", "a, b", null));
044        assertFalse(TeeFilter.computeActivation("a", "b", null));
045        assertFalse(TeeFilter.computeActivation("a", "b, c", null));
046    }
047
048    @Test
049    public void withExcludesOnly() {
050        assertFalse(TeeFilter.computeActivation("a", null, "a"));
051        assertFalse(TeeFilter.computeActivation("a", null, "a, b"));
052        assertTrue(TeeFilter.computeActivation("a", null, "b"));
053        assertTrue(TeeFilter.computeActivation("a", null, "b, c"));
054    }
055
056    @Test
057    public void withIncludesAndExcludes() {
058        assertFalse(TeeFilter.computeActivation("a", "a", "a"));
059        assertTrue(TeeFilter.computeActivation("a", "a", "b"));
060        assertFalse(TeeFilter.computeActivation("a", "b", "a"));
061        assertFalse(TeeFilter.computeActivation("a", "b", "b"));
062
063    }
064
065}