Search in sources :

Example 1 with MapPropertySource

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

Example 2 with MapPropertySource

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

Example 3 with MapPropertySource

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

Example 4 with MapPropertySource

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

Example 5 with MapPropertySource

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");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) ArrayList(java.util.ArrayList) PropertyValue(org.springframework.beans.PropertyValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)205 HashMap (java.util.HashMap)96 Test (org.junit.jupiter.api.Test)80 MutablePropertySources (org.springframework.core.env.MutablePropertySources)62 Test (org.junit.Test)57 StandardEnvironment (org.springframework.core.env.StandardEnvironment)49 LinkedHashMap (java.util.LinkedHashMap)42 URI (java.net.URI)24 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)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)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 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13