Search in sources :

Example 1 with InvalidConfigurationPropertyValueException

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

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(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 2 with InvalidConfigurationPropertyValueException

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

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithNullEnvironment.

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

Example 4 with InvalidConfigurationPropertyValueException

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

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(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 5 with InvalidConfigurationPropertyValueException

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

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(org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 InvalidConfigurationPropertyValueException (org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException)5 FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)4 MapPropertySource (org.springframework.core.env.MapPropertySource)3