InvalidConfigDataPropertyExceptionTests Class — spring-boot Architecture
Architecture documentation for the InvalidConfigDataPropertyExceptionTests class in InvalidConfigDataPropertyExceptionTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java lines 40–165
class InvalidConfigDataPropertyExceptionTests {
private final ConfigDataResource resource = new TestConfigDataResource();
private final ConfigurationPropertyName replacement = ConfigurationPropertyName.of("replacement");
private final ConfigurationPropertyName invalid = ConfigurationPropertyName.of("invalid");
private final ConfigurationProperty property = new ConfigurationProperty(this.invalid, "bad",
MockOrigin.of("origin"));
private final ConversionService conversionService = DefaultConversionService.getSharedInstance();
@Test
void createHasCorrectMessage() {
assertThat(new InvalidConfigDataPropertyException(this.property, false, this.replacement, this.resource))
.hasMessage(
"Property 'invalid' imported from location 'test' is invalid and should be replaced with 'replacement' [origin: origin]");
}
@Test
void createWhenNoLocationHasCorrectMessage() {
assertThat(new InvalidConfigDataPropertyException(this.property, false, this.replacement, null))
.hasMessage("Property 'invalid' is invalid and should be replaced with 'replacement' [origin: origin]");
}
@Test
void createWhenNoReplacementHasCorrectMessage() {
assertThat(new InvalidConfigDataPropertyException(this.property, false, null, this.resource))
.hasMessage("Property 'invalid' imported from location 'test' is invalid [origin: origin]");
}
@Test
void createWhenNoOriginHasCorrectMessage() {
ConfigurationProperty property = new ConfigurationProperty(this.invalid, "bad", null);
assertThat(new InvalidConfigDataPropertyException(property, false, this.replacement, this.resource)).hasMessage(
"Property 'invalid' imported from location 'test' is invalid and should be replaced with 'replacement'");
}
@Test
void createWhenProfileSpecificHasCorrectMessage() {
ConfigurationProperty property = new ConfigurationProperty(this.invalid, "bad", null);
assertThat(new InvalidConfigDataPropertyException(property, true, null, this.resource))
.hasMessage("Property 'invalid' imported from location 'test' is invalid in a profile specific resource");
}
@Test
void getPropertyReturnsProperty() {
InvalidConfigDataPropertyException exception = new InvalidConfigDataPropertyException(this.property, false,
this.replacement, this.resource);
assertThat(exception.getProperty()).isEqualTo(this.property);
}
@Test
void getLocationReturnsLocation() {
InvalidConfigDataPropertyException exception = new InvalidConfigDataPropertyException(this.property, false,
this.replacement, this.resource);
assertThat(exception.getLocation()).isEqualTo(this.resource);
}
@Test
void getReplacementReturnsReplacement() {
InvalidConfigDataPropertyException exception = new InvalidConfigDataPropertyException(this.property, false,
this.replacement, this.resource);
assertThat(exception.getReplacement()).isEqualTo(this.replacement);
}
@Test
void throwOrWarnWhenHasInvalidPropertyThrowsException() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.profiles", "a");
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(propertySource,
this.conversionService);
assertThatExceptionOfType(InvalidConfigDataPropertyException.class)
.isThrownBy(() -> InvalidConfigDataPropertyException.throwIfPropertyFound(contributor))
.withMessageStartingWith("Property 'spring.profiles' is invalid and should be replaced with "
+ "'spring.config.activate.on-profile'");
}
@Test
void throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException() {
throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.include");
throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.active");
throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException("spring.profiles.default");
}
@Test
void throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyOnIgnoringProfilesContributorDoesNotThrowException() {
ConfigDataEnvironmentContributor contributor = createInvalidProfileSpecificPropertyContributor(
"spring.profiles.active", ConfigData.Option.IGNORE_PROFILES);
assertThatNoException().isThrownBy(() -> InvalidConfigDataPropertyException.throwIfPropertyFound(contributor));
}
private void throwOrWarnWhenWhenHasInvalidProfileSpecificPropertyThrowsException(String name) {
ConfigDataEnvironmentContributor contributor = createInvalidProfileSpecificPropertyContributor(name);
assertThatExceptionOfType(InvalidConfigDataPropertyException.class)
.isThrownBy(() -> InvalidConfigDataPropertyException.throwIfPropertyFound(contributor))
.withMessageStartingWith("Property '" + name + "' is invalid in a profile specific resource");
}
private ConfigDataEnvironmentContributor createInvalidProfileSpecificPropertyContributor(String name,
ConfigData.Option... configDataOptions) {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty(name, "a");
return new ConfigDataEnvironmentContributor(Kind.BOUND_IMPORT, null, null, true, propertySource,
ConfigurationPropertySource.from(propertySource), null, ConfigData.Options.of(configDataOptions), null,
this.conversionService);
}
@Test
void throwOrWarnWhenHasNoInvalidPropertyDoesNothing() {
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor
.ofExisting(new MockPropertySource(), this.conversionService);
InvalidConfigDataPropertyException.throwIfPropertyFound(contributor);
}
private static final class TestConfigDataResource extends ConfigDataResource {
@Override
public String toString() {
return "test";
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free