Search in sources :

Example 1 with BootiqueException

use of io.bootique.BootiqueException 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 2 with BootiqueException

use of io.bootique.BootiqueException 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)

Example 3 with BootiqueException

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

the class ManagedDataSourceFactoryProxy method createDataSourceFactory.

private ManagedDataSourceFactory createDataSourceFactory(Injector injector) {
    Class<? extends ManagedDataSourceFactory> factoryType = delegateFactoryType(injector);
    ObjectMapper mapper = createObjectMapper(injector);
    // Disables all annotations to prevent the following exception:
    // "Class io.bootique.jdbc.managed.ManagedDataSourceFactoryProxy not subtype of [simple type, class com.foo.MyFactory]"
    // This should work, as we already know the subclass to instantiate. But this will ignore any custom deserializers
    // on factories, which seems like a minor limitation.
    mapper.disable(MapperFeature.USE_ANNOTATIONS);
    ManagedDataSourceFactory factory;
    try {
        factory = factoryType.newInstance();
        mapper.readerForUpdating(factory).readValue(new TreeTraversingParser(jsonNode, mapper), factoryType);
    } catch (Exception e) {
        throw new BootiqueException(1, "Deserialization of JDBC DataSource configuration failed.", e);
    }
    return factory;
}
Also used : BootiqueException(io.bootique.BootiqueException) TreeTraversingParser(com.fasterxml.jackson.databind.node.TreeTraversingParser) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BootiqueException(io.bootique.BootiqueException)

Example 4 with BootiqueException

use of io.bootique.BootiqueException 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 5 with BootiqueException

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

the class ManagedDataSourceFactoryProxyIT method testFactories_NoType_Exception.

@Test
public void testFactories_NoType_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(ManagedDataSourceFactoryY1.class).addFactoryType(ManagedDataSourceFactoryY2.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)

Aggregations

BootiqueException (io.bootique.BootiqueException)5 ProvisionException (com.google.inject.ProvisionException)4 BQRuntime (io.bootique.BQRuntime)4 Test (org.junit.Test)4 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)3 Injector (com.google.inject.Injector)3 BQTestFactory (io.bootique.test.junit.BQTestFactory)3 Map (java.util.Map)3 Optional (java.util.Optional)3 DataSource (javax.sql.DataSource)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Assert.fail (org.junit.Assert.fail)3 Rule (org.junit.Rule)3 Mockito.mock (org.mockito.Mockito.mock)3 ConfigurationFactory (io.bootique.config.ConfigurationFactory)2 DataSourceFactory (io.bootique.jdbc.DataSourceFactory)2 JdbcModule (io.bootique.jdbc.JdbcModule)2 ManagedDataSourceFactory (io.bootique.jdbc.managed.ManagedDataSourceFactory)2 TypeRef (io.bootique.type.TypeRef)2