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");
}
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();
}
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"));
}
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");
}
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);
}
Aggregations