org.springframework.boot.context.properties.bind.validation.BindValidationException Java Examples

The following examples show how to use org.springframework.boot.context.properties.bind.validation.BindValidationException. 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: RSocketConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldRequireGatewayProfile() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: not_gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).doesNotHaveBean(RSocketLiiklusService.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
}
 
Example #2
Source File: RSocketConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateParameters() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "rsocket.host: localhost"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "rsocket.port: 0"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .hasNotFailed();
    });
}
 
Example #3
Source File: DynamoDBConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateProperties() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "storage.positions.type: DYNAMODB"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "dynamodb.positionsTable: foo"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).hasNotFailed();
    });
}
 
Example #4
Source File: RedisPositionsConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void should_validate_properties() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "storage.positions.type: REDIS"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "redis.host: host"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "redis.port: 8888"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).hasNotFailed();
    });
}
 
Example #5
Source File: PulsarRecordsStorageConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateProperties() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway",
            "storage.records.type: PULSAR"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "pulsar.serviceUrl: host:6650"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).hasSingleBean(PulsarRecordsStorage.class);
    });
}
 
Example #6
Source File: KafkaRecordsStorageConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateProperties() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway",
            "storage.records.type: KAFKA"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "kafka.bootstrapServers: host:9092"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).hasSingleBean(KafkaRecordsStorage.class);
    });
}
 
Example #7
Source File: GRPCConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldRequireGatewayProfile() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: not_gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context).doesNotHaveBean(GRPCLiiklusService.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
}
 
Example #8
Source File: GRPCConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldValidateParameters() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: gateway"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "grpc.port: 0"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .hasNotFailed();
    });
}
 
Example #9
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");
}
 
Example #10
Source File: GRPCAuthConfigurationTest.java    From liiklus with MIT License 5 votes vote down vote up
@Test
void shouldValidateParametersHmac512() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: not_gateway",
            "grpc.auth.alg: HMAC512"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
}
 
Example #11
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #12
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #13
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #14
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #15
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #16
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #17
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@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]");

}
 
Example #18
Source File: GRPCAuthConfigurationTest.java    From liiklus with MIT License 5 votes vote down vote up
@Test
void shouldValidateParametersRsa512() {
    applicationContextRunner = applicationContextRunner.withPropertyValues(
            "spring.profiles.active: not_gateway",
            "grpc.auth.alg: RSA512"
    );
    applicationContextRunner.run(context -> {
        assertThat(context)
                .getFailure()
                .hasCauseInstanceOf(BindValidationException.class);
    });
}