Search in sources :

Example 1 with SqlStatements

use of org.jdbi.v3.core.statement.SqlStatements in project dropwizard by dropwizard.

the class JdbiFactoryTest method testBuild.

@Test
void testBuild() {
    final Environment environment = mock(Environment.class);
    final MetricRegistry metrics = mock(MetricRegistry.class);
    final LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    final HealthCheckRegistry healthChecks = mock(HealthCheckRegistry.class);
    final PooledDataSourceFactory configuration = mock(PooledDataSourceFactory.class);
    final String name = UUID.randomUUID().toString();
    final ManagedDataSource dataSource = mock(ManagedDataSource.class);
    final String validationQuery = UUID.randomUUID().toString();
    final Jdbi jdbi = mock(Jdbi.class);
    final SqlStatements sqlStatements = new SqlStatements();
    when(environment.metrics()).thenReturn(metrics);
    when(environment.lifecycle()).thenReturn(lifecycle);
    when(environment.healthChecks()).thenReturn(healthChecks);
    when(configuration.build(metrics, name)).thenReturn(dataSource);
    when(configuration.getValidationQuery()).thenReturn(Optional.of(validationQuery));
    when(configuration.isAutoCommentsEnabled()).thenReturn(true);
    when(jdbi.getConfig(SqlStatements.class)).thenReturn(sqlStatements);
    final JdbiFactory factory = spy(new JdbiFactory());
    when(factory.newInstance(dataSource)).thenReturn(jdbi);
    final Jdbi result = factory.build(environment, configuration, name);
    assertThat(result).isSameAs(jdbi);
    verify(lifecycle).manage(dataSource);
    verify(healthChecks).register(eq(name), any(JdbiHealthCheck.class));
    verify(jdbi).setSqlLogger(any(InstrumentedSqlLogger.class));
    verify(factory).buildSQLLogger(same(metrics), any(StatementNameStrategy.class));
    verify(jdbi).setTemplateEngine(any(NamePrependingTemplateEngine.class));
    verify(factory).configure(jdbi);
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) StatementNameStrategy(com.codahale.metrics.jdbi3.strategies.StatementNameStrategy) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) InstrumentedSqlLogger(com.codahale.metrics.jdbi3.InstrumentedSqlLogger) SqlStatements(org.jdbi.v3.core.statement.SqlStatements) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) Environment(io.dropwizard.setup.Environment) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) PooledDataSourceFactory(io.dropwizard.db.PooledDataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.jupiter.api.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 InstrumentedSqlLogger (com.codahale.metrics.jdbi3.InstrumentedSqlLogger)1 StatementNameStrategy (com.codahale.metrics.jdbi3.strategies.StatementNameStrategy)1 ManagedDataSource (io.dropwizard.db.ManagedDataSource)1 PooledDataSourceFactory (io.dropwizard.db.PooledDataSourceFactory)1 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)1 Environment (io.dropwizard.setup.Environment)1 Jdbi (org.jdbi.v3.core.Jdbi)1 SqlStatements (org.jdbi.v3.core.statement.SqlStatements)1 Test (org.junit.jupiter.api.Test)1