From 63de33ef3e121a4a42e8bf627911bef62c280d5f Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 20 Mar 2014 15:41:22 +0000 Subject: [PATCH] Add further test for activating profiles The new test asserts that a profile defined in one profile can be switched off in another. Seems to work. More gh-483 --- .../config/ConfigFileApplicationListenerTests.java | 13 +++++++++++++ .../src/test/resources/enabletwoprofiles.properties | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 spring-boot/src/test/resources/enabletwoprofiles.properties diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 0257b768ea9..0e24edc573a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -110,6 +110,19 @@ public class ConfigFileApplicationListenerTests { assertThat(property, equalTo("fromotherpropertiesfile")); } + @Test + public void loadTwoPropertiesFilesWithProfilesAndSwitchOneOff() throws Exception { + EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:" + + "classpath:enabletwoprofiles.properties," + + "classpath:enableprofile.properties"); + this.initializer.onApplicationEvent(this.event); + assertEquals("myprofile", + StringUtils.arrayToCommaDelimitedString(this.environment + .getActiveProfiles())); + String property = this.environment.getProperty("my.property"); + assertThat(property, equalTo("fromtwopropertiesfile")); + } + @Test public void localFileTakesPrecedenceOverClasspath() throws Exception { File localFile = new File(new File("."), "application.properties"); diff --git a/spring-boot/src/test/resources/enabletwoprofiles.properties b/spring-boot/src/test/resources/enabletwoprofiles.properties new file mode 100644 index 00000000000..90d74d0f417 --- /dev/null +++ b/spring-boot/src/test/resources/enabletwoprofiles.properties @@ -0,0 +1,2 @@ +spring.profiles.active=myprofile,another +my.property=fromtwopropertiesfile