diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-24 16:10:14 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-06-24 16:10:28 +0200 |
commit | 86bec73a9c8db5c695042b83d54b06fe2ce9de6d (patch) | |
tree | 3964f5b9d79222e785e22359b56dc075ba220c99 /sonar-batch | |
parent | 1385dd342df0ce5fc41872979731ecdeefc76dfb (diff) | |
download | sonarqube-86bec73a9c8db5c695042b83d54b06fe2ce9de6d.tar.gz sonarqube-86bec73a9c8db5c695042b83d54b06fe2ce9de6d.zip |
Fix Quality flaws in batch
Diffstat (limited to 'sonar-batch')
3 files changed, 58 insertions, 10 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PersistentCacheProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PersistentCacheProviderTest.java index 24bdf6047d5..813c5efce70 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PersistentCacheProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PersistentCacheProviderTest.java @@ -55,4 +55,9 @@ public class PersistentCacheProviderTest { provider = new PersistentCacheProvider(); assertThat(provider.provide(props).isForceUpdate()).isFalse(); } + + @Test + public void test_reconfigure() { + + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java index ea1fd3a470e..b01b214e345 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java @@ -24,6 +24,8 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.reset; + import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; import org.junit.Test; @@ -39,21 +41,32 @@ public class LogCallbackAppenderTest { public void setUp() { listener = mock(LogListener.class); appender = new LogCallbackAppender(listener); - event = mock(ILoggingEvent.class); - when(event.getMessage()).thenReturn("test"); - when(event.getLevel()).thenReturn(Level.INFO); } + @Test - public void testAppendLog() { - + public void testLevelTranslation() { + testMessage("test", Level.INFO, LogListener.Level.INFO); + testMessage("test", Level.DEBUG, LogListener.Level.DEBUG); + testMessage("test", Level.ERROR, LogListener.Level.ERROR); + testMessage("test", Level.TRACE, LogListener.Level.TRACE); + testMessage("test", Level.WARN, LogListener.Level.WARN); + + // this should never happen + testMessage("test", Level.OFF, LogListener.Level.DEBUG); + } + + private void testMessage(String msg, Level level, LogListener.Level translatedLevel) { + reset(listener); + event = mock(ILoggingEvent.class); + when(event.getMessage()).thenReturn(msg); + when(event.getLevel()).thenReturn(level); + appender.append(event); verify(event).getMessage(); verify(event).getLevel(); - - verify(listener).log("test", LogListener.Level.INFO); - + verify(listener).log(msg, translatedLevel); verifyNoMoreInteractions(event, listener); } @@ -61,6 +74,6 @@ public class LogCallbackAppenderTest { public void testChangeTarget() { listener = mock(LogListener.class); appender.setTarget(listener); - testAppendLog(); + testLevelTranslation(); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java index 2f7311a39de..5e139684e19 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java @@ -19,12 +19,20 @@ */ package org.sonar.batch.bootstrapper; +import org.apache.commons.io.IOUtils; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; import org.sonar.home.log.LogListener; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; @@ -34,10 +42,13 @@ import org.junit.Test; import org.junit.Before; public class LoggingConfiguratorTest { + private static final String DEFAULT_CLASSPATH_CONF = "/org/sonar/batch/bootstrapper/logback.xml"; private static final String TEST_STR = "foo"; private LoggingConfiguration conf = new LoggingConfiguration(); private ByteArrayOutputStream out; private SimpleLogListener listener; + @Rule + public TemporaryFolder folder = new TemporaryFolder(); @Before public void setUp() { @@ -56,6 +67,25 @@ public class LoggingConfiguratorTest { this.level = level; } } + + @Test + public void testWithFile() throws FileNotFoundException, IOException { + InputStream is = this.getClass().getResourceAsStream(DEFAULT_CLASSPATH_CONF); + File tmpFolder = folder.getRoot(); + File testFile = new File(tmpFolder, "test"); + OutputStream os = new FileOutputStream(testFile); + IOUtils.copy(is, os); + os.close(); + + conf.setListener(listener); + LoggingConfigurator.apply(conf, testFile); + + Logger logger = LoggerFactory.getLogger(this.getClass()); + logger.info(TEST_STR); + + assertThat(listener.msg).endsWith(TEST_STR); + assertThat(listener.level).isEqualTo(LogListener.Level.INFO); + } @Test public void testCustomAppender() throws UnsupportedEncodingException { |