Test case for MDC conversion pattern.
String mdcMsgPattern1 = "%m : %X%n";
String mdcMsgPattern2 = "%m : %X{key1}%n";
String mdcMsgPattern3 = "%m : %X{key2}%n";
String mdcMsgPattern4 = "%m : %X{key3}%n";
String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
// set up appender
PatternLayout layout = new PatternLayout(msgPattern);
Appender appender = new FileAppender(layout, OUTPUT_FILE+"_mdc", false);
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output starting message
root.debug("starting mdc pattern test");
layout.setConversionPattern(mdcMsgPattern1);
root.debug("empty mdc, no key specified in pattern");
layout.setConversionPattern(mdcMsgPattern2);
root.debug("empty mdc, key1 in pattern");
layout.setConversionPattern(mdcMsgPattern3);
root.debug("empty mdc, key2 in pattern");
layout.setConversionPattern(mdcMsgPattern4);
root.debug("empty mdc, key3 in pattern");
layout.setConversionPattern(mdcMsgPattern5);
root.debug("empty mdc, key1, key2, and key3 in pattern");
MDC.put("key1", "value1");
MDC.put("key2", "value2");
layout.setConversionPattern(mdcMsgPattern1);
root.debug("filled mdc, no key specified in pattern");
layout.setConversionPattern(mdcMsgPattern2);
root.debug("filled mdc, key1 in pattern");
layout.setConversionPattern(mdcMsgPattern3);
root.debug("filled mdc, key2 in pattern");
layout.setConversionPattern(mdcMsgPattern4);
root.debug("filled mdc, key3 in pattern");
layout.setConversionPattern(mdcMsgPattern5);
root.debug("filled mdc, key1, key2, and key3 in pattern");
MDC.remove("key1");
MDC.remove("key2");
layout.setConversionPattern(msgPattern);
root.debug("finished mdc pattern test");
assertTrue(Compare.compare(OUTPUT_FILE+"_mdc", WITNESS_FILE+"_mdc"));