|
|
|
|
@@ -57,12 +57,8 @@ import org.springframework.web.context.support.StandardServletEnvironment;
|
|
|
|
|
import org.springframework.web.context.support.StaticWebApplicationContext;
|
|
|
|
|
import org.springframework.web.context.support.XmlWebApplicationContext;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
import static org.hamcrest.Matchers.lessThan;
|
|
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
|
|
|
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
|
|
|
|
|
import static org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME;
|
|
|
|
|
import static org.springframework.core.env.EnvironmentSystemIntegrationTests.Constants.DERIVED_DEV_BEAN_NAME;
|
|
|
|
|
@@ -137,8 +133,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.setEnvironment(prodEnv);
|
|
|
|
|
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -147,8 +143,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.setEnvironment(prodEnv);
|
|
|
|
|
new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -159,8 +155,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
|
|
|
|
|
scanner.scan("org.springframework.core.env.scan1");
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -170,9 +166,9 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
|
|
|
|
|
scanner.scan("org.springframework.core.env.scan2");
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
assertThat(scanner.getEnvironment(), is((Environment)ctx.getEnvironment()));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(scanner.getEnvironment()).isEqualTo((Environment)ctx.getEnvironment());
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -186,8 +182,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
assertHasEnvironment(ctx, prodEnv);
|
|
|
|
|
assertEnvironmentBeanRegistered(ctx);
|
|
|
|
|
assertEnvironmentAwareInvoked(ctx, prodEnv);
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -199,8 +195,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
assertEnvironmentBeanRegistered(ctx);
|
|
|
|
|
assertHasEnvironment(ctx, prodEnv);
|
|
|
|
|
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -217,8 +213,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
assertEnvironmentBeanRegistered(ctx);
|
|
|
|
|
assertHasEnvironment(ctx, prodEnv);
|
|
|
|
|
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -244,7 +240,7 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.register(ProdConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -257,8 +253,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.register(DevConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -271,8 +267,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.register(DevConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
|
|
|
|
|
assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isTrue();
|
|
|
|
|
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -286,9 +282,9 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertEnvironmentAwareInvoked(ctx, prodEnv);
|
|
|
|
|
assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -300,9 +296,9 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.register(DerivedDevConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
|
|
|
|
|
assertThat("should have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(true));
|
|
|
|
|
assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isTrue();
|
|
|
|
|
assertThat(ctx.containsBean(DERIVED_DEV_BEAN_NAME)).isTrue();
|
|
|
|
|
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -312,9 +308,9 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.register(DerivedDevConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat("should not have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(DERIVED_DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -344,8 +340,7 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.setEnvironment(environment);
|
|
|
|
|
ctx.register(ProfileExpressionConfig.class);
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
assertThat("wrong presence of expression bean",
|
|
|
|
|
ctx.containsBean("expressionBean"), is(expected));
|
|
|
|
|
assertThat(ctx.containsBean("expressionBean")).isEqualTo(expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -370,8 +365,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
assertHasEnvironment(ctx, prodWebEnv);
|
|
|
|
|
assertEnvironmentBeanRegistered(ctx);
|
|
|
|
|
assertEnvironmentAwareInvoked(ctx, prodWebEnv);
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
|
|
|
|
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -434,23 +429,23 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
ConfigurableEnvironment environment = ctx.getEnvironment();
|
|
|
|
|
assertThat(environment, instanceOf(StandardServletEnvironment.class));
|
|
|
|
|
assertThat(environment).isInstanceOf(StandardServletEnvironment.class);
|
|
|
|
|
MutablePropertySources propertySources = environment.getPropertySources();
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)).isTrue();
|
|
|
|
|
|
|
|
|
|
// ServletConfig gets precedence
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
|
|
|
|
lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
|
|
|
|
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)));
|
|
|
|
|
|
|
|
|
|
// but all params are available
|
|
|
|
|
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
|
|
|
|
assertThat(environment.getProperty("pConfig1")).isEqualTo("pConfig1Value");
|
|
|
|
|
|
|
|
|
|
// Servlet* PropertySources have precedence over System* PropertySources
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
|
|
|
|
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
|
|
|
|
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
|
|
|
|
|
|
|
|
|
// Replace system properties with a mock property source for convenience
|
|
|
|
|
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
|
|
|
|
@@ -459,8 +454,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
|
|
|
|
|
|
|
|
|
// assert that servletconfig params resolve with higher precedence than sysprops
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -474,17 +469,17 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
|
|
ConfigurableEnvironment environment = ctx.getEnvironment();
|
|
|
|
|
assertThat(environment, instanceOf(StandardServletEnvironment.class));
|
|
|
|
|
assertThat(environment).isInstanceOf(StandardServletEnvironment.class);
|
|
|
|
|
MutablePropertySources propertySources = environment.getPropertySources();
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
|
|
|
|
|
|
|
|
|
// ServletContext params are available
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
|
|
|
|
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonContextValue");
|
|
|
|
|
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
|
|
|
|
|
|
|
|
|
// Servlet* PropertySources have precedence over System* PropertySources
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)),
|
|
|
|
|
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))
|
|
|
|
|
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
|
|
|
|
|
|
|
|
|
// Replace system properties with a mock property source for convenience
|
|
|
|
|
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
|
|
|
|
@@ -493,8 +488,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
|
|
|
|
|
|
|
|
|
// assert that servletcontext init params resolve with higher precedence than sysprops
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonContextValue");
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -513,21 +508,21 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
|
|
|
|
|
ConfigurableEnvironment environment = ctx.getEnvironment();
|
|
|
|
|
MutablePropertySources propertySources = environment.getPropertySources();
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
|
|
|
|
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)).isTrue();
|
|
|
|
|
|
|
|
|
|
// ServletConfig gets precedence
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
|
|
|
|
lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
|
|
|
|
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)));
|
|
|
|
|
|
|
|
|
|
// but all params are available
|
|
|
|
|
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
|
|
|
|
assertThat(environment.getProperty("pConfig1")).isEqualTo("pConfig1Value");
|
|
|
|
|
|
|
|
|
|
// Servlet* PropertySources have precedence over System* PropertySources
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
|
|
|
|
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
|
|
|
|
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
|
|
|
|
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
|
|
|
|
|
|
|
|
|
// Replace system properties with a mock property source for convenience
|
|
|
|
|
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
|
|
|
|
@@ -536,8 +531,8 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
|
|
|
|
|
|
|
|
|
// assert that servletconfig params resolve with higher precedence than sysprops
|
|
|
|
|
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
|
|
|
|
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
|
|
|
|
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -593,33 +588,33 @@ public class EnvironmentSystemIntegrationTests {
|
|
|
|
|
private void assertEnvironmentBeanRegistered(
|
|
|
|
|
ConfigurableApplicationContext ctx) {
|
|
|
|
|
// ensure environment is registered as a bean
|
|
|
|
|
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertHasStandardEnvironment(ApplicationContext ctx) {
|
|
|
|
|
Environment defaultEnv = ctx.getEnvironment();
|
|
|
|
|
assertThat(defaultEnv, notNullValue());
|
|
|
|
|
assertThat(defaultEnv, instanceOf(StandardEnvironment.class));
|
|
|
|
|
assertThat(defaultEnv).isNotNull();
|
|
|
|
|
assertThat(defaultEnv).isInstanceOf(StandardEnvironment.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertHasStandardServletEnvironment(WebApplicationContext ctx) {
|
|
|
|
|
// ensure a default servlet environment exists
|
|
|
|
|
Environment defaultEnv = ctx.getEnvironment();
|
|
|
|
|
assertThat(defaultEnv, notNullValue());
|
|
|
|
|
assertThat(defaultEnv, instanceOf(StandardServletEnvironment.class));
|
|
|
|
|
assertThat(defaultEnv).isNotNull();
|
|
|
|
|
assertThat(defaultEnv).isInstanceOf(StandardServletEnvironment.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertHasEnvironment(ApplicationContext ctx, Environment expectedEnv) {
|
|
|
|
|
// ensure the custom environment took
|
|
|
|
|
Environment actualEnv = ctx.getEnvironment();
|
|
|
|
|
assertThat(actualEnv, notNullValue());
|
|
|
|
|
assertThat(actualEnv, is(expectedEnv));
|
|
|
|
|
assertThat(actualEnv).isNotNull();
|
|
|
|
|
assertThat(actualEnv).isEqualTo(expectedEnv);
|
|
|
|
|
// ensure environment is registered as a bean
|
|
|
|
|
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
|
|
|
|
|
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME)).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertEnvironmentAwareInvoked(ConfigurableApplicationContext ctx, Environment expectedEnv) {
|
|
|
|
|
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment, is(expectedEnv));
|
|
|
|
|
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment).isEqualTo(expectedEnv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|