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");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method init.
@Before
public void init() {
this.propertySources.addFirst(new PropertySource<String>("static", "foo") {
@Override
public Object getProperty(String name) {
if (name.equals(getSource())) {
return "bar";
}
return null;
}
});
this.propertySources.addFirst(new MapPropertySource("map", Collections.<String, Object>singletonMap("name", "${foo}")));
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class RelaxedPropertyResolverTests method setup.
@Before
public void setup() {
this.environment = new StandardEnvironment();
this.source = new LinkedHashMap<>();
this.source.put("myString", "value");
this.source.put("myobject", "object");
this.source.put("myInteger", 123);
this.source.put("myClass", "java.lang.String");
this.environment.getPropertySources().addFirst(new MapPropertySource("test", this.source));
this.resolver = new RelaxedPropertyResolver(this.environment);
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method addBeforeDefaultProperties.
@Test
public void addBeforeDefaultProperties() throws Exception {
MapPropertySource defaultSource = new MapPropertySource("defaultProperties", Collections.<String, Object>singletonMap("the.property", "fromdefaultproperties"));
this.environment.getPropertySources().addFirst(defaultSource);
this.initializer.setSearchNames("testproperties");
this.initializer.postProcessEnvironment(this.environment, this.application);
String property = this.environment.getProperty("the.property");
assertThat(property).isEqualTo("frompropertiesfile");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method defaultPropertyAsFallback.
@Test
public void defaultPropertyAsFallback() throws Exception {
this.environment.getPropertySources().addLast(new MapPropertySource("defaultProperties", Collections.singletonMap("my.fallback", (Object) "foo")));
this.initializer.postProcessEnvironment(this.environment, this.application);
String property = this.environment.getProperty("my.fallback");
assertThat(property).isEqualTo("foo");
}
Aggregations