use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class LoggingSystemPropertiesTests method environment.
private Environment environment(String key, Object value) {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addLast(new MapPropertySource("test", Collections.singletonMap(key, value)));
return environment;
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourceOriginTests method getWhenPropertySourceIsNotOriginAwareShouldWrap.
@Test
void getWhenPropertySourceIsNotOriginAwareShouldWrap() {
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
assertThat(origin.getPropertySource()).isEqualTo(propertySource);
assertThat(origin.getPropertyName()).isEqualTo("foo");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class TestPropertyValues method addToSources.
@SuppressWarnings("unchecked")
private void addToSources(MutablePropertySources sources, Type type, String name) {
if (sources.contains(name)) {
PropertySource<?> propertySource = sources.get(name);
if (propertySource.getClass() == type.getSourceClass()) {
((Map<String, Object>) propertySource.getSource()).putAll(this.properties);
return;
}
}
Map<String, Object> source = new LinkedHashMap<>(this.properties);
sources.addFirst((type.equals(Type.MAP) ? new MapPropertySource(name, source) : new SystemEnvironmentPropertySource(name, source)));
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class ServerPortInfoApplicationContextInitializer method setPortProperty.
@SuppressWarnings("unchecked")
private void setPortProperty(ConfigurableEnvironment environment, String propertyName, int port) {
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get("server.ports");
if (source == null) {
source = new MapPropertySource("server.ports", new HashMap<>());
sources.addFirst(source);
}
((Map<String, Object>) source.getSource()).put(propertyName, port);
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithKnownProperty.
@Test
void analysisWithKnownProperty() {
MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("test.property", "invalid"));
this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
FailureAnalysis analysis = performAnalysis(failure);
assertCommonParts(failure, analysis);
assertThat(analysis.getAction()).contains("Review the value of the property with the provided reason.");
assertThat(analysis.getDescription()).contains("Validation failed for the following reason").contains("This is not valid.").doesNotContain("Additionally, this property is also set");
}
Aggregations