Example usage for org.springframework.core.env MutablePropertySources size

List of usage examples for org.springframework.core.env MutablePropertySources size

Introduction

In this page you can find the example usage for org.springframework.core.env MutablePropertySources size.

Prototype

public int size() 

Source Link

Document

Return the number of PropertySource objects contained.

Usage

From source file:io.bitsquare.app.BitsquareEnvironmentTests.java

@Test
public void testPropertySourcePrecedence() {
    PropertySource commandlineProps = new MockPropertySource(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)
            .withProperty("key.x", "x.commandline");

    PropertySource filesystemProps = new MockPropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME)
            .withProperty("key.x", "x.env").withProperty("key.y", "y.env");

    ConfigurableEnvironment env = new BitsquareEnvironment(commandlineProps) {
        @Override/*  www  . ja  va2  s.  co  m*/
        PropertySource<?> filesystemProperties() {
            return filesystemProps;
        }
    };
    MutablePropertySources propertySources = env.getPropertySources();

    assertThat(propertySources.precedenceOf(named(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)), equalTo(0));
    assertThat(propertySources.precedenceOf(named(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(1));
    assertThat(propertySources.precedenceOf(named(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(2));
    assertThat(propertySources.precedenceOf(named(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME)), equalTo(3));
    assertThat(propertySources.precedenceOf(named(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(4));
    assertThat(propertySources.precedenceOf(named(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(5));
    assertThat(propertySources.size(), equalTo(6));

    assertThat(env.getProperty("key.x"), equalTo("x.commandline")); // commandline value wins due to precedence
    assertThat(env.getProperty("key.y"), equalTo("y.env")); // env value wins because it's the only one available
}