Search in sources :

Example 1 with MutuallyExclusiveConfigurationPropertiesException

use of org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project spring-boot by spring-projects.

the class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests method analyzeWhenEnvironmentIsNullShouldReturnNull.

@Test
void analyzeWhenEnvironmentIsNullShouldReturnNull() {
    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 failureAnalysis = new MutuallyExclusiveConfigurationPropertiesFailureAnalyzer().analyze(failure);
    assertThat(failureAnalysis).isNull();
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 2 with MutuallyExclusiveConfigurationPropertiesException

use of org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException 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 3 with MutuallyExclusiveConfigurationPropertiesException

use of org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException 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 4 with MutuallyExclusiveConfigurationPropertiesException

use of org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project spring-boot by spring-projects.

the class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests method analyzeWhenAllConfiguredPropertiesAreInTheEnvironmentShouldReturnAnalysis.

@Test
void analyzeWhenAllConfiguredPropertiesAreInTheEnvironmentShouldReturnAnalysis() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("com.example.a", "alpha");
    properties.put("com.example.b", "bravo");
    MapPropertySource source = new MapPropertySource("test", properties);
    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.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')%n" + "\tcom.example.b (originating from 'TestOrigin test')%n"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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)

Aggregations

Test (org.junit.jupiter.api.Test)4 MutuallyExclusiveConfigurationPropertiesException (org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException)4 FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)4 MapPropertySource (org.springframework.core.env.MapPropertySource)3 LinkedHashMap (java.util.LinkedHashMap)2 HashMap (java.util.HashMap)1