use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class TestLogMessages method testXmlLayout.
@Test
public void testXmlLayout() {
TestAppender appender = TestAppender.newBuilder().useIbisXmlLayout().useIbisThreadFilter("HIDE-HERE").build();
TestAppender.addToRootLogger(appender);
String threadName = Thread.currentThread().getName();
try {
Thread.currentThread().setName("HIDE-HERE");
log.debug("my beautiful debug <![CDATA[message]]> for me & you --> \"world\"");
log.info("my beautiful info <![CDATA[message]]> for me & you --> \"world\"");
log.warn("my beautiful warning <![CDATA[message]]> for me & you --> \"world\"");
log.error("my beautiful error <![CDATA[message]]> for me & you --> \"world\"");
Thread.currentThread().setName("LOG-ALL");
log.debug("some message");
log.info("some message");
log.warn("some message");
log.error("some message");
List<String> logEvents = appender.getLogLines();
assertEquals(6, logEvents.size());
String expectedWarn = "<event logger=\"nl.nn.adapterframework.logging.TestLogMessages\" timestamp=\"xxx\" level=\"WARN\" thread=\"HIDE-HERE\">\n" + " <message>my beautiful warning <![CDATA[message]]> for me & you --> \\\"world\\\"</message>\n" + "</event>";
String expectedError = "<event logger=\"nl.nn.adapterframework.logging.TestLogMessages\" timestamp=\"xxx\" level=\"ERROR\" thread=\"HIDE-HERE\">\n" + " <message>my beautiful error <![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 {
Thread.currentThread().setName(threadName);
TestAppender.removeAppender(appender);
}
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class TestLogMessages method logLength.
@Test
public void logLength() {
TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).build();
TestAppender.addToRootLogger(appender);
int length = 23;
IbisMaskingLayout.setMaxLength(length);
try {
log.debug(TEST_REGEX_IN);
List<String> logEvents = appender.getLogLines();
assertEquals(1, logEvents.size());
String message = logEvents.get(0);
String expected = "DEBUG - " + TEST_REGEX_IN.substring(0, length).trim() + " ...(" + (TEST_REGEX_IN.length() - length) + " more characters)";
TestAssertions.assertEqualsIgnoreCRLF(expected, message);
} finally {
IbisMaskingLayout.setMaxLength(-1);
TestAppender.removeAppender(appender);
}
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class TestLogMessages method logWithStacktrace.
@Test
public void logWithStacktrace() {
TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).build();
TestAppender.addToRootLogger(appender);
try {
Throwable t = new Throwable("my exception message");
StackTraceElement[] stackTrace = new StackTraceElement[1];
stackTrace[0] = new StackTraceElement(this.getClass().getSimpleName(), "logWithStacktrace", "TestLogMessages", 0);
t.setStackTrace(stackTrace);
log.debug("Oh no, something went wrong!", t);
List<String> logEvents = appender.getLogLines();
assertEquals(1, logEvents.size());
String message = logEvents.get(0);
String expected = "DEBUG - Oh no, something went wrong! java.lang.Throwable: my exception message\n" + " at TestLogMessages.logWithStacktrace(TestLogMessages:0) ~[?:?]";
TestAssertions.assertEqualsIgnoreCRLF(expected, message);
} finally {
TestAppender.removeAppender(appender);
}
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class MigratorTest method testScriptExecutionLogs.
@Test
public void testScriptExecutionLogs() throws Exception {
AppConstants.getInstance().setProperty("liquibase.changeLogFile", "/Migrator/DatabaseChangelog.xml");
TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout("%level - %m").build();
try {
Configurator.reconfigure();
TestAppender.addToRootLogger(appender);
migrator.validate();
// Validate Liquibase logs on INFO level
assertTrue(appender.contains("Successfully acquired change log lock"));
// Capture all loggers (at debug level)
Configurator.setRootLevel(Level.DEBUG);
// Exclude Frank!Framework loggers
Configurator.setLevel("nl.nn", Level.WARN);
// Set all Liquibase loggers to WARN
Configurator.setLevel("liquibase", Level.WARN);
appender.clearLogs();
migrator.update();
String msg = "LiquiBase applied [2] change(s) and added tag [two:Niels Meijer]";
// Validate Liquibase doesn't log
assertFalse("expected message not to be logged but found [" + appender.getLogLines() + "]", appender.contains(msg));
ConfigurationMessageEventListener configurationMessages = configuration.getBean("ConfigurationMessageListener", ConfigurationMessageEventListener.class);
// Validate Liquibase did run
assertTrue(configurationMessages.contains(msg));
} finally {
TestAppender.removeAppender(appender);
Configurator.reconfigure();
}
}
use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.
the class JarFileClassLoaderTest method testMyConfig.
@Test
public void testMyConfig() throws Exception {
TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout("%level - %m").build();
TestAppender.addToRootLogger(appender);
try {
JarFileClassLoader classLoader = createClassLoader(null, "/ClassLoader/zip/myConfig.zip");
appConstants.put("configurations.myConfig.classLoaderType", classLoader.getClass().getSimpleName());
classLoader.configure(ibisContext, "myConfig");
List<String> logEvents = appender.getLogLines();
System.out.println(logEvents);
URL configurationURL = classLoader.getResource("Configuration.xml");
assertNotNull("unable to locate test file [Configuration.xml]", configurationURL);
assertEquals("Should find 8 log messages", 8, logEvents.size());
long warnMsgs = logEvents.stream().filter(k -> k.startsWith("WARN")).count();
assertEquals("Should find one warning message", 1, warnMsgs);
} finally {
TestAppender.removeAppender(appender);
}
}
Aggregations