XMLLayoutTestCasepublic class XMLLayoutTestCase extends TestCase
Fields Summary |
---|
static String | TEMP | static String | FILTERED | Logger | root | Logger | logger |
Constructors Summary |
---|
public XMLLayoutTestCase(String name)
super(name);
|
Methods Summary |
---|
public void | basic()
XMLLayout xmlLayout = new XMLLayout();
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
common();
Transformer.transform(
TEMP, FILTERED,
new Filter[] {
new LineNumberFilter(),
new XMLTimestampFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter()
});
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.1"));
| void | common()
String oldThreadName = Thread.currentThread().getName();
Thread.currentThread().setName("main");
int i = -1;
new X();
logger.trace("Message " + ++i);
root.trace("Message " + i);
logger.debug("Message " + ++i);
root.debug("Message " + i);
logger.info("Message " + ++i);
root.info("Message " + i);
logger.warn ("Message " + ++i);
root.warn("Message " + i);
logger.error("Message " + ++i);
root.error("Message " + i);
logger.log(Level.FATAL, "Message " + ++i);
root.log(Level.FATAL, "Message " + i);
Exception e = new Exception("Just testing");
logger.debug("Message " + ++i, e);
root.debug("Message " + i, e);
logger.error("Message " + ++i, e);
root.error("Message " + i, e);
Thread.currentThread().setName(oldThreadName);
| public void | locationInfo()
XMLLayout xmlLayout = new XMLLayout();
xmlLayout.setLocationInfo(true);
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
common();
Transformer.transform(
TEMP, FILTERED,
new Filter[] {
new LineNumberFilter(),
new XMLTimestampFilter(),
new XMLLineAttributeFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter()
});
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.2"));
| public void | setUp()
root = Logger.getRootLogger();
root.setLevel(Level.TRACE);
logger = Logger.getLogger(XMLLayoutTestCase.class);
logger.setLevel(Level.TRACE);
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite();
suite.addTest(new XMLLayoutTestCase("basic"));
suite.addTest(new XMLLayoutTestCase("locationInfo"));
suite.addTest(new XMLLayoutTestCase("testCDATA"));
suite.addTest(new XMLLayoutTestCase("testNull"));
suite.addTest(new XMLLayoutTestCase("testMDC"));
suite.addTest(new XMLLayoutTestCase("testMDCEscaped"));
return suite;
| public void | tearDown()
root.getLoggerRepository().resetConfiguration();
| public void | testCDATA()
XMLLayout xmlLayout = new XMLLayout();
xmlLayout.setLocationInfo(true);
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
String oldThreadName = Thread.currentThread().getName();
Thread.currentThread().setName("main");
logger.trace("Message with embedded <![CDATA[<hello>hi</hello>]]>.");
logger.debug("Message with embedded <![CDATA[<hello>hi</hello>]]>.");
Thread.currentThread().setName(oldThreadName);
Transformer.transform(
TEMP, FILTERED,
new Filter[] {
new LineNumberFilter(),
new XMLTimestampFilter(),
new XMLLineAttributeFilter(),
new SunReflectFilter(),
new JunitTestRunnerFilter()
});
Transformer.transform(TEMP, FILTERED, new Filter[] {new LineNumberFilter(),
new XMLTimestampFilter(),
new XMLLineAttributeFilter()});
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.3"));
| public void | testMDC()Tests the format of the MDC portion of the layout to ensure
the key-value pairs we put in turn up in the output file.
XMLLayout xmlLayout = new XMLLayout();
xmlLayout.setProperties(true);
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
Hashtable context = MDC.getContext();
if (context != null) {
context.clear();
}
MDC.put("key1", "val1");
MDC.put("key2", "val2");
logger.debug("Hello");
Transformer.transform(
TEMP, FILTERED,
new Filter[] { new LineNumberFilter(),
new JunitTestRunnerFilter(),
new XMLTimestampFilter()});
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.mdc.1"));
| public void | testMDCEscaped()
XMLLayout xmlLayout = new XMLLayout();
xmlLayout.setProperties(true);
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
Hashtable context = MDC.getContext();
if (context != null) {
context.clear();
}
MDC.put("blahAttribute", "<blah value='blah'>");
MDC.put("<blahKey value='blah'/>", "blahValue");
logger.debug("Hello");
Transformer.transform(
TEMP, FILTERED,
new Filter[] { new LineNumberFilter(),
new JunitTestRunnerFilter(),
new XMLTimestampFilter() });
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.mdc.2"));
| public void | testNull()
XMLLayout xmlLayout = new XMLLayout();
root.addAppender(new FileAppender(xmlLayout, TEMP, false));
String oldThreadName = Thread.currentThread().getName();
Thread.currentThread().setName("main");
logger.debug("hi");
logger.debug(null);
Exception e = new Exception((String) null);
logger.debug("hi", e);
Thread.currentThread().setName(oldThreadName);
Transformer.transform(
TEMP, FILTERED,
new Filter[] { new LineNumberFilter(),
new XMLTimestampFilter(),
new JunitTestRunnerFilter(),
new SunReflectFilter()});
assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.null"));
|
|