use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringBootContextLoader method convertToPropertySources.
private PropertySources convertToPropertySources(List<String> properties) {
Map<String, Object> source = TestPropertySourceUtils.convertInlinedPropertiesToMap(properties.toArray(new String[properties.size()]));
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new MapPropertySource("inline", source));
return sources;
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class EnvironmentTestUtilsTests method testConfigHasHigherPrecedence.
@Test
public void testConfigHasHigherPrecedence() {
Map<String, Object> map = new HashMap<>();
map.put("my.foo", "bar");
MapPropertySource source = new MapPropertySource("sample", map);
this.environment.getPropertySources().addFirst(source);
assertThat(this.environment.getProperty("my.foo")).isEqualTo("bar");
EnvironmentTestUtils.addEnvironment(this.environment, "my.foo=bar2");
assertThat(this.environment.getProperty("my.foo")).isEqualTo("bar2");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringApplicationJsonEnvironmentPostProcessor method processJson.
private void processJson(ConfigurableEnvironment environment, String json) {
try {
JsonParser parser = JsonParserFactory.getJsonParser();
Map<String, Object> map = parser.parseMap(json);
if (!map.isEmpty()) {
addJsonPropertySource(environment, new MapPropertySource("spring.application.json", flatten(map)));
}
} catch (Exception ex) {
logger.warn("Cannot parse JSON for spring.application.json: " + json, ex);
}
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testPlaceholdersBindingWithError.
@Test
public void testPlaceholdersBindingWithError() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new MapPropertySource("another", Collections.<String, Object>singletonMap("something", "${nonexistent}")));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getName()).isEqualTo("bar");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testOrderPreserved.
@Test
public void testOrderPreserved() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("one", 1);
map.put("two", 2);
map.put("three", 3);
map.put("four", 4);
map.put("five", 5);
this.propertySources.addFirst(new MapPropertySource("ordered", map));
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
PropertyValue[] values = propertyValues.getPropertyValues();
assertThat(values).hasSize(6);
Collection<String> names = new ArrayList<>();
for (PropertyValue value : values) {
names.add(value.getName());
}
assertThat(names).containsExactly("one", "two", "three", "four", "five", "name");
}
Aggregations