Search in sources :

Example 11 with TestAppender

use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.

the class TestLogMessages method hidePasswordInLogMessages.

@Test
public void hidePasswordInLogMessages() {
    TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).build();
    TestAppender.addToRootLogger(appender);
    IbisMaskingLayout.addToGlobalReplace("(?<=password=\").+?(?=\")");
    try {
        log.debug(TEST_REGEX_IN);
        List<String> logEvents = appender.getLogLines();
        assertEquals(1, logEvents.size());
        String message = logEvents.get(0);
        assertEquals("DEBUG - " + TEST_REGEX_OUT, message);
    } finally {
        IbisMaskingLayout.cleanGlobalReplace();
        TestAppender.removeAppender(appender);
    }
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) Test(org.junit.Test)

Example 12 with TestAppender

use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.

the class TestLogMessages method dontLogDebugAndInfoLevelsWhenThreadFilterIsActive.

@Test
public void dontLogDebugAndInfoLevelsWhenThreadFilterIsActive() {
    TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).useIbisThreadFilter("HIDE-HERE").build();
    TestAppender.addToRootLogger(appender);
    String threadName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("HIDE-HERE");
        log.debug("my beautiful debug message");
        log.info("my beautiful info message");
        log.warn("my beautiful warning message");
        log.error("my beautiful error message");
        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());
        assertEquals("WARN - my beautiful warning message", logEvents.get(0));
        assertEquals("ERROR - my beautiful error message", logEvents.get(1));
    } finally {
        Thread.currentThread().setName(threadName);
        TestAppender.removeAppender(appender);
    }
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) Test(org.junit.Test)

Example 13 with TestAppender

use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.

the class TestLogMessages method testUnicodeCharactersInMessage.

@Test
public void testUnicodeCharactersInMessage() {
    TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).build();
    TestAppender.addToRootLogger(appender);
    try {
        log.debug("my beautiful unicode debug  aâΔع你好ಡತ  message for me & you --> \\\"world\\\"");
        List<String> logEvents = appender.getLogLines();
        assertEquals(1, logEvents.size());
        String message = logEvents.get(0);
        assertEquals("DEBUG - my beautiful unicode debug  aâΔع你好ಡತ  message for me & you --> \\\"world\\\"", message);
    } finally {
        IbisMaskingLayout.cleanGlobalReplace();
        TestAppender.removeAppender(appender);
    }
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) Test(org.junit.Test)

Example 14 with TestAppender

use of nl.nn.adapterframework.testutil.TestAppender in project iaf by ibissource.

the class TestLogMessages method testCdataInMessage.

@Test
public void testCdataInMessage() {
    TestAppender appender = TestAppender.newBuilder().useIbisPatternLayout(PATTERN).build();
    TestAppender.addToRootLogger(appender);
    try {
        log.debug("my beautiful <![CDATA[debug]]> for me & you --> \"world\"");
        List<String> logEvents = appender.getLogLines();
        assertEquals(1, logEvents.size());
        String message = logEvents.get(0);
        assertEquals("DEBUG - my beautiful <![CDATA[debug]]> for me & you --> \"world\"", message);
    } finally {
        IbisMaskingLayout.cleanGlobalReplace();
        TestAppender.removeAppender(appender);
    }
}
Also used : TestAppender(nl.nn.adapterframework.testutil.TestAppender) Test(org.junit.Test)

Aggregations

TestAppender (nl.nn.adapterframework.testutil.TestAppender)14 Test (org.junit.Test)14 ClassLoaderManager (nl.nn.adapterframework.configuration.ClassLoaderManager)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 URL (java.net.URL)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 ApplicationMessageEvent (nl.nn.adapterframework.lifecycle.ApplicationMessageEvent)1 ConfigurationMessageEventListener (nl.nn.adapterframework.testutil.ConfigurationMessageEventListener)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1