use of io.bootique.config.ConfigurationFactory 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);
}
use of io.bootique.config.ConfigurationFactory 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);
}
use of io.bootique.config.ConfigurationFactory 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);
}
use of io.bootique.config.ConfigurationFactory 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