Search in sources :

Example 36 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class TomcatInstrumentedJdbcModuleIT method testMetricsListener_Injected.

@Test
public void testMetricsListener_Injected() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/dummy-ds.yml").autoLoadModules().createRuntime();
    TypeLiteral<Set<DataSourceListener>> typeLiteral = new TypeLiteral<Set<io.bootique.jdbc.DataSourceListener>>() {
    };
    Set<DataSourceListener> set = runtime.getInstance(Key.get(typeLiteral));
    assertEquals(set.size(), 1);
    assertTrue(set.iterator().next() instanceof TomcatMetricsInitializer);
}
Also used : Set(java.util.Set) TypeLiteral(com.google.inject.TypeLiteral) BQRuntime(io.bootique.BQRuntime) DataSourceListener(io.bootique.jdbc.DataSourceListener) Test(org.junit.Test)

Example 37 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class TomcatInstrumentedJdbcModuleProviderTest method testModuleDeclaresDependencies.

@Test
public void testModuleDeclaresDependencies() {
    final BQRuntime bqRuntime = testFactory.app().module(new TomcatInstrumentedJdbcModuleProvider()).createRuntime();
    BQRuntimeChecker.testModulesLoaded(bqRuntime, JdbcModule.class, TomcatJdbcModule.class, InstrumentedJdbcModule.class, MetricsModule.class);
}
Also used : BQRuntime(io.bootique.BQRuntime) Test(org.junit.Test)

Example 38 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class DefaultDatabaseChannelIT method loadChannel.

private DefaultDatabaseChannel loadChannel(String configResource) {
    BQRuntime runtime = TEST_FACTORY.app("-c", configResource).autoLoadModules().createRuntime();
    DatabaseChannel channel = DatabaseChannel.get(runtime);
    assertTrue(channel instanceof DefaultDatabaseChannel);
    return (DefaultDatabaseChannel) channel;
}
Also used : BQRuntime(io.bootique.BQRuntime)

Example 39 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class DataSourceFactoryIT method testForName_NoImpl.

@Test
public void testForName_NoImpl() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/DataSourceFactoryIT_notype.yml").autoLoadModules().createRuntime();
    try {
        runtime.getInstance(DataSourceFactory.class).forName("ds1");
        fail("Exception expected");
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof BootiqueException);
    }
}
Also used : BootiqueException(io.bootique.BootiqueException) ProvisionException(com.google.inject.ProvisionException) ManagedDataSourceFactory(io.bootique.jdbc.managed.ManagedDataSourceFactory) BQRuntime(io.bootique.BQRuntime) Test(org.junit.Test)

Example 40 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class DataSourceFactoryIT method testForName_SingleImpl.

@Test
public void testForName_SingleImpl() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/DataSourceFactoryIT_notype.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(Factory1.class)).createRuntime();
    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("ds1");
    assertNotNull(ds);
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) BQRuntime(io.bootique.BQRuntime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) BQTestFactory(io.bootique.test.junit.BQTestFactory) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) Assert.assertSame(org.junit.Assert.assertSame) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) BootiqueException(io.bootique.BootiqueException) List(java.util.List) Rule(org.junit.Rule) ManagedDataSourceFactory(io.bootique.jdbc.managed.ManagedDataSourceFactory) Map(java.util.Map) DataSource(javax.sql.DataSource) ManagedDataSourceSupplier(io.bootique.jdbc.managed.ManagedDataSourceSupplier) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) ProvisionException(com.google.inject.ProvisionException) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) ManagedDataSourceFactory(io.bootique.jdbc.managed.ManagedDataSourceFactory) BQRuntime(io.bootique.BQRuntime) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

BQRuntime (io.bootique.BQRuntime)45 Test (org.junit.Test)39 DataSource (javax.sql.DataSource)23 DataSourceFactory (io.bootique.jdbc.DataSourceFactory)22 HikariDataSource (com.zaxxer.hikari.HikariDataSource)12 ProvisionException (com.google.inject.ProvisionException)10 BootiqueException (io.bootique.BootiqueException)10 BQTestFactory (io.bootique.test.junit.BQTestFactory)10 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)9 Injector (com.google.inject.Injector)9 Map (java.util.Map)9 Optional (java.util.Optional)9 Assert.assertNotNull (org.junit.Assert.assertNotNull)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 Assert.fail (org.junit.Assert.fail)9 Rule (org.junit.Rule)9 Mockito.mock (org.mockito.Mockito.mock)9 JdbcModule (io.bootique.jdbc.JdbcModule)8 Connection (java.sql.Connection)7 ConfigurationFactory (io.bootique.config.ConfigurationFactory)6