Refactor Environment and PropertySource
* Environment now extends PropertyResolver * Environment no longer exposes resolver and sources * PropertySource is String,Object instead of String,String * PropertySource no longer assumes enumerability of property names * Introduced EnumerablePropertySource for those that do have enumerable property names
This commit is contained in:
@@ -433,18 +433,17 @@ public class EnvironmentIntegrationTests {
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
assertThat(environment, instanceOf(DefaultWebEnvironment.class));
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
PropertyResolver propertyResolver = environment.getPropertyResolver();
|
||||
assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
||||
|
||||
// ServletConfig gets precedence
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
||||
|
||||
// but all params are available
|
||||
assertThat(propertyResolver.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(propertyResolver.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
@@ -457,8 +456,8 @@ public class EnvironmentIntegrationTests {
|
||||
propertySources.replace(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletconfig params resolve with higher precedence than sysprops
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertyResolver.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -474,12 +473,11 @@ public class EnvironmentIntegrationTests {
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
assertThat(environment, instanceOf(DefaultWebEnvironment.class));
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
PropertyResolver propertyResolver = environment.getPropertyResolver();
|
||||
assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
|
||||
// ServletContext params are available
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(propertyResolver.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)),
|
||||
@@ -492,8 +490,8 @@ public class EnvironmentIntegrationTests {
|
||||
propertySources.replace(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletcontext init params resolve with higher precedence than sysprops
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(propertyResolver.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -512,18 +510,17 @@ public class EnvironmentIntegrationTests {
|
||||
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
PropertyResolver propertyResolver = environment.getPropertyResolver();
|
||||
assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
||||
|
||||
// ServletConfig gets precedence
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
||||
|
||||
// but all params are available
|
||||
assertThat(propertyResolver.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(propertyResolver.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.asList().indexOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
@@ -536,8 +533,8 @@ public class EnvironmentIntegrationTests {
|
||||
propertySources.replace(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletconfig params resolve with higher precedence than sysprops
|
||||
assertThat(propertyResolver.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertyResolver.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user