use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class XmlLoggerPropsTest method testWithProps.
@Test
public void testWithProps() {
final ListAppender listAppender = context.getListAppender("List");
assertNotNull("No List Appender", listAppender);
try {
assertThat(context.getConfiguration(), is(instanceOf(XmlConfiguration.class)));
Logger logger = LogManager.getLogger(XmlLoggerPropsTest.class);
logger.debug("Test with props");
logger = LogManager.getLogger("tiny.bubbles");
logger.debug("Test on root");
final List<String> events = listAppender.getMessages();
assertTrue("No events", events.size() > 0);
assertTrue("Incorrect number of events", events.size() == 2);
assertThat(events.get(0), allOf(containsString("user="), containsString("phrasex=****"), containsString("test=test"), containsString("test2=test2default"), containsString("test3=Unknown"), containsString("test4=test"), containsString("test5=test"), containsString("attribKey=attribValue"), containsString("duplicateKey=nodeValue")));
assertThat(events.get(1), allOf(containsString("user="), containsString("phrasex=****"), containsString("test=test"), containsString("test2=test2default"), containsString("test3=Unknown"), containsString("test4=test"), containsString("test5=test"), containsString("attribKey=attribValue"), containsString("duplicateKey=nodeValue")));
} finally {
System.clearProperty("test");
}
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class LoggingTest method verify.
private void verify(final String expected) {
final ListAppender listApp = ListAppender.getListAppender("List");
assertNotNull("Missing Appender", listApp);
final List<String> events = listApp.getMessages();
assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size() == 1);
final String actual = events.get(0);
assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
listApp.clear();
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class CallerInformationTest method testClassLogger.
@Test
public void testClassLogger() throws Exception {
final ListAppender app = ctx.getListAppender("Class").clear();
final Logger logger = Logger.getLogger("ClassLogger");
logger.info("Ignored message contents.");
logger.warning("Verifying the caller class is still correct.");
logger.severe("Hopefully nobody breaks me!");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 3, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
}
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class CallerInformationTest method testMethodLogger.
@Test
public void testMethodLogger() throws Exception {
final ListAppender app = ctx.getListAppender("Method").clear();
final Logger logger = Logger.getLogger("MethodLogger");
logger.info("More messages.");
logger.warning("CATASTROPHE INCOMING!");
logger.severe("ZOMBIES!!!");
logger.warning("brains~~~");
logger.info("Itchy. Tasty.");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 5, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller method name.", "testMethodLogger", message);
}
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class CallerInformationTest method testClassLogger.
@Test
public void testClassLogger() throws Exception {
final ListAppender app = ctx.getListAppender("Class").clear();
final Log logger = LogFactory.getLog("ClassLogger");
logger.info("Ignored message contents.");
logger.warn("Verifying the caller class is still correct.");
logger.error("Hopefully nobody breaks me!");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 3, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
}
}
Aggregations