Add test case for profile ordering
The command line profile (or equivalently System property) is not winning right now. Arguably that should be fixed. (Thinking...) Relevant to gh-342
This commit is contained in:
@@ -59,6 +59,7 @@ import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -277,6 +278,29 @@ public class SpringApplicationTests {
|
||||
assertEquals("bucket", environment.getProperty("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addProfiles() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setAdditionalProfiles("foo");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
application.run();
|
||||
assertTrue(environment.acceptsProfiles("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addProfilesOrder() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setAdditionalProfiles("foo");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
application.run("--spring.profiles.active=bar");
|
||||
// Command line arguably should always come last (not the case currently)
|
||||
assertArrayEquals(new String[] { "bar", "foo" }, environment.getActiveProfiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
@@ -284,8 +308,7 @@ public class SpringApplicationTests {
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
application.run();
|
||||
assertFalse(hasPropertySource(environment, PropertySource.class,
|
||||
"commandLineArgs"));
|
||||
assertEquals("bucket", environment.getProperty("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user