Search in sources :

Example 16 with BQRuntime

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

the class ManagedDataSourceFactoryProxyIT method testFactory_MultiLevel.

@Test
public void testFactory_MultiLevel() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factory-type.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class).addFactoryType(ManagedDataSourceFactoryX4.class)).createRuntime();
    ConfigurationFactory configFactory = runtime.getInstance(ConfigurationFactory.class);
    Map<String, ManagedDataSourceFactory> configs = configFactory.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
    }, configPrefix);
    assertTrue(configs.get("ds1") instanceof ManagedDataSourceFactoryX4);
    assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryX1);
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    DataSource ds1 = factory.forName("ds1");
    assertNotNull(ds1);
    DataSource ds2 = factory.forName("ds2");
    assertNotNull(ds2);
}
Also used : JdbcModule(io.bootique.jdbc.JdbcModule) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) BQRuntime(io.bootique.BQRuntime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BQTestFactory(io.bootique.test.junit.BQTestFactory) Injector(com.google.inject.Injector) TypeRef(io.bootique.type.TypeRef) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) BootiqueException(io.bootique.BootiqueException) Rule(org.junit.Rule) Map(java.util.Map) DataSource(javax.sql.DataSource) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) ProvisionException(com.google.inject.ProvisionException) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) Mockito.mock(org.mockito.Mockito.mock) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) BQRuntime(io.bootique.BQRuntime) DataSource(javax.sql.DataSource) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Map(java.util.Map) Test(org.junit.Test)

Example 17 with BQRuntime

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

the class ManagedDataSourceFactoryProxyIT method testFactory_HierarchicalNoType_Exception.

@Test
public void testFactory_HierarchicalNoType_Exception() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factory-notype.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class).addFactoryType(ManagedDataSourceFactoryX33.class)).createRuntime();
    try {
        runtime.getInstance(DataSourceFactory.class).forName("ds1");
        fail("Exception expected");
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof BootiqueException);
    }
}
Also used : JdbcModule(io.bootique.jdbc.JdbcModule) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) BQRuntime(io.bootique.BQRuntime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BQTestFactory(io.bootique.test.junit.BQTestFactory) Injector(com.google.inject.Injector) TypeRef(io.bootique.type.TypeRef) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) BootiqueException(io.bootique.BootiqueException) Rule(org.junit.Rule) Map(java.util.Map) DataSource(javax.sql.DataSource) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) ProvisionException(com.google.inject.ProvisionException) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) Mockito.mock(org.mockito.Mockito.mock) BootiqueException(io.bootique.BootiqueException) ProvisionException(com.google.inject.ProvisionException) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) BQRuntime(io.bootique.BQRuntime) Test(org.junit.Test)

Example 18 with BQRuntime

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

the class ManagedDataSourceFactoryProxyIT method testFactories_Hierarchical.

@Test
public void testFactories_Hierarchical() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factories-type.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class).addFactoryType(ManagedDataSourceFactoryX33.class).addFactoryType(ManagedDataSourceFactoryY1.class).addFactoryType(ManagedDataSourceFactoryY2.class)).createRuntime();
    ConfigurationFactory configFactory = runtime.getInstance(ConfigurationFactory.class);
    Map<String, ManagedDataSourceFactory> configs = configFactory.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
    }, configPrefix);
    assertTrue(configs.get("ds1") instanceof ManagedDataSourceFactoryX33);
    assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryY2);
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    DataSource ds1 = factory.forName("ds1");
    assertNotNull(ds1);
    DataSource ds2 = factory.forName("ds2");
    assertNotNull(ds2);
}
Also used : JdbcModule(io.bootique.jdbc.JdbcModule) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) BQRuntime(io.bootique.BQRuntime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BQTestFactory(io.bootique.test.junit.BQTestFactory) Injector(com.google.inject.Injector) TypeRef(io.bootique.type.TypeRef) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) BootiqueException(io.bootique.BootiqueException) Rule(org.junit.Rule) Map(java.util.Map) DataSource(javax.sql.DataSource) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) ProvisionException(com.google.inject.ProvisionException) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) Mockito.mock(org.mockito.Mockito.mock) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) BQRuntime(io.bootique.BQRuntime) DataSource(javax.sql.DataSource) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Map(java.util.Map) Test(org.junit.Test)

Example 19 with BQRuntime

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

the class ManagedDataSourceFactoryProxyIT method testFactory_MultilevelNoType.

@Test
public void testFactory_MultilevelNoType() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factory-notype.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class)).createRuntime();
    ConfigurationFactory configFactory = runtime.getInstance(ConfigurationFactory.class);
    Map<String, ManagedDataSourceFactory> configs = configFactory.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
    }, configPrefix);
    assertTrue(configs.get("ds1") instanceof ManagedDataSourceFactoryProxy);
    assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryProxy);
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    DataSource ds1 = factory.forName("ds1");
    assertNotNull(ds1);
    DataSource ds2 = factory.forName("ds2");
    assertNotNull(ds2);
}
Also used : JdbcModule(io.bootique.jdbc.JdbcModule) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) BQRuntime(io.bootique.BQRuntime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BQTestFactory(io.bootique.test.junit.BQTestFactory) Injector(com.google.inject.Injector) TypeRef(io.bootique.type.TypeRef) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) BootiqueException(io.bootique.BootiqueException) Rule(org.junit.Rule) Map(java.util.Map) DataSource(javax.sql.DataSource) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) ProvisionException(com.google.inject.ProvisionException) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) Mockito.mock(org.mockito.Mockito.mock) DataSourceFactory(io.bootique.jdbc.DataSourceFactory) BQRuntime(io.bootique.BQRuntime) ConfigurationFactory(io.bootique.config.ConfigurationFactory) Map(java.util.Map) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 20 with BQRuntime

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

the class DataSourceFactoryIT method testForName_MultiImpl.

@Test
public void testForName_MultiImpl() {
    BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/DataSourceFactoryIT_notype.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(Factory1.class).addFactoryType(Factory2.class)).createRuntime();
    try {
        runtime.getInstance(DataSourceFactory.class).forName("ds1");
        fail("Exception expected");
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof BootiqueException);
    }
}
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) BootiqueException(io.bootique.BootiqueException) ProvisionException(com.google.inject.ProvisionException) ManagedDataSourceFactory(io.bootique.jdbc.managed.ManagedDataSourceFactory) BQRuntime(io.bootique.BQRuntime) 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