Search in sources :

Example 1 with MutuallyExclusiveConfigurationPropertiesException

use of cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.core.env.MapPropertySource) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 2 with MutuallyExclusiveConfigurationPropertiesException

use of cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.core.env.MapPropertySource) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 3 with MutuallyExclusiveConfigurationPropertiesException

use of cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project today-framework by TAKETODAY.

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(cn.taketoday.core.env.MapPropertySource) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 4 with MutuallyExclusiveConfigurationPropertiesException

use of cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project today-framework by TAKETODAY.

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(cn.taketoday.core.env.MapPropertySource) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 5 with MutuallyExclusiveConfigurationPropertiesException

use of cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException in project today-framework by TAKETODAY.

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(environment).analyze(failure);
    assertThat(failureAnalysis).isNull();
}
Also used : FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Aggregations

MutuallyExclusiveConfigurationPropertiesException (cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException)8 FailureAnalysis (cn.taketoday.framework.diagnostics.FailureAnalysis)8 Test (org.junit.jupiter.api.Test)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 LinkedHashMap (java.util.LinkedHashMap)4 HashMap (java.util.HashMap)2