Search in sources :

Example 36 with MapPropertySource

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

Example 37 with MapPropertySource

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

Example 38 with MapPropertySource

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

Example 39 with MapPropertySource

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

Example 40 with MapPropertySource

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