Search in sources :

Example 1 with InvalidConfigurationPropertyValueException

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithUnknownKey.

@Test
void analysisWithUnknownKey() {
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.key.not.defined", "invalid", "This is not valid.");
    assertThat(performAnalysis(failure)).isNull();
}
Also used : InvalidConfigurationPropertyValueException(cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidConfigurationPropertyValueException

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithNullEnvironment.

@Test
void analysisWithNullEnvironment() {
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
    FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer(environment).analyze(failure);
    assertThat(analysis).isNull();
}
Also used : InvalidConfigurationPropertyValueException(cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 3 with InvalidConfigurationPropertyValueException

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithKnownProperty.

@Test
void analysisWithKnownProperty() {
    MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("test.property", "invalid"));
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
    FailureAnalysis analysis = performAnalysis(failure);
    assertCommonParts(failure, analysis);
    assertThat(analysis.getAction()).contains("Review the value of the property with the provided reason.");
    assertThat(analysis.getDescription()).contains("Validation failed for the following reason").contains("This is not valid.").doesNotContain("Additionally, this property is also set");
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) InvalidConfigurationPropertyValueException(cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 4 with InvalidConfigurationPropertyValueException

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithKnownPropertyAndOtherCandidates.

@Test
void analysisWithKnownPropertyAndOtherCandidates() {
    MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("test.property", "invalid"));
    MapPropertySource additional = new MapPropertySource("additional", Collections.singletonMap("test.property", "valid"));
    MapPropertySource another = new MapPropertySource("another", Collections.singletonMap("test.property", "test"));
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    this.environment.getPropertySources().addLast(additional);
    this.environment.getPropertySources().addLast(OriginCapablePropertySource.get(another));
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
    FailureAnalysis analysis = performAnalysis(failure);
    assertCommonParts(failure, analysis);
    assertThat(analysis.getAction()).contains("Review the value of the property with the provided reason.");
    assertThat(analysis.getDescription()).contains("Additionally, this property is also set in the following property sources:").contains("In 'additional' with the value 'valid'").contains("In 'another' with the value 'test' (originating from 'TestOrigin test.property')");
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) InvalidConfigurationPropertyValueException(cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 5 with InvalidConfigurationPropertyValueException

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithNullEnvironment.

@Test
void analysisWithNullEnvironment() {
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
    FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer(environment).analyze(failure);
    assertThat(analysis).isNull();
}
Also used : InvalidConfigurationPropertyValueException(cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidConfigurationPropertyValueException (cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException)10 Test (org.junit.jupiter.api.Test)10 FailureAnalysis (cn.taketoday.framework.diagnostics.FailureAnalysis)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6