Search in sources :

Example 61 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testTypesPreserved.

@Test
public void testTypesPreserved() {
    Map<String, Object> map = Collections.<String, Object>singletonMap("name", 123);
    this.propertySources.replace("map", new MapPropertySource("map", map));
    PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
    assertThat(propertyValues.getPropertyValues()[0].getValue()).isEqualTo(123);
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 62 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testCollectionProperty.

@Test
public void testCollectionProperty() throws Exception {
    ListBean target = new ListBean();
    DataBinder binder = new DataBinder(target);
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("list[0]", "v0");
    map.put("list[1]", "v1");
    this.propertySources.addFirst(new MapPropertySource("values", map));
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertThat(target.getList()).containsExactly("v0", "v1");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) DataBinder(org.springframework.validation.DataBinder) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 63 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class PropertiesConfigurationFactoryMapTests method testBindFromPropertySource.

@Test
public void testBindFromPropertySource() throws Exception {
    this.targetName = "foo";
    setupFactory();
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new MapPropertySource("map", Collections.singletonMap("foo.map.name", (Object) "blah")));
    this.factory.setPropertySources(sources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.map.get("name")).isEqualTo("blah");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 64 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class PropertiesConfigurationFactoryMapTests method testBindFromCompositePropertySource.

@Test
public void testBindFromCompositePropertySource() throws Exception {
    this.targetName = "foo";
    setupFactory();
    MutablePropertySources sources = new MutablePropertySources();
    CompositePropertySource composite = new CompositePropertySource("composite");
    composite.addPropertySource(new MapPropertySource("map", Collections.singletonMap("foo.map.name", (Object) "blah")));
    sources.addFirst(composite);
    this.factory.setPropertySources(sources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.map.get("name")).isEqualTo("blah");
}
Also used : CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 65 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfiguration method getLdapPorts.

@SuppressWarnings("unchecked")
private Map<String, Object> getLdapPorts(MutablePropertySources sources) {
    PropertySource<?> propertySource = sources.get(PROPERTY_SOURCE_NAME);
    if (propertySource == null) {
        propertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<String, Object>());
        sources.addFirst(propertySource);
    }
    return (Map<String, Object>) propertySource.getSource();
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)74 Test (org.junit.Test)53 HashMap (java.util.HashMap)36 StandardEnvironment (org.springframework.core.env.StandardEnvironment)27 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)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 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 MutablePropertySources (org.springframework.core.env.MutablePropertySources)11 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 ArrayList (java.util.ArrayList)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9