Search in sources :

Example 6 with MapPropertySource

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

the class PropertySourcesPropertyValuesTests method testOrderPreserved.

@Test
public void testOrderPreserved() {
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();
    map.put("one", 1);
    map.put("two", 2);
    map.put("three", 3);
    map.put("four", 4);
    map.put("five", 5);
    this.propertySources.addFirst(new MapPropertySource("ordered", map));
    PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
    PropertyValue[] values = propertyValues.getPropertyValues();
    assertThat(values).hasSize(6);
    Collection<String> names = new ArrayList<>();
    for (PropertyValue value : values) {
        names.add(value.getName());
    }
    assertThat(names).containsExactly("one", "two", "three", "four", "five", "name");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) ArrayList(java.util.ArrayList) PropertyValue(org.springframework.beans.PropertyValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with MapPropertySource

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

the class PropertySourcesPropertyValuesTests method init.

@Before
public void init() {
    this.propertySources.addFirst(new PropertySource<String>("static", "foo") {

        @Override
        public Object getProperty(String name) {
            if (name.equals(getSource())) {
                return "bar";
            }
            return null;
        }
    });
    this.propertySources.addFirst(new MapPropertySource("map", Collections.<String, Object>singletonMap("name", "${foo}")));
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Before(org.junit.Before)

Example 8 with MapPropertySource

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

the class RelaxedPropertyResolverTests method setup.

@Before
public void setup() {
    this.environment = new StandardEnvironment();
    this.source = new LinkedHashMap<>();
    this.source.put("myString", "value");
    this.source.put("myobject", "object");
    this.source.put("myInteger", 123);
    this.source.put("myClass", "java.lang.String");
    this.environment.getPropertySources().addFirst(new MapPropertySource("test", this.source));
    this.resolver = new RelaxedPropertyResolver(this.environment);
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Before(org.junit.Before)

Example 9 with MapPropertySource

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

the class ConfigFileApplicationListenerTests method addBeforeDefaultProperties.

@Test
public void addBeforeDefaultProperties() throws Exception {
    MapPropertySource defaultSource = new MapPropertySource("defaultProperties", Collections.<String, Object>singletonMap("the.property", "fromdefaultproperties"));
    this.environment.getPropertySources().addFirst(defaultSource);
    this.initializer.setSearchNames("testproperties");
    this.initializer.postProcessEnvironment(this.environment, this.application);
    String property = this.environment.getProperty("the.property");
    assertThat(property).isEqualTo("frompropertiesfile");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 10 with MapPropertySource

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

the class ConfigFileApplicationListenerTests method defaultPropertyAsFallback.

@Test
public void defaultPropertyAsFallback() throws Exception {
    this.environment.getPropertySources().addLast(new MapPropertySource("defaultProperties", Collections.singletonMap("my.fallback", (Object) "foo")));
    this.initializer.postProcessEnvironment(this.environment, this.application);
    String property = this.environment.getProperty("my.fallback");
    assertThat(property).isEqualTo("foo");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)72 Test (org.junit.Test)52 HashMap (java.util.HashMap)35 StandardEnvironment (org.springframework.core.env.StandardEnvironment)26 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)10 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