Search in sources :

Example 11 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method propertyOverrideInYamlMultipleValues.

@Test
public void propertyOverrideInYamlMultipleValues() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("A", "Y");
    map.put("S", 2);
    map.put("Y", 0);
    this.environment.add(new PropertySource("one", map));
    map = new LinkedHashMap<String, Object>();
    map.put("A", "Z");
    map.put("S", 3);
    this.environment.addFirst(new PropertySource("two", map));
    Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
    String yaml = this.controller.yaml("foo", "bar", false).getBody();
    assertEquals("A: Z\nS: 3\nY: 0\n", yaml);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 12 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method arrayOfObjectNestedLevelInYaml.

@Test
public void arrayOfObjectNestedLevelInYaml() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("x.a.b[0].c", "d");
    map.put("x.a.b[1].c", "d");
    this.environment.add(new PropertySource("one", map));
    Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
    String yaml = this.controller.yaml("foo", "bar", false).getBody();
    assertEquals("x:\n  a:\n    b:\n    - c: d\n    - c: d\n", yaml);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 13 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class CipherEnvironmentEncryptorTests method shouldDecryptEnvironment.

@Test
public void shouldDecryptEnvironment() {
    // given
    String secret = randomUUID().toString();
    // when
    Environment environment = new Environment("name", "profile", "label");
    environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(), "{cipher}" + this.textEncryptor.encrypt(secret))));
    // then
    assertEquals(secret, this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 14 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class CipherEnvironmentEncryptorTests method shouldDecryptEnvironmentWithKey.

@Test
public void shouldDecryptEnvironmentWithKey() {
    // given
    String secret = randomUUID().toString();
    // when
    Environment environment = new Environment("name", "profile", "label");
    environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(), "{cipher}{key:test}" + this.textEncryptor.encrypt(secret))));
    // then
    assertEquals(secret, this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 15 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class ConfigServicePropertySourceLocator method log.

private void log(Environment result) {
    if (logger.isInfoEnabled()) {
        logger.info(String.format("Located environment: name=%s, profiles=%s, label=%s, version=%s, state=%s", result.getName(), result.getProfiles() == null ? "" : Arrays.asList(result.getProfiles()), result.getLabel(), result.getVersion(), result.getState()));
    }
    if (logger.isDebugEnabled()) {
        List<PropertySource> propertySourceList = result.getPropertySources();
        if (propertySourceList != null) {
            int propertyCount = 0;
            for (PropertySource propertySource : propertySourceList) {
                propertyCount += propertySource.getSource().size();
            }
            logger.debug(String.format("Environment %s has %d property sources with %d properties.", result.getName(), result.getPropertySources().size(), propertyCount));
        }
    }
}
Also used : PropertySource(org.springframework.cloud.config.environment.PropertySource) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Aggregations

PropertySource (org.springframework.cloud.config.environment.PropertySource)33 Test (org.junit.Test)20 LinkedHashMap (java.util.LinkedHashMap)19 Environment (org.springframework.cloud.config.environment.Environment)12 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 MapPropertySource (org.springframework.core.env.MapPropertySource)4 CompositePropertySource (org.springframework.core.env.CompositePropertySource)3 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)1 EnvironmentRepository (org.springframework.cloud.config.server.environment.EnvironmentRepository)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1