-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
logback-classic/src/test/java/ch/qos/logback/classic/turbo/MDCFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2015, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.turbo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
import org.slf4j.MDC; | ||
|
||
import ch.qos.logback.core.spi.FilterReply; | ||
|
||
public class MDCFilterTest { | ||
|
||
private static String KEY = "myKey"; | ||
|
||
private MDCFilter filter; | ||
|
||
@Before | ||
public void init() { | ||
filter = new MDCFilter(); | ||
filter.setOnMatch("ACCEPT"); | ||
filter.setOnMismatch("DENY"); | ||
filter.setMDCKey(KEY); | ||
filter.start(); | ||
MDC.clear(); | ||
} | ||
|
||
@Test | ||
public void testNoValue() { | ||
filter.setMDCKey(null); | ||
MDC.remove(KEY); | ||
assertEquals(FilterReply.NEUTRAL, filter.decide(null, null, null, null, null, null)); | ||
MDC.put(KEY, "key"); | ||
assertEquals(FilterReply.NEUTRAL, filter.decide(null, null, null, null, null, null)); | ||
} | ||
|
||
@Test | ||
public void testNoMdcValue() { | ||
MDC.remove(KEY); | ||
assertEquals(FilterReply.ACCEPT, filter.decide(null, null, null, null, null, null)); | ||
} | ||
|
||
@Test | ||
public void testMdcValue() { | ||
MDC.put(KEY, "myKey"); | ||
assertEquals(FilterReply.DENY, filter.decide(null, null, null, null, null, null)); | ||
} | ||
|
||
@Test | ||
public void testMdcAndValue() { | ||
filter.setValue("correct"); | ||
MDC.put(KEY, "wrong"); | ||
assertEquals(FilterReply.DENY, filter.decide(null, null, null, null, null, null)); | ||
MDC.put(KEY, "correct"); | ||
assertEquals(FilterReply.ACCEPT, filter.decide(null, null, null, null, null, null)); | ||
} | ||
} | ||
|