[logback-dev] [Bug 36] add filter for simple filtering on level

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Thu Jan 4 07:09:57 CET 2007


http://bugzilla.qos.ch/show_bug.cgi?id=36





------- Comment #2 from sdavids at gmx.de  2007-01-04 07:09 -------
/*******************************************************************************
 * Copyright (c) 2007 Sebastian Davids.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors:
 *     Sebastian Davids - initial API and implementation

*******************************************************************************/
package name.davids.sebastian.logback.filter;

import junit.framework.TestCase;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.spi.FilterReply;

/**
 * Test for {@link LevelFilter}.
 * 
 * @author Sebastian Davids, <a
href="mailto:sebastian at davids.name">sebastian at davids.name</a>
 */
public class LevelFilterTest extends TestCase {

    public void testDecideNull() {
        levelFilter.start();
        assertEquals(FilterReply.NEUTRAL, levelFilter.decide(null));
    }

    public void testDecideString() {
        levelFilter.start();
        assertEquals(FilterReply.NEUTRAL, levelFilter.decide(""));
    }

    public void testDecideNotStarted() {
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createDebugEvent()));
    }

    public void testDecideDefaultLevel() {
        levelFilter.start();
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createDebugEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createInfoEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createWarnEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createErrorEvent()));
    }

    public void testDecideDebugLevel() {
        levelFilter.setLevel("DEBUG"); //$NON-NLS-1$
        levelFilter.start();
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createDebugEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createInfoEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createWarnEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createErrorEvent()));
    }

    public void testDecideInfoLevel() {
        levelFilter.setLevel("INFO"); //$NON-NLS-1$
        levelFilter.start();
        assertEquals(FilterReply.DENY, levelFilter.decide(createDebugEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createInfoEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createWarnEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createErrorEvent()));
    }

    public void testDecideWarnLevel() {
        levelFilter.setLevel("WARN"); //$NON-NLS-1$
        levelFilter.start();
        assertEquals(FilterReply.DENY, levelFilter.decide(createDebugEvent()));
        assertEquals(FilterReply.DENY, levelFilter.decide(createInfoEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createWarnEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createErrorEvent()));
    }

    public void testDecideErrorLevel() {
        levelFilter.setLevel("ERROR"); //$NON-NLS-1$
        levelFilter.start();
        assertEquals(FilterReply.DENY, levelFilter.decide(createDebugEvent()));
        assertEquals(FilterReply.DENY, levelFilter.decide(createInfoEvent()));
        assertEquals(FilterReply.DENY, levelFilter.decide(createWarnEvent()));
        assertEquals(FilterReply.NEUTRAL,
levelFilter.decide(createErrorEvent()));
    }

    private LevelFilter levelFilter;

    /** {@inheritDoc} */
    @Override
    protected void setUp() throws Exception {
        levelFilter = new LevelFilter();
    }

    private LoggingEvent createDebugEvent() {
        LoggingEvent event = new LoggingEvent();
        event.setLevel(Level.DEBUG);
        return event;
    }

    private LoggingEvent createErrorEvent() {
        LoggingEvent event = new LoggingEvent();
        event.setLevel(Level.ERROR);
        return event;
    }

    private LoggingEvent createInfoEvent() {
        LoggingEvent event = new LoggingEvent();
        event.setLevel(Level.INFO);
        return event;
    }

    private LoggingEvent createWarnEvent() {
        LoggingEvent event = new LoggingEvent();
        event.setLevel(Level.WARN);
        return event;
    }
}


-- 
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the logback-dev mailing list