Search in sources :

Example 6 with BQRuntime

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

the class HikariCPModuleIT method testDataSource_DriverAutoDetected.

@Test
public void testDataSource_DriverAutoDetected() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPModuleIT_nodriver.yml").autoLoadModules().createRuntime();
    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby2");
    assertNotNull(ds);
    assertTrue(ds instanceof HikariDataSource);
    try (Connection c = ds.getConnection()) {
        assertTrue(c.getMetaData().getDriverName().toLowerCase().contains("derby"));
    }
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) BQRuntime(io.bootique.BQRuntime) Connection(java.sql.Connection) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 7 with BQRuntime

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

the class HikariCPModuleIT method testDataSource.

@Test
public void testDataSource() {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPModuleIT_ds.yml").autoLoadModules().createRuntime();
    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby1");
    assertNotNull(ds);
    assertTrue(ds instanceof HikariDataSource);
    HikariDataSource hikariDS = (HikariDataSource) ds;
    assertEquals("jdbc:derby:target/derby1;create=true", hikariDS.getJdbcUrl());
    assertEquals("sa", hikariDS.getUsername());
    assertEquals(1, hikariDS.getMinimumIdle());
    assertEquals(3, hikariDS.getMaximumPoolSize());
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) BQRuntime(io.bootique.BQRuntime) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 8 with BQRuntime

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

the class HikariCPModuleProviderIT method testModuleDeclaresDependencies.

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

Example 9 with BQRuntime

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

the class CsvDataSetBuilderIT method setupDB.

@BeforeClass
public static void setupDB() {
    BQRuntime runtime = TEST_FACTORY.app("--config=classpath:io/bootique/jdbc/test/dataset/CsvDataSetBuilderIT.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)");
    channel.execStatement().exec("CREATE TABLE \"t4\" (\"c1\" INT, \"c2\" BOOLEAN)");
    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();
    T4 = channel.newTable("t4").columnNames("c1", "c2").initColumnTypesFromDBMetadata().build();
}
Also used : DatabaseChannel(io.bootique.jdbc.test.DatabaseChannel) BQRuntime(io.bootique.BQRuntime) BeforeClass(org.junit.BeforeClass)

Example 10 with BQRuntime

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

the class DerbyDatabaseIT method before.

@Before
public void before() {
    this.derbyDir = new File("target/derby/DerbyDatabaseIT");
    BQRuntime runtime = testFactory.app("--config=classpath:io/bootique/jdbc/test/DerbyDatabaseIT.yml").autoLoadModules().createRuntime();
    this.channel = DatabaseChannel.get(runtime);
    assertNotNull(this.channel);
}
Also used : BQRuntime(io.bootique.BQRuntime) File(java.io.File) Before(org.junit.Before)

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