下面列出了怎么用org.springframework.boot.context.properties.ConfigurationPropertiesBindException的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testConfigurationWithUnknownControlFlag() throws Exception {
ConfigFile configFile = new ConfigFile(
new ClassPathResource("jaas-sample-kafka-only.conf").getURI());
assertThatThrownBy(() -> SpringApplication.run(SimpleApplication.class,
"--spring.cloud.stream.kafka.binder.jaas.options.useKeyTab=true",
"--spring.cloud.stream.kafka.binder.jaas.controlFlag=unknown",
"--spring.cloud.stream.kafka.binder.jaas.options.storeKey=true",
"--spring.cloud.stream.kafka.binder.jaas.options.keyTab=/etc/security/keytabs/kafka_client.keytab",
"--spring.[email protected]EXAMPLE.COM",
"--spring.jmx.enabled=false"))
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasMessageContaining(
"Error creating bean with name 'configurationProperties'");
}
@Test
void whenGivenNameEmpty_thenNotBlankValidationFails() {
properties.put("app.properties.name", "");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("Field error in object 'app.properties' on field 'name'")
.hasStackTraceContaining("[must not be blank]");
}
@Test
void whenGivenNameDoesNotContainBaseName_thenCustomAppPropertiesValidatorFails() {
properties.put("app.properties.name", "My App");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("Field error in object 'app.properties' on field 'name'")
.hasStackTraceContaining("[The application name must contain [Application] base name]");
}
@Test
void whenGivenReportIntervalInDaysMoreThan30_thenMaxValidationFails() {
properties.put("app.properties.report.interval-in-days", "31");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("rejected value [31]");
}
@Test
void whenGivenReportIntervalInDaysLessThan7_thenMinValidationFails() {
properties.put("app.properties.report.interval-in-days", "6");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("rejected value [6]");
}
@Test
void whenGivenReportEmailAddressIsNotWellFormed_thenEmailValidationFails() {
properties.put("app.properties.report.email-address", "manager.analysisapp.com");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("rejected value [manager.analysisapp.com]");
}
@Test
void whenGivenReportEmailAddressDoesNotContainAnalysisappDomain_thenCustomEmailValidatorFails() {
properties.put("app.properties.report.email-address", "[email protected]");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("Field error in object 'app.properties.report' on field 'emailAddress'")
.hasStackTraceContaining("[The email address must contain [@analysisapp.com] domain]");
}
@Test
void whenGivenThirdPartyComponentNameIsEmpty_thenNotBlankValidationFails() {
properties.put("app.third-party.properties.name", "");
assertThatThrownBy(application::run)
.isInstanceOf(ConfigurationPropertiesBindException.class)
.hasRootCauseInstanceOf(BindValidationException.class)
.hasStackTraceContaining("Field error in object 'app.third-party.properties' on field 'name'")
.hasStackTraceContaining("[must not be blank]");
}
@Test
void bindInvalidProperties() {
this.context.register(ServiceBrokerPropertiesConfiguration.class);
TestPropertyValues.of("spring.cloud.openservicebroker.catalog.services[0].id:service-one-id")
.applyTo(this.context);
assertThrows(ConfigurationPropertiesBindException.class, this.context::refresh);
}
@Test(expected = ConfigurationPropertiesBindException.class)
public void validatedConfigProperties() {
new SpringApplicationBuilder(ValidatedConfiguration.class).web(WebApplicationType.NONE)
.run("--spring.jmx.enabled=false");
fail();
}
@Test
public void customPathMustBeginWithASlash() {
this.thrown.expect(UnsatisfiedDependencyException.class);
this.thrown.expectCause(
allOf(instanceOf(ConfigurationPropertiesBindException.class), hasProperty("cause",
allOf(instanceOf(BindException.class), hasProperty("cause",
allOf(instanceOf(BindValidationException.class),
hasProperty("message", containsString("Path must start with /"))))))));
load(CxfAutoConfiguration.class, "cxf.path=invalid");
}