Tidy up log tests

Bamboo doesn't seem to be causing issues now, so assume
[Fixes #52871199] [bs-176] -Djava.util.logging.config.file
is passed to log4j as a file name?
This commit is contained in:
Dave Syer
2013-11-06 13:53:16 +00:00
parent 5aba3272c2
commit 7cf98d15f2
2 changed files with 10 additions and 48 deletions

View File

@@ -36,7 +36,7 @@ public abstract class TestUtils {
int index = pair.indexOf(":");
String key = pair.substring(0, index > 0 ? index : pair.length());
String value = index > 0 ? pair.substring(index + 1) : "";
map.put(key, value);
map.put(key.trim(), value.trim());
}
context.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("test", map));

View File

@@ -29,10 +29,10 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.OutputCapture;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.TestUtils;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.java.JavaLoggingSystem;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.PropertySource;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
@@ -90,16 +90,8 @@ public class LoggingApplicationContextInitializerTests {
@Test
public void testOverrideConfigLocation() {
this.context.getEnvironment().getPropertySources()
.addFirst(new PropertySource<String>("manual") {
@Override
public Object getProperty(String name) {
if ("logging.config".equals(name)) {
return "classpath:logback-nondefault.xml";
}
return null;
}
});
TestUtils.addEnviroment(this.context,
"logging.config: classpath:logback-nondefault.xml");
this.initializer.initialize(this.context);
this.logger.info("Hello world");
String output = this.outputCapture.toString().trim();
@@ -110,35 +102,16 @@ public class LoggingApplicationContextInitializerTests {
@Test
public void testOverrideConfigDoesNotExist() throws Exception {
this.context.getEnvironment().getPropertySources()
.addFirst(new PropertySource<String>("manual") {
@Override
public Object getProperty(String name) {
if ("logging.config".equals(name)) {
return "doesnotexist.xml";
}
return null;
}
});
TestUtils.addEnviroment(this.context, "logging.config: doesnotexist.xml");
this.initializer.initialize(this.context);
// Should not throw
}
@Test
public void testAddLogFileProperty() {
this.context.getEnvironment().getPropertySources()
.addFirst(new PropertySource<String>("manual") {
@Override
public Object getProperty(String name) {
if ("logging.config".equals(name)) {
return "classpath:logback-nondefault.xml";
}
if ("logging.file".equals(name)) {
return "foo.log";
}
return null;
}
});
TestUtils.addEnviroment(this.context,
"logging.config: classpath:logback-nondefault.xml",
"logging.file: foo.log");
this.initializer.initialize(this.context);
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
logger.info("Hello world");
@@ -148,19 +121,8 @@ public class LoggingApplicationContextInitializerTests {
@Test
public void testAddLogPathProperty() {
this.context.getEnvironment().getPropertySources()
.addFirst(new PropertySource<String>("manual") {
@Override
public Object getProperty(String name) {
if ("logging.config".equals(name)) {
return "classpath:logback-nondefault.xml";
}
if ("logging.path".equals(name)) {
return "foo/";
}
return null;
}
});
TestUtils.addEnviroment(this.context,
"logging.config: classpath:logback-nondefault.xml", "logging.path: foo/");
this.initializer.initialize(this.context);
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
logger.info("Hello world");