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);
}
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");
}
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");
}
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");
}
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();
}
Aggregations