use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class DatabaseClassLoaderTest method testExceptionHandlingWARN.
/**
* This test makes sure that when the config can't be found, it only throws a WARN error in the log4j logger
* @throws Exception
*/
@Test
public void testExceptionHandlingWARN() throws Exception {
TestAppender appender = TestAppender.newBuilder().build();
TestAppender.addToRootLogger(appender);
boolean makeSureNoExceptionIsThrown = false;
try {
mockDatabase(true);
appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "WARN");
ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
// Does not throw an exception
ClassLoader config = manager.get(getConfigurationName());
makeSureNoExceptionIsThrown = true;
assertNull(config);
} finally {
TestAppender.removeAppender(appender);
assertTrue(makeSureNoExceptionIsThrown);
}
List<LogEvent> log = appender.getLogEvents();
LogEvent firstLogEntry = log.get(log.size() - 1);
assertEquals(ClassLoaderManager.class.getCanonicalName(), firstLogEntry.getLoggerName());
assertEquals(Level.WARN, firstLogEntry.getLevel());
String msg = firstLogEntry.getMessage().getFormattedMessage();
assertThat(msg, Matchers.startsWith(ERROR_PREFIX));
assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class DatabaseClassLoaderTest method testExceptionHandlingDEBUG.
/**
* This test makes sure that when the config can't be found, it only throws a DEBUG error in the log4j logger
* @throws Exception
*/
@Test
public void testExceptionHandlingDEBUG() throws Exception {
TestAppender appender = TestAppender.newBuilder().build();
TestAppender.addToRootLogger(appender);
boolean makeSureNoExceptionIsThrown = false;
try {
mockDatabase(true);
appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "DEBUG");
ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
// Does not throw an exception
ClassLoader config = manager.get(getConfigurationName());
makeSureNoExceptionIsThrown = true;
assertNull(config);
} finally {
TestAppender.removeAppender(appender);
}
assertTrue(makeSureNoExceptionIsThrown);
List<LogEvent> log = appender.getLogEvents();
LogEvent firstLogEntry = log.get(log.size() - 1);
assertEquals(ClassLoaderManager.class.getCanonicalName(), firstLogEntry.getLoggerName());
assertEquals(Level.DEBUG, firstLogEntry.getLevel());
String msg = firstLogEntry.getMessage().getFormattedMessage();
assertThat(msg, Matchers.startsWith(ERROR_PREFIX));
assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class DatabaseClassLoaderTest method testExceptionHandlingINFO.
/**
* This test makes sure that when the config can't be found, it only throws an INFO error in the log4j logger
* @throws Exception
*/
@Test
public void testExceptionHandlingINFO() throws Exception {
TestAppender appender = TestAppender.newBuilder().build();
TestAppender.addToRootLogger(appender);
boolean makeSureNoExceptionIsThrown = false;
try {
mockDatabase(true);
appConstants.put("configurations." + getConfigurationName() + ".reportLevel", "INFO");
ClassLoaderManager manager = new ClassLoaderManager(ibisContext);
// Does not throw an exception
ClassLoader config = manager.get(getConfigurationName());
makeSureNoExceptionIsThrown = true;
assertNull(config);
} finally {
TestAppender.removeAppender(appender);
}
assertTrue(makeSureNoExceptionIsThrown);
List<LogEvent> log = appender.getLogEvents();
LogEvent firstLogEntry = log.get(log.size() - 1);
assertEquals(ApplicationMessageEvent.class.getCanonicalName(), firstLogEntry.getLoggerName());
assertEquals(Level.INFO, firstLogEntry.getLevel());
String msg = firstLogEntry.getMessage().getFormattedMessage();
// Ignore the log4j prefix
assertThat(msg, StringContains.containsString(ERROR_PREFIX));
assertThat(msg, Matchers.endsWith(ERROR_SUFFIX));
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class TestLogMessages method testXmlLayoutWithUnicodeAndCdata.
@Test
public void testXmlLayoutWithUnicodeAndCdata() {
TestAppender appender = TestAppender.newBuilder().useIbisXmlLayout().build();
TestAppender.addToRootLogger(appender);
try {
log.debug("my beautiful aâΔع你好ಡತ debug <![CDATA[message]]> for me & you --> \"world\"");
log.info("my beautiful aâΔع你好ಡತ info <![CDATA[message]]> for me & you --> \"world\"");
List<String> logEvents = appender.getLogLines();
assertEquals(2, logEvents.size());
String expectedWarn = "<event logger=\"nl.nn.adapterframework.logging.TestLogMessages\" timestamp=\"xxx\" level=\"DEBUG\" thread=\"main\">\n" + " <message>my beautiful \\u0010 a\\u00E2\\u0394\\u0639\\u4F60\\u597D\\u0CA1\\u0CA4 debug <![CDATA[message]]> for me & you --> \\\"world\\\"</message>\n" + "</event>";
String expectedError = "<event logger=\"nl.nn.adapterframework.logging.TestLogMessages\" timestamp=\"xxx\" level=\"INFO\" thread=\"main\">\n" + " <message>my beautiful \\u0010 a\\u00E2\\u0394\\u0639\\u4F60\\u597D\\u0CA1\\u0CA4 info <![CDATA[message]]> for me & you --> \\\"world\\\"</message>\n" + "</event>";
// Remove the timestamp
String actualWarn = logEvents.get(0).replaceAll("(?<=timestamp=\").+?(?=\")", "xxx");
String actualError = logEvents.get(1).replaceAll("(?<=timestamp=\").+?(?=\")", "xxx");
TestAssertions.assertEqualsIgnoreCRLF(expectedWarn, actualWarn);
TestAssertions.assertEqualsIgnoreCRLF(expectedError, actualError);
} finally {
TestAppender.removeAppender(appender);
}
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class TestLogMessages method testChangeLogLevel.
@Test
public void testChangeLogLevel() {
TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout("%level - %m").build();
TestAppender.addToRootLogger(appender);
// For tests we use the `nl.nn` logger instead of the rootlogger
String rootLoggerName = LogUtil.getLogger(this).getName();
try {
Configurator.setLevel(rootLoggerName, Level.DEBUG);
log.debug("debug");
Configurator.setLevel(rootLoggerName, Level.INFO);
log.debug("debug");
log.info("info");
Configurator.setLevel(rootLoggerName, Level.WARN);
log.debug("debug");
log.info("info");
log.warn("warn");
Configurator.setLevel(rootLoggerName, Level.ERROR);
log.debug("debug");
log.info("info");
log.warn("warn");
log.error("error");
assertEquals(4, appender.getNumberOfAlerts());
} finally {
TestAppender.removeAppender(appender);
Configurator.setLevel(rootLoggerName, Level.DEBUG);
}
}
Aggregations