Search in sources :

Example 31 with BQRuntime

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

the class JdbcTestModuleIT method testListenersClasses_Injected.

@Test
public void testListenersClasses_Injected() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/test/dummy-ds.yml").autoLoadModules().module(binder -> {
        JdbcModule.extend(binder).addDataSourceListener(new TestDataSourceListener1()).addDataSourceListener(new TestDataSourceListener2());
    }).createRuntime();
    TypeLiteral<Set<io.bootique.jdbc.DataSourceListener>> typeLiteral = new TypeLiteral<Set<io.bootique.jdbc.DataSourceListener>>() {
    };
    Set<io.bootique.jdbc.DataSourceListener> set = runtime.getInstance(Key.get(typeLiteral));
    assertEquals(set.size(), 3);
}
Also used : Module(com.google.inject.Module) JdbcModule(io.bootique.jdbc.JdbcModule) DataSourceListener(io.bootique.jdbc.DataSourceListener) BQRuntime(io.bootique.BQRuntime) Key(com.google.inject.Key) Set(java.util.Set) Test(org.junit.Test) BQTestFactory(io.bootique.test.junit.BQTestFactory) Provides(com.google.inject.Provides) Binder(com.google.inject.Binder) BootLogger(io.bootique.log.BootLogger) DataSource(javax.sql.DataSource) ClassRule(org.junit.ClassRule) TypeLiteral(com.google.inject.TypeLiteral) Assert.assertEquals(org.junit.Assert.assertEquals) Singleton(com.google.inject.Singleton) Set(java.util.Set) TypeLiteral(com.google.inject.TypeLiteral) BQRuntime(io.bootique.BQRuntime) DataSourceListener(io.bootique.jdbc.DataSourceListener) Test(org.junit.Test)

Example 32 with BQRuntime

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

the class JdbcTestModuleIT method testListeners_Injected.

@Test
public void testListeners_Injected() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/test/dummy-ds.yml").autoLoadModules().module(new Module() {

        @Override
        public void configure(Binder binder) {
            JdbcModule.extend(binder).addDataSourceListener(TestDataSourceListener3.class).addDataSourceListener(TestDataSourceListener4.class);
        }

        @Singleton
        @Provides
        TestDataSourceListener3 provideListener3(BootLogger bootLogger) {
            return new TestDataSourceListener3();
        }

        @Singleton
        @Provides
        TestDataSourceListener4 provideListener4(BootLogger bootLogger) {
            return new TestDataSourceListener4();
        }
    }).createRuntime();
    TypeLiteral<Set<io.bootique.jdbc.DataSourceListener>> typeLiteral = new TypeLiteral<Set<io.bootique.jdbc.DataSourceListener>>() {
    };
    Set<io.bootique.jdbc.DataSourceListener> set = runtime.getInstance(Key.get(typeLiteral));
    assertEquals(set.size(), 3);
}
Also used : Set(java.util.Set) BQRuntime(io.bootique.BQRuntime) DataSourceListener(io.bootique.jdbc.DataSourceListener) BootLogger(io.bootique.log.BootLogger) Binder(com.google.inject.Binder) TypeLiteral(com.google.inject.TypeLiteral) Module(com.google.inject.Module) JdbcModule(io.bootique.jdbc.JdbcModule) Test(org.junit.Test)

Example 33 with BQRuntime

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

the class JdbcTestModuleProviderTest method testModuleDeclaresDependencies.

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

Example 34 with BQRuntime

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

the class TableIT method setupDB.

@BeforeClass
public static void setupDB() {
    BQRuntime runtime = TEST_FACTORY.app("--config=classpath:io/bootique/jdbc/test/TableIT.yml").autoLoadModules().createRuntime();
    DatabaseChannel channel = DatabaseChannel.get(runtime);
    channel.execStatement().exec("CREATE TABLE \"t1\" (\"c1\" INT, \"c2\" VARCHAR(10), \"c3\" VARCHAR(10))");
    channel.execStatement().exec("CREATE TABLE \"t2\" (\"c1\" INT, \"c2\" INT, \"c3\" DATE, \"c4\" TIMESTAMP)");
    channel.execStatement().exec("CREATE TABLE \"t3\" (\"c1\" INT, \"c2\" VARCHAR (10) FOR BIT DATA)");
    T1 = channel.newTable("t1").columnNames("c1", "c2", "c3").initColumnTypesFromDBMetadata().build();
    T2 = channel.newTable("t2").columnNames("c1", "c2", "c3", "c4").initColumnTypesFromDBMetadata().build();
    T3 = channel.newTable("t3").columnNames("c1", "c2").initColumnTypesFromDBMetadata().build();
}
Also used : BQRuntime(io.bootique.BQRuntime) BeforeClass(org.junit.BeforeClass)

Example 35 with BQRuntime

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

the class TestDataManagerIT method setupDB.

@BeforeClass
public static void setupDB() {
    BQRuntime testRuntime = TEST_FACTORY.app("--config=classpath:io/bootique/jdbc/test/TestDataManagerIT.yml").autoLoadModules().createRuntime();
    DatabaseChannel channel = DatabaseChannel.get(testRuntime);
    channel.execStatement().exec("CREATE TABLE \"t1\" (\"id\" INT NOT NULL PRIMARY KEY, \"name\" VARCHAR(10))");
    channel.execStatement().exec("CREATE TABLE \"t2\" (\"id\" INT NOT NULL PRIMARY KEY, \"name\" VARCHAR(10), \"t1_id\" INT)");
    T1 = channel.newTable("t1").columnNames("id", "name").build();
    T2 = channel.newTable("t2").columnNames("id", "name", "t1_id").build();
}
Also used : BQRuntime(io.bootique.BQRuntime) BeforeClass(org.junit.BeforeClass)

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