Skip to content

Commit

Permalink
Added classpath tests to MissingConfigurationTest (issue qos-ch#39).
Browse files Browse the repository at this point in the history
  • Loading branch information
jgibson committed Feb 16, 2016
1 parent 4592889 commit 2941026
Showing 1 changed file with 35 additions and 1 deletion.
Expand Up @@ -80,7 +80,7 @@ public void cleanupLogging() {
}

@Test(timeout = 1000L)
public void testMissingConfiguration() throws Exception {
public void testMissingFileConfiguration() throws Exception {
MockServletContext context = new MockServletContext();
File missingConfig = null;
do {
Expand All @@ -92,6 +92,13 @@ public void testMissingConfiguration() throws Exception {
WebLogbackConfigurer.initLogging(context);
}

@Test
public void testMissingClasspathConfiguration() throws Exception {
MockServletContext context = new MockServletContext();
context.addInitParameter(CONFIG_LOCATION_PARAM, "classpath:ch/qos/logback/ext/spring/does/not/exist/" + rng.nextInt() + ".xml");
WebLogbackConfigurer.initLogging(context);
}

@Test
public void testInvalidConfiguration() throws Exception {
MockServletContext context = new MockServletContext();
Expand Down Expand Up @@ -132,6 +139,33 @@ public void testMissingFollowedByNormalConfiguration() throws Exception {
assertTrue("Logging event was not found: " + logs, found);
}

@Test(timeout = 1000L)
public void testMissingFollowedByNormalClasspathConfiguration() throws Exception {
MockServletContext context = new MockServletContext();
File missingConfig = null;
do {
missingConfig = new File("missingConfigTest" + rng.nextInt() + ".xml");
} while (missingConfig.exists());

context.addInitParameter(CONFIG_LOCATION_PARAM, missingConfig.toURI().toURL().toString() + "," +
"classpath:ch/qos/logback/ext/spring/fakeLogger.xml");
WebLogbackConfigurer.initLogging(context);
Logger log = LoggerFactory.getLogger(MissingConfigurationTest.class);
String key = "missingConfig" + rng.nextInt();
log.error(key);
boolean found = false;
ArrayList<ILoggingEvent> logs;
synchronized (FakeAppender.class) {
logs = new ArrayList<ILoggingEvent>(FakeAppender.logs);
}
for (ILoggingEvent evt : logs) {
if (key.equals(evt.getMessage())) {
found = true;
}
}
assertTrue("Logging event was not found: " + logs, found);
}

public static class FakeAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
private static final ArrayList<ILoggingEvent> logs = new ArrayList<ILoggingEvent>();

Expand Down

0 comments on commit 2941026

Please sign in to comment.