RelationalProvider implements SchematicDbProvider<RelationalDb> { @Override public RelationalDb getDB(String type, Document configuration) { if (!RelationalDbConfig.ALIASES.contains(type.toLowerCase())) { return null; } return new RelationalDb(configuration); }  @Override RelationalDb getDB(String type, Document configuration);  }
@Test public void shouldReturnDefaultDbWhenNoExplicitConfigurationGiven() { BasicDocument configDocument = new BasicDocument(Schematic.TYPE_FIELD, RelationalDbConfig.ALIAS1); RelationalDb db = Schematic.getDb(configDocument); assertNotNull(db); assertEquals(RelationalDbConfig.DEFAULT_CONNECTION_URL, db.id()); RelationalDbConfig config = db.config(); assertNotNull(config); assertTrue(config.createOnStart()); assertFalse(config.dropOnExit()); assertEquals(RelationalDbConfig.DEFAULT_TABLE_NAME, config.tableName()); assertEquals(RelationalDbConfig.DEFAULT_FETCH_SIZE, config.fetchSize()); assertFalse(config.compress()); DataSourceManager dsManager = db.dsManager(); assertNotNull(dsManager); assertEquals(DatabaseType.Name.H2, dsManager.dbType().name()); }
@Test public void shouldReturnDbConfiguredFromDocument() throws ParsingException { RelationalDb db = Schematic.getDb(RelationalProviderTest.class.getClassLoader().getResourceAsStream("db-config-h2-full.json")); assertNotNull(db); assertEquals("jdbc:h2:mem:modeshape", db.id()); RelationalDbConfig config = db.config(); assertNotNull(config); assertFalse(config.createOnStart()); assertTrue(config.dropOnExit()); assertEquals("REPO", config.tableName()); assertEquals(100, config.fetchSize()); assertFalse(config.compress()); DataSourceManager dsManager = db.dsManager(); assertNotNull(dsManager); assertEquals(DatabaseType.Name.H2, dsManager.dbType().name()); HikariDataSource dataSource = (HikariDataSource) dsManager.dataSource(); assertEquals((int) Integer.valueOf(RelationalDbConfig.DEFAULT_MIN_IDLE), dataSource.getMinimumIdle()); assertEquals((int) Integer.valueOf(RelationalDbConfig.DEFAULT_MAX_POOL_SIZE), dataSource.getMaximumPoolSize()); assertEquals((long) Integer.valueOf(RelationalDbConfig.DEFAULT_IDLE_TIMEOUT), dataSource.getIdleTimeout()); }
@Test @FixFor("MODE-2674") public void shouldAllowCustomHikariPassthroughProperties() throws ParsingException { RelationalDb db = Schematic.getDb(RelationalProviderTest.class.getClassLoader().getResourceAsStream("db-config-custom-props.json")); assertNotNull(db); DataSourceManager dsManager = db.dsManager(); HikariDataSource dataSource = (HikariDataSource) dsManager.dataSource(); assertEquals(4, dataSource.getMinimumIdle()); assertEquals(4000, dataSource.getLeakDetectionThreshold()); assertEquals(5, dataSource.getMaximumPoolSize()); assertFalse(dataSource.isReadOnly()); assertEquals("testPool", dataSource.getPoolName()); }