Search in sources :

Example 91 with MapPropertySource

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;
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 92 with MapPropertySource

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");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 93 with MapPropertySource

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)));
}
Also used : SystemEnvironmentPropertySource(org.springframework.core.env.SystemEnvironmentPropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 94 with MapPropertySource

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);
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) HashMap(java.util.HashMap) Map(java.util.Map)

Example 95 with MapPropertySource

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");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) InvalidConfigurationPropertyValueException(org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)213 HashMap (java.util.HashMap)103 Test (org.junit.jupiter.api.Test)80 MutablePropertySources (org.springframework.core.env.MutablePropertySources)66 Test (org.junit.Test)59 StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 LinkedHashMap (java.util.LinkedHashMap)42 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)30 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 ArrayList (java.util.ArrayList)18 Map (java.util.Map)16 RestTemplate (org.springframework.web.client.RestTemplate)16 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14