use of org.springframework.core.env.MapPropertySource in project dubbo by alibaba.
the class PropertySourcesUtilsTest method testGetSubProperties.
@Test
public void testGetSubProperties() {
MutablePropertySources propertySources = new MutablePropertySources();
Map<String, Object> source = new HashMap<String, Object>();
MapPropertySource propertySource = new MapPropertySource("test", source);
propertySources.addFirst(propertySource);
String KEY_PREFIX = "user";
String KEY_NAME = "name";
String KEY_AGE = "age";
Map<String, String> result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX);
Assert.assertEquals(Collections.emptyMap(), result);
source.put(KEY_PREFIX + "." + KEY_NAME, "Mercy");
source.put(KEY_PREFIX + "." + KEY_AGE, 31);
Map<String, Object> expected = new HashMap<String, Object>();
expected.put(KEY_NAME, "Mercy");
expected.put(KEY_AGE, "31");
result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX);
Assert.assertEquals(expected, result);
result = PropertySourcesUtils.getSubProperties(propertySources, "");
Assert.assertEquals(Collections.emptyMap(), result);
result = PropertySourcesUtils.getSubProperties(propertySources, "no-exists");
Assert.assertEquals(Collections.emptyMap(), result);
}
use of org.springframework.core.env.MapPropertySource in project spring-framework by spring-projects.
the class PropertySourceAnnotationTests method orderingDoesntReplaceExisting.
@Test
public void orderingDoesntReplaceExisting() throws Exception {
// SPR-12198: mySource should 'win' as it was registered manually
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext();
MapPropertySource mySource = new MapPropertySource("mine", Collections.singletonMap("testbean.name", "myTestBean"));
ctxWithoutName.getEnvironment().getPropertySources().addLast(mySource);
ctxWithoutName.register(ConfigWithFourResourceLocations.class);
ctxWithoutName.refresh();
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("myTestBean"));
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class AbstractEndpointTests method testGlobalEndpointsSensitive.
private void testGlobalEndpointsSensitive(boolean sensitive) {
this.context = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object>singletonMap("endpoints.sensitive", sensitive));
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isSensitive()).isEqualTo(sensitive);
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class AbstractEndpointTests method isSensitiveOverride.
@Test
public void isSensitiveOverride() throws Exception {
this.context = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object>singletonMap(this.property + ".sensitive", String.valueOf(!this.sensitive)));
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive);
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class AbstractEndpointTests method isAllEndpointsDisabled.
@Test
public void isAllEndpointsDisabled() throws Exception {
this.context = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object>singletonMap("endpoints.enabled", false));
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isEnabled()).isFalse();
}
Aggregations