diff options
Diffstat (limited to 'server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java')
-rw-r--r-- | server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java index 87944620241..dde89d32d45 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java @@ -21,17 +21,38 @@ package org.sonar.search; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.encoder.PatternLayoutEncoder; +import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.Appender; -import ch.qos.logback.core.ConsoleAppender; +import ch.qos.logback.core.FileAppender; +import java.io.File; +import java.io.IOException; +import java.util.Properties; import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.sonar.process.LogbackHelper; +import org.sonar.process.ProcessProperties; +import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; public class SearchLoggingTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); - SearchLogging underTest = new SearchLogging(); + private File logDir; + + private Props props = new Props(new Properties()); + private SearchLogging underTest = new SearchLogging(); + + @Before + public void setUp() throws IOException { + logDir = temp.newFolder(); + props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath()); + } @AfterClass public static void resetLogback() throws Exception { @@ -39,11 +60,25 @@ public class SearchLoggingTest { } @Test - public void log_to_console() { - LoggerContext ctx = underTest.configure(); + public void do_not_log_to_console() { + LoggerContext ctx = underTest.configure(props); Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME); Appender appender = root.getAppender("CONSOLE"); - assertThat(appender).isInstanceOf(ConsoleAppender.class); + assertThat(appender).isNull(); + } + + @Test + public void log_to_es_file() { + LoggerContext ctx = underTest.configure(props); + + Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME); + Appender<ILoggingEvent> appender = root.getAppender("file"); + assertThat(appender).isInstanceOf(FileAppender.class); + FileAppender fileAppender = (FileAppender) appender; + assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.log").getAbsolutePath()); + assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class); + PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder(); + assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level [][%logger{20}] %msg%n"); } } |