Search in sources :

Example 96 with MapPropertySource

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithKnownPropertyAndNoReason.

@Test
void analysisWithKnownPropertyAndNoReason() {
    MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("test.property", "invalid"));
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", null);
    FailureAnalysis analysis = performAnalysis(failure);
    assertThat(analysis.getAction()).contains("Review the value of the property.");
    assertThat(analysis.getDescription()).contains("No reason was provided.").doesNotContain("Additionally, this property is also set");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) InvalidConfigurationPropertyValueException(org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 97 with MapPropertySource

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

the class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests method analyzeWhenNotAllPropertiesAreInTheEnvironmentShouldReturnNull.

@Test
void analyzeWhenNotAllPropertiesAreInTheEnvironmentShouldReturnNull() {
    MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("com.example.a", "alpha"));
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    MutuallyExclusiveConfigurationPropertiesException failure = new MutuallyExclusiveConfigurationPropertiesException(new HashSet<>(Arrays.asList("com.example.a", "com.example.b")), new HashSet<>(Arrays.asList("com.example.a", "com.example.b")));
    FailureAnalysis analysis = performAnalysis(failure);
    assertThat(analysis).isNull();
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 98 with MapPropertySource

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

the class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests method analyzeWhenPropertyIsInMultiplePropertySourcesShouldListEachSourceInAnalysis.

@Test
void analyzeWhenPropertyIsInMultiplePropertySourcesShouldListEachSourceInAnalysis() {
    Map<String, Object> properties = new LinkedHashMap<>();
    properties.put("com.example.a", "alpha");
    properties.put("com.example.b", "bravo");
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(new MapPropertySource("test-one", properties)));
    this.environment.getPropertySources().addLast(OriginCapablePropertySource.get(new MapPropertySource("test-two", properties)));
    MutuallyExclusiveConfigurationPropertiesException failure = new MutuallyExclusiveConfigurationPropertiesException(new HashSet<>(Arrays.asList("com.example.a", "com.example.b")), new HashSet<>(Arrays.asList("com.example.a", "com.example.b")));
    FailureAnalysis analysis = performAnalysis(failure);
    assertThat(analysis.getAction()).isEqualTo("Update your configuration so that only one of the mutually exclusive properties is configured.");
    assertThat(analysis.getDescription()).contains(String.format("The following configuration properties are mutually exclusive:%n%n\tcom.example.a%n\tcom.example.b%n")).contains(String.format("However, more than one of those properties has been configured at the same time:%n%n" + "\tcom.example.a (originating from 'TestOrigin test-one')%n" + "\tcom.example.a (originating from 'TestOrigin test-two')%n" + "\tcom.example.b (originating from 'TestOrigin test-one')%n" + "\tcom.example.b (originating from 'TestOrigin test-two')%n"));
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 99 with MapPropertySource

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

the class SpringConfigurationPropertySourcesTests method shouldTrackWhenSourceHasIdenticalName.

@Test
void shouldTrackWhenSourceHasIdenticalName() {
    MutablePropertySources sources = new MutablePropertySources();
    SpringConfigurationPropertySources configurationSources = new SpringConfigurationPropertySources(sources);
    ConfigurationPropertyName name = ConfigurationPropertyName.of("a");
    MapPropertySource source1 = new MapPropertySource("test", Collections.singletonMap("a", "s1"));
    sources.addLast(source1);
    assertThat(configurationSources.iterator().next().getConfigurationProperty(name).getValue()).isEqualTo("s1");
    MapPropertySource source2 = new MapPropertySource("test", Collections.singletonMap("a", "s2"));
    sources.remove("test");
    sources.addLast(source2);
    assertThat(configurationSources.iterator().next().getConfigurationProperty(name).getValue()).isEqualTo("s2");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.jupiter.api.Test)

Example 100 with MapPropertySource

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

the class SpringApplicationJsonEnvironmentPostProcessorTests method propertySourceOrderingWhenMultipleServletSpecificPropertySources.

@Test
void propertySourceOrderingWhenMultipleServletSpecificPropertySources() {
    MapPropertySource jndi = getPropertySource(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME, "jndi");
    this.environment.getPropertySources().addFirst(jndi);
    MapPropertySource servlet = getPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, "servlet");
    this.environment.getPropertySources().addFirst(servlet);
    MapPropertySource custom = getPropertySource("custom", "custom");
    this.environment.getPropertySources().addFirst(custom);
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "SPRING_APPLICATION_JSON={\"foo\":\"bar\"}");
    this.processor.postProcessEnvironment(this.environment, null);
    PropertySource<?> json = this.environment.getPropertySources().get("spring.application.json");
    assertThat(this.environment.getProperty("foo")).isEqualTo("custom");
    assertThat(this.environment.getPropertySources()).containsSequence(custom, json, servlet, jndi);
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)213 HashMap (java.util.HashMap)103 Test (org.junit.jupiter.api.Test)80 MutablePropertySources (org.springframework.core.env.MutablePropertySources)66 Test (org.junit.Test)59 StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 LinkedHashMap (java.util.LinkedHashMap)42 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)30 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 ArrayList (java.util.ArrayList)18 Map (java.util.Map)16 RestTemplate (org.springframework.web.client.RestTemplate)16 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)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