Search in sources :

Example 41 with MapPropertySource

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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 42 with MapPropertySource

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);
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 43 with MapPropertySource

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();
}
Also used : PrintStream(java.io.PrintStream) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 44 with MapPropertySource

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");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 45 with MapPropertySource

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();
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Map(java.util.Map) HashMap(java.util.HashMap)

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