Example usage for org.springframework.boot.autoconfigure AutoConfigurations of

List of usage examples for org.springframework.boot.autoconfigure AutoConfigurations of

Introduction

In this page you can find the example usage for org.springframework.boot.autoconfigure AutoConfigurations of.

Prototype

public static AutoConfigurations of(Class<?>... classes) 

Source Link

Usage

From source file:com.github.gavlyukovskiy.boot.jdbc.decorator.flexypool.FlexyPoolConfigurationTests.java

@Test
void testDecoratingHikariDataSourceWithCustomBeanStrategies() {
    ApplicationContextRunner contextRunner = this.contextRunner
            .withPropertyValues("spring.datasource.type:" + HikariDataSource.class.getName())
            .withConfiguration(AutoConfigurations.of(HikariConfiguration.class));

    contextRunner.run(context -> {/*from   w w w . j a  v  a  2  s  . c  om*/
        DataSource dataSource = context.getBean(DataSource.class);
        FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource,
                HikariDataSource.class);
        IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 = findStrategy(flexyPoolDataSource,
                IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
        assertThat(strategy1).isNotNull();
        assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35);
        assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000);

        RetryConnectionAcquiringStrategy strategy2 = findStrategy(flexyPoolDataSource,
                RetryConnectionAcquiringStrategy.class);
        assertThat(strategy2).isNotNull();
        assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5);

        HikariConnectionAcquiringFactory strategy3 = findStrategy(flexyPoolDataSource,
                HikariConnectionAcquiringFactory.class);
        assertThat(strategy3).isNotNull();

        Dbcp2ConnectionAcquiringFactory strategy4 = findStrategy(flexyPoolDataSource,
                Dbcp2ConnectionAcquiringFactory.class);
        assertThat(strategy4).isNull();
    });
}