Search in sources :

Example 1 with OptionsCapableConnectionFactory

use of org.springframework.boot.r2dbc.OptionsCapableConnectionFactory in project spring-boot by spring-projects.

the class R2dbcAutoConfigurationTests method configureWithPoolInvokeOptionCustomizer.

@Test
void configureWithPoolInvokeOptionCustomizer() {
    this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:simple://host/database").withUserConfiguration(CustomizerConfiguration.class).run((context) -> {
        assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
        ConnectionFactory pool = context.getBean(ConnectionFactory.class);
        ConnectionFactory connectionFactory = ((ConnectionPool) pool).unwrap();
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> assertThat(options.getRequiredValue(Option.valueOf("customized"))).isEqualTo(Boolean.TRUE));
    });
}
Also used : ConnectionPool(io.r2dbc.pool.ConnectionPool) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 2 with OptionsCapableConnectionFactory

use of org.springframework.boot.r2dbc.OptionsCapableConnectionFactory in project spring-boot by spring-projects.

the class R2dbcAutoConfigurationTests method configureWithoutPoolShouldApplyAdditionalProperties.

@Test
void configureWithoutPoolShouldApplyAdditionalProperties() {
    this.contextRunner.withPropertyValues("spring.r2dbc.pool.enabled=false", "spring.r2dbc.url:r2dbc:simple://foo", "spring.r2dbc.properties.test=value", "spring.r2dbc.properties.another=2").run((context) -> {
        ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> {
            assertThat(options.getRequiredValue(Option.<String>valueOf("test"))).isEqualTo("value");
            assertThat(options.getRequiredValue(Option.<String>valueOf("another"))).isEqualTo("2");
        });
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 3 with OptionsCapableConnectionFactory

use of org.springframework.boot.r2dbc.OptionsCapableConnectionFactory in project spring-boot by spring-projects.

the class R2dbcAutoConfigurationTests method configureWithPoolShouldApplyAdditionalProperties.

@Test
void configureWithPoolShouldApplyAdditionalProperties() {
    this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:simple://foo", "spring.r2dbc.properties.test=value", "spring.r2dbc.properties.another=2").run((context) -> {
        assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
        ConnectionFactory connectionFactory = context.getBean(ConnectionPool.class).unwrap();
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> {
            assertThat(options.getRequiredValue(Option.<String>valueOf("test"))).isEqualTo("value");
            assertThat(options.getRequiredValue(Option.<String>valueOf("another"))).isEqualTo("2");
        });
    });
}
Also used : ConnectionPool(io.r2dbc.pool.ConnectionPool) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 4 with OptionsCapableConnectionFactory

use of org.springframework.boot.r2dbc.OptionsCapableConnectionFactory in project spring-boot by spring-projects.

the class R2dbcAutoConfigurationTests method configureWithoutPoolInvokeOptionCustomizer.

@Test
void configureWithoutPoolInvokeOptionCustomizer() {
    this.contextRunner.withPropertyValues("spring.r2dbc.pool.enabled=false", "spring.r2dbc.url:r2dbc:simple://host/database").withUserConfiguration(CustomizerConfiguration.class).run((context) -> {
        assertThat(context).hasSingleBean(ConnectionFactory.class).doesNotHaveBean(ConnectionPool.class);
        ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> assertThat(options.getRequiredValue(Option.valueOf("customized"))).isEqualTo(Boolean.TRUE));
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Aggregations

H2ConnectionFactory (io.r2dbc.h2.H2ConnectionFactory)4 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)4 Test (org.junit.jupiter.api.Test)4 SimpleTestConnectionFactory (org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory)4 OptionsCapableConnectionFactory (org.springframework.boot.r2dbc.OptionsCapableConnectionFactory)4 ConnectionPool (io.r2dbc.pool.ConnectionPool)2