use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class DataSourceFactoryIT method testForName_ListenerLifecycle.
@Test
public void testForName_ListenerLifecycle() {
TestListener listener = new TestListener();
BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/DataSourceFactoryIT_2ds.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(Factory1.class).addDataSourceListener(listener)).createRuntime();
listener.assertEmpty();
DataSource ds1 = runtime.getInstance(DataSourceFactory.class).forName("ds1");
listener.assertDSStartup("jdbc:dummy1", ds1, 1);
DataSource ds2 = runtime.getInstance(DataSourceFactory.class).forName("ds2");
listener.assertDSStartup("jdbc:dummy2", ds2, 2);
runtime.getInstance(DataSourceFactory.class).forName("ds2");
listener.assertDSStartup("jdbc:dummy2", ds2, 2);
runtime.shutdown();
listener.assertShutdown();
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class TomcatJdbcModuleIT method testDataSource_TypeAutoDetected.
@Test
public void testDataSource_TypeAutoDetected() {
BQRuntime runtime = testFactory.app("-c", "classpath:TomcatJdbcModuleIT_notype.yml").autoLoadModules().createRuntime();
DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby3");
assertNotNull(ds);
assertTrue(ds instanceof org.apache.tomcat.jdbc.pool.DataSource);
org.apache.tomcat.jdbc.pool.DataSource tomcatDS = (org.apache.tomcat.jdbc.pool.DataSource) ds;
assertEquals("jdbc:derby:target/derby3;create=true", tomcatDS.getUrl());
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class TomcatJdbcModuleIT method testDataSource_DriverAutoDetected.
@Test
public void testDataSource_DriverAutoDetected() throws SQLException {
BQRuntime runtime = testFactory.app("-c", "classpath:TomcatJdbcModuleIT_nodriver.yml").autoLoadModules().createRuntime();
DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby2");
assertNotNull(ds);
assertTrue(ds instanceof org.apache.tomcat.jdbc.pool.DataSource);
try (Connection c = ds.getConnection()) {
assertTrue(c.getMetaData().getDriverName().toLowerCase().contains("derby"));
}
}
use of io.bootique.BQRuntime 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);
}
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class ManagedDataSourceFactoryProxyIT method testFactory_Hierarchical.
@Test
public void testFactory_Hierarchical() {
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(ManagedDataSourceFactoryX33.class).addFactoryType(ManagedDataSourceFactoryX4.class).addFactoryType(ManagedDataSourceFactoryX44.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);
}
Aggregations