Search in sources :

Example 51 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentMvcEndpointTests method nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty.

@Test
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("my.foo", "${my.bar}");
    ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources().addFirst(new MapPropertySource("unresolved-placeholder", map));
    this.mvc.perform(get("/env/my.*")).andExpect(status().isOk()).andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentMvcEndpointTests method nestedPathWithSensitivePlaceholderShouldSanitize.

@Test
public void nestedPathWithSensitivePlaceholderShouldSanitize() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("my.foo", "${my.password}");
    map.put("my.password", "hello");
    ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources().addFirst(new MapPropertySource("placeholder", map));
    this.mvc.perform(get("/env/my.*")).andExpect(status().isOk()).andExpect(content().string(containsString("\"my.foo\":\"******\"")));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentMvcEndpointTests method regex.

@Test
public void regex() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("food", null);
    ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources().addFirst(new MapPropertySource("null-value", map));
    this.mvc.perform(get("/env/foo.*")).andExpect(status().isOk()).andExpect(content().string(containsString("\"foo\":\"bar\""))).andExpect(content().string(containsString("\"fool\":\"baz\"")));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 54 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method testCompositeSource.

@SuppressWarnings("unchecked")
@Test
public void testCompositeSource() throws Exception {
    EnvironmentEndpoint report = getEndpointBean();
    CompositePropertySource source = new CompositePropertySource("composite");
    source.addPropertySource(new MapPropertySource("one", Collections.singletonMap("foo", (Object) "bar")));
    source.addPropertySource(new MapPropertySource("two", Collections.singletonMap("foo", (Object) "spam")));
    this.context.getEnvironment().getPropertySources().addFirst(source);
    Map<String, Object> env = report.invoke();
    assertThat(((Map<String, Object>) env.get("composite:one")).get("foo")).isEqualTo("bar");
}
Also used : CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) Map(java.util.Map) Test(org.junit.Test)

Example 55 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.

the class FlywayAutoConfigurationTests method overrideBaselineVersionNumber.

@Test
public void overrideBaselineVersionNumber() throws Exception {
    Map<String, Object> source = Collections.<String, Object>singletonMap("flyway.baseline-version", 1);
    this.context.getEnvironment().getPropertySources().addLast(new MapPropertySource("flyway", source));
    registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertThat(flyway.getBaselineVersion()).isEqualTo(MigrationVersion.fromVersion("1"));
}
Also used : Flyway(org.flywaydb.core.Flyway) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

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