org.springframework.boot.context.properties.bind.BindException Java Examples

The following examples show how to use org.springframework.boot.context.properties.bind.BindException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OSSCondition.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String sourceClass = "";
	if (metadata instanceof ClassMetadata) {
		sourceClass = ((ClassMetadata) metadata).getClassName();
	}
	ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
	Environment environment = context.getEnvironment();
	try {
		BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
		if (!specified.isBound()) {
			return ConditionOutcome.match(message.because("automatic OSS type"));
		}
		OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
		if (specified.get() == required) {
			return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
		}
	}
	catch (BindException ex) {
	}
	return ConditionOutcome.noMatch(message.because("unknown OSS type"));
}
 
Example #2
Source File: SchemaPluginConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateProperties() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway",
            "schema.enabled: true"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .isInstanceOf(BindException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "schema.schemaURL: " + getSchemaURL()
    );
    applicationContextRunner.run(context -> {
        assertThat(context).hasNotFailed();
    });
}
 
Example #3
Source File: ConfigurationServiceTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void validationOnCreateWorks() {
	thrown.expect(BindException.class);

	Map<String, Object> map = Collections.singletonMap("config.value", 11);

	ConfigurationService.bindOrCreate(Bindable.of(ValidatedConfig.class), map,
			"config", getValidator(), null);
}
 
Example #4
Source File: ConfigurationServiceTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void validationOnBindWorks() {
	thrown.expect(BindException.class);

	Map<String, Object> map = Collections.singletonMap("config.value", 11);

	ValidatedConfig config = new ValidatedConfig();
	ConfigurationService.bindOrCreate(Bindable.ofInstance(config), map, "config",
			getValidator(), null);
}
 
Example #5
Source File: CxfAutoConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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");
}