|
|
|
@ -22,8 +22,6 @@ import org.junit.Ignore; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
|
|
|
import org.springframework.test.context.ActiveProfiles; |
|
|
|
|
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.springframework.test.context.MergedContextConfiguration; |
|
|
|
import org.springframework.test.context.MergedContextConfiguration; |
|
|
|
import org.springframework.test.context.TestContext; |
|
|
|
import org.springframework.test.context.TestContext; |
|
|
|
@ -91,40 +89,13 @@ public class SpringBootContextLoaderTests { |
|
|
|
assertKey(config, "variables", "foo=FOO\n bar=BAR"); |
|
|
|
assertKey(config, "variables", "foo=FOO\n bar=BAR"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void noActiveProfiles() { |
|
|
|
|
|
|
|
Environment environment = getApplicationEnvironment(SimpleConfig.class); |
|
|
|
|
|
|
|
assertThat(environment.getActiveProfiles()).isEmpty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void multipleActiveProfiles() { |
|
|
|
|
|
|
|
Environment environment = getApplicationEnvironment(MultipleActiveProfiles.class); |
|
|
|
|
|
|
|
assertThat(environment.getActiveProfiles()).containsExactly("profile1", "profile2"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void activeProfileWithComma() { |
|
|
|
|
|
|
|
Environment environment = getApplicationEnvironment(ActiveProfileWithComma.class); |
|
|
|
|
|
|
|
assertThat(environment.getActiveProfiles()).containsExactly("profile1,2"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getEnvironmentProperties(Class<?> testClass) { |
|
|
|
private Map<String, Object> getEnvironmentProperties(Class<?> testClass) { |
|
|
|
TestContext context = getTestContext(testClass); |
|
|
|
TestContext context = new ExposedTestContextManager(testClass).getExposedTestContext(); |
|
|
|
MergedContextConfiguration config = (MergedContextConfiguration) ReflectionTestUtils.getField(context, |
|
|
|
MergedContextConfiguration config = (MergedContextConfiguration) ReflectionTestUtils.getField(context, |
|
|
|
"mergedContextConfiguration"); |
|
|
|
"mergedContextConfiguration"); |
|
|
|
return TestPropertySourceUtils.convertInlinedPropertiesToMap(config.getPropertySourceProperties()); |
|
|
|
return TestPropertySourceUtils.convertInlinedPropertiesToMap(config.getPropertySourceProperties()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Environment getApplicationEnvironment(Class<?> testClass) { |
|
|
|
|
|
|
|
TestContext context = getTestContext(testClass); |
|
|
|
|
|
|
|
return context.getApplicationContext().getEnvironment(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TestContext getTestContext(Class<?> testClass) { |
|
|
|
|
|
|
|
return new ExposedTestContextManager(testClass).getExposedTestContext(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertKey(Map<String, Object> actual, String key, Object value) { |
|
|
|
private void assertKey(Map<String, Object> actual, String key, Object value) { |
|
|
|
assertThat(actual.containsKey(key)).as("Key '" + key + "' not found").isTrue(); |
|
|
|
assertThat(actual.containsKey(key)).as("Key '" + key + "' not found").isTrue(); |
|
|
|
assertThat(actual.get(key)).isEqualTo(value); |
|
|
|
assertThat(actual.get(key)).isEqualTo(value); |
|
|
|
@ -172,20 +143,6 @@ public class SpringBootContextLoaderTests { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SpringBootTest |
|
|
|
|
|
|
|
@ActiveProfiles({ "profile1", "profile2" }) |
|
|
|
|
|
|
|
@ContextConfiguration(classes = Config.class) |
|
|
|
|
|
|
|
static class MultipleActiveProfiles { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SpringBootTest |
|
|
|
|
|
|
|
@ActiveProfiles({ "profile1,2" }) |
|
|
|
|
|
|
|
@ContextConfiguration(classes = Config.class) |
|
|
|
|
|
|
|
static class ActiveProfileWithComma { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class Config { |
|
|
|
static class Config { |
|
|
|
|
|
|
|
|
|
|
|
|