use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class SpringProfileDocumentMatcher method extractSpringProfiles.
protected List<String> extractSpringProfiles(Properties properties) {
SpringProperties springProperties = new SpringProperties();
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("profiles", properties));
PropertyValues propertyValues = new PropertySourcesPropertyValues(propertySources);
new RelaxedDataBinder(springProperties, "spring").bind(propertyValues);
List<String> profiles = springProperties.getProfiles();
return profiles;
}
use of org.springframework.core.env.MutablePropertySources in project spring-framework by spring-projects.
the class StandardServletEnvironmentTests method propertySourceOrder.
@Test
public void propertySourceOrder() throws Exception {
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
ConfigurableEnvironment env = new StandardServletEnvironment();
MutablePropertySources sources = env.getPropertySources();
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(sources.size(), is(5));
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfiguration method setPortProperty.
private void setPortProperty(ApplicationContext currentContext, int port) {
if (currentContext instanceof ConfigurableApplicationContext) {
MutablePropertySources sources = ((ConfigurableApplicationContext) currentContext).getEnvironment().getPropertySources();
getMongoPorts(sources).put("local.mongo.port", port);
}
if (currentContext.getParent() != null) {
setPortProperty(currentContext.getParent(), port);
}
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class EnvironmentTestUtils method addEnvironment.
/**
* Add additional (high priority) values to an {@link Environment}. Name-value pairs
* can be specified with colon (":") or equals ("=") separators.
* @param environment the environment to modify
* @param name the property source name
* @param pairs the name:value pairs
*/
public static void addEnvironment(String name, ConfigurableEnvironment environment, String... pairs) {
MutablePropertySources sources = environment.getPropertySources();
Map<String, Object> map = getOrAdd(sources, name);
for (String pair : pairs) {
int index = getSeparatorIndex(pair);
String key = pair.substring(0, index > 0 ? index : pair.length());
String value = index > 0 ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());
}
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class SpringBootTestContextBootstrapper method convertToPropertySources.
private PropertySources convertToPropertySources(String[] properties) {
Map<String, Object> source = TestPropertySourceUtils.convertInlinedPropertiesToMap(properties);
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new MapPropertySource("inline", source));
return sources;
}
Aggregations