From d5de29b76cf9385b1fb2f8c51662000179cb75e0 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 17 Feb 2014 11:05:15 +0000 Subject: [PATCH] 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 --- .../boot/SpringApplicationTests.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 77aa86507e..49b9c5db38 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -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