aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-24 09:45:35 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-24 09:55:30 +0200
commit9753a640f136e17b3f5c14f8c0ad5938532909ec (patch)
tree0d8084e525b9e9d16ac09106183cd2d61f10f69a /server/sonar-server
parentd95b174d0e4aa9384bb82917cf0b12a95aceffb5 (diff)
downloadsonarqube-9753a640f136e17b3f5c14f8c0ad5938532909ec.tar.gz
sonarqube-9753a640f136e17b3f5c14f8c0ad5938532909ec.zip
Add tests to SwitchLogbackAppenderTest
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/SwitchLogbackAppenderTest.java34
1 files changed, 23 insertions, 11 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/SwitchLogbackAppenderTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/SwitchLogbackAppenderTest.java
index d8b27b77168..faaa89a30f3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/SwitchLogbackAppenderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/SwitchLogbackAppenderTest.java
@@ -38,8 +38,8 @@ public class SwitchLogbackAppenderTest {
LoggerContext loggerContext = new LoggerContext();
Logger logger = loggerContext.getLogger(this.getClass().getName());
- ListAppender<ILoggingEvent> console;
- ListAppender<ILoggingEvent> analyisReport;
+ SwitchLogbackAppender switchAppender;
+ ListAppender<ILoggingEvent> console, analyisReports;
protected void configure(URL file) throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
@@ -47,9 +47,9 @@ public class SwitchLogbackAppenderTest {
jc.doConfigure(file);
Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
- SwitchLogbackAppender switchAppender = (SwitchLogbackAppender) root.getAppender("SWITCH");
+ switchAppender = (SwitchLogbackAppender) root.getAppender("SWITCH");
console = (ListAppender<ILoggingEvent>) switchAppender.getAppender("CONSOLE");
- analyisReport = (ListAppender<ILoggingEvent>) switchAppender.getAppender("ANALYSIS_REPORTS");
+ analyisReports = (ListAppender<ILoggingEvent>) switchAppender.getAppender("ANALYSIS_REPORTS");
}
/**
@@ -63,7 +63,7 @@ public class SwitchLogbackAppenderTest {
assertThat(console.list).hasSize(1);
assertThat(console.list.get(0).getMessage()).isEqualTo("hello");
- assertThat(analyisReport.list).isEmpty();
+ assertThat(analyisReports.list).isEmpty();
}
/**
@@ -77,19 +77,19 @@ public class SwitchLogbackAppenderTest {
Thread.currentThread().setName(AnalysisReportTaskLauncher.ANALYSIS_REPORT_THREAD_NAME_PREFIX + "test");
try {
logger.info("hello");
- assertThat(analyisReport.list).hasSize(1);
- assertThat(analyisReport.list.get(0).getMessage()).isEqualTo("hello");
+ assertThat(analyisReports.list).hasSize(1);
+ assertThat(analyisReports.list.get(0).getMessage()).isEqualTo("hello");
assertThat(console.list).isEmpty();
logger.warn("a warning");
- assertThat(analyisReport.list).hasSize(2);
- assertThat(analyisReport.list.get(1).getMessage()).isEqualTo("a warning");
+ assertThat(analyisReports.list).hasSize(2);
+ assertThat(analyisReports.list.get(1).getMessage()).isEqualTo("a warning");
assertThat(console.list).hasSize(1);
assertThat(console.list.get(0).getMessage()).isEqualTo("a warning");
logger.warn("an error");
- assertThat(analyisReport.list).hasSize(3);
- assertThat(analyisReport.list.get(2).getMessage()).isEqualTo("an error");
+ assertThat(analyisReports.list).hasSize(3);
+ assertThat(analyisReports.list.get(2).getMessage()).isEqualTo("an error");
assertThat(console.list).hasSize(2);
assertThat(console.list.get(1).getMessage()).isEqualTo("an error");
@@ -112,4 +112,16 @@ public class SwitchLogbackAppenderTest {
}
assertThat(foundError).isTrue();
}
+
+ @Test
+ public void test_logback_internals() throws Exception {
+ configure(getClass().getResource("SwitchLogbackAppenderTest/valid-switch.xml"));
+
+ assertThat(switchAppender.iteratorForAppenders()).hasSize(2);
+ assertThat(switchAppender.isAttached(console)).isTrue();
+
+ assertThat(switchAppender.detachAppender("CONSOLE")).isTrue();
+ assertThat(switchAppender.detachAppender(analyisReports)).isTrue();
+ switchAppender.detachAndStopAllAppenders();
+ }
}