package de.bwaldvogel.log4j;

import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class SystemdJournalAppenderTest {

    private static final Logger LOGGER = Logger.getLogger(SystemdJournalAppenderTest.class);

    private static final String APPENDER_NAME = "journaldAppender";

    @BeforeClass
    public static void setUpJournaldAppender() {
        SystemdJournalAppender journaldAppender = new SystemdJournalAppender();
        journaldAppender.setName(APPENDER_NAME);
        journaldAppender.setThreshold(Level.TRACE);
        Logger.getRootLogger().addAppender(journaldAppender);
    }

    @AfterClass
    public static void closeJournaldAppender() {
        Appender appender = Logger.getRootLogger().getAppender(APPENDER_NAME);
        if (appender != null) {
            appender.close();
        }
    }

    @Before
    public void clearMdc() {
        MDC.clear();
    }

    @Test
    public void testMessages() {
        LOGGER.trace("this is a test message with level TRACE");
        LOGGER.debug("this is a test message with level DEBUG");
        LOGGER.info("this is a test message with level INFO");
        LOGGER.warn("this is a test message with level WARN");
        LOGGER.error("this is a test message with level ERROR");
    }

    @Test
    public void testMessageWithMDC() {
        MDC.put("some key1", "some value %d");
        MDC.put("some key2", "some other value with unicode: →←üöß");
        LOGGER.info("this is a test message with a MDC");
    }

    @Test
    public void testMessageWithStacktrace() {
        LOGGER.info("this is a test message with an exception", new RuntimeException("some exception"));
    }

}

@@ -1434,32 +1434,159 @@
 ERROR%22);%0A    %7D%0A%0A
+    @Test%0A    public void testMessageWithUnicode() %7B%0A        LOGGER.info(%22this is a test message with unicode: %E2%86%92%E2%86%90%C3%BC%C3%B6%C3%9F%22);%0A    %7D%0A%0A
     @Test%0A    pu

add unicode test