mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Respect spring.profiles.active in #addActiveProfile
Prior to this commit, calls to ConfigurableEnvironment#addActiveProfile would cause any active profile values provided via the "spring.profiles.active" property to be ignored. Now these two mechanisms can be used in conjunction and work as expected. Issue: SPR-9944
This commit is contained in:
+10
@@ -185,6 +185,16 @@ public class StandardEnvironmentTests {
|
||||
assertThat(environment.getActiveProfiles().length, is(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addActiveProfile_whenActiveProfilesPropertyIsAlreadySet() {
|
||||
ConfigurableEnvironment env = new StandardEnvironment();
|
||||
assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), nullValue());
|
||||
env.getPropertySources().addFirst(new MockPropertySource().withProperty(ACTIVE_PROFILES_PROPERTY_NAME, "p1"));
|
||||
assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), equalTo("p1"));
|
||||
env.addActiveProfile("p2");
|
||||
assertThat(env.getActiveProfiles(), arrayContaining("p1", "p2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reservedDefaultProfile() {
|
||||
assertThat(environment.getDefaultProfiles(), equalTo(new String[]{RESERVED_DEFAULT_PROFILE_NAME}));
|
||||
|
||||
Reference in New Issue
Block a user