Commit 9db55a3b authored by Dave Syer's avatar Dave Syer

Add explicit test for config file and SpringApplication

parent 131cfd61
......@@ -32,7 +32,6 @@ public class SampleSpringXmlApplication implements CommandLineRunner {
}
public static void main(String[] args) throws Exception {
// TODO: to make this a pure XML example, will need <boot:auto-configure/>
SpringApplication.run("classpath:/META-INF/application-context.xml", args);
}
}
......@@ -19,6 +19,8 @@ package org.springframework.boot.config;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
......@@ -31,6 +33,8 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
*/
public class PropertiesPropertySourceLoader implements PropertySourceLoader {
private static Log logger = LogFactory.getLog(PropertiesPropertySourceLoader.class);
@Override
public boolean supports(Resource resource) {
return resource.getFilename().endsWith(".properties");
......@@ -40,6 +44,11 @@ public class PropertiesPropertySourceLoader implements PropertySourceLoader {
public PropertySource<?> load(Resource resource) {
try {
Properties properties = loadProperties(resource);
// N.B. this is off by default unless user has supplied logback config in
// standard location
if (logger.isDebugEnabled()) {
logger.debug("Properties loaded from " + resource + ": " + properties);
}
return new PropertiesPropertySource(resource.getDescription(), properties);
}
catch (IOException ex) {
......
......@@ -59,7 +59,8 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
}
public LogbackLoggingSystem(ClassLoader classLoader) {
super(classLoader, "logback.xml");
super(classLoader, "logback-test.groovy", "logback-test.xml", "logback.groovy",
"logback.xml");
}
@Override
......
......@@ -273,6 +273,16 @@ public class SpringApplicationTests {
assertEquals("bar", environment.getProperty("foo"));
}
@Test
public void proprtiesFileEnhancesEnvironment() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebEnvironment(false);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
application.run();
assertEquals("bucket", environment.getProperty("foo"));
}
@Test
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
......@@ -404,8 +414,6 @@ public class SpringApplicationTests {
// FIXME test initializers
// FIXME test config files?
public static class SpyApplicationContext extends AnnotationConfigApplicationContext {
ConfigurableApplicationContext applicationContext = spy(new AnnotationConfigApplicationContext());
......
......@@ -153,7 +153,7 @@ public class LoggingApplicationContextInitializerTests {
@Test
public void parseArgsDisabled() throws Exception {
this.initializer.setParseArgs(false);
this.initializer.initialize(this.springApplication, new String[] { "--debug" });
TestUtils.addEnviroment(this.context, "debug");
this.initializer.initialize(this.context);
this.logger.debug("testatdebug");
assertThat(this.outputCapture.toString(), not(containsString("testatdebug")));
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] spring - ${PID:-????} %5p [%t] --- %c{1}: %m%n"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-/tmp/logs/service.log}}"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="org.springframework.boot.context.annotation" level="TRACE" />
<logger name="org.springframework.boot.context.initializer" level="TRACE" />
<logger name="org.springframework.boot.config" level="TRACE" />
<logger name="org.thymeleaf" level="TRACE" />
<root level="INFO">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment