use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class AbstractEndpointTests method isEnabledFallbackToEnvironment.
@Test
public void isEnabledFallbackToEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object>singletonMap(this.property + ".enabled", false));
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isEnabled()).isFalse();
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class RemoteUrlPropertyExtractor method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS));
Assert.state(StringUtils.hasLength(url), "No remote URL specified");
Assert.state(url.indexOf(",") == -1, "Multiple URLs specified");
try {
new URI(url);
} catch (URISyntaxException ex) {
throw new IllegalStateException("Malformed URL '" + url + "'");
}
Map<String, Object> source = Collections.singletonMap("remoteUrl", (Object) url);
PropertySource<?> propertySource = new MapPropertySource("remoteUrl", source);
environment.getPropertySources().addLast(propertySource);
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class ResourceBannerTests method printBanner.
private String printBanner(Resource resource, String bootVersion, String applicationVersion, String applicationTitle) {
ResourceBanner banner = new MockResourceBanner(resource, bootVersion, applicationVersion, applicationTitle);
ConfigurableEnvironment environment = new MockEnvironment();
Map<String, Object> source = Collections.<String, Object>singletonMap("a", "1");
environment.getPropertySources().addLast(new MapPropertySource("map", source));
ByteArrayOutputStream out = new ByteArrayOutputStream();
banner.printBanner(environment, getClass(), new PrintStream(out));
return out.toString();
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringApplicationTests method commandLinePropertySourceEnhancesEnvironment.
@Test
public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.<String, Object>singletonMap("foo", "original")));
application.setEnvironment(environment);
this.context = application.run("--foo=bar", "--bar=foo");
assertThat(environment).has(matchingPropertySource(CompositePropertySource.class, "commandLineArgs"));
assertThat(environment.getProperty("bar")).isEqualTo("foo");
// New command line properties take precedence
assertThat(environment.getProperty("foo")).isEqualTo("bar");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfiguration method getMongoPorts.
@SuppressWarnings("unchecked")
private Map<String, Object> getMongoPorts(MutablePropertySources sources) {
PropertySource<?> propertySource = sources.get("mongo.ports");
if (propertySource == null) {
propertySource = new MapPropertySource("mongo.ports", new HashMap<String, Object>());
sources.addFirst(propertySource);
}
return (Map<String, Object>) propertySource.getSource();
}
Aggregations