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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations