@Test public void testBuildWithServiceOverride() { StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()) .buildServiceRegistry(); JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); assertTrue(jdbcServices.getDialect() instanceof H2Dialect); assertTrue( jdbcServices .getConnectionProvider() .isUnwrappableAs(DriverManagerConnectionProviderImpl.class)); Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); props.setProperty(Environment.DIALECT, H2Dialect.class.getName()); serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings(props) .addService(ConnectionProvider.class, new UserSuppliedConnectionProviderImpl()) .buildServiceRegistry(); jdbcServices = serviceRegistry.getService(JdbcServices.class); assertTrue(jdbcServices.getDialect() instanceof H2Dialect); assertTrue( jdbcServices .getConnectionProvider() .isUnwrappableAs(UserSuppliedConnectionProviderImpl.class)); serviceRegistry.destroy(); }
@Test public void testBasicBuild() { StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()) .buildServiceRegistry(); JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); assertTrue(jdbcServices.getDialect() instanceof H2Dialect); assertTrue( jdbcServices .getConnectionProvider() .isUnwrappableAs(DriverManagerConnectionProviderImpl.class)); assertFalse(jdbcServices.getSqlStatementLogger().isLogToStdout()); serviceRegistry.destroy(); }
@Test public void testBuildWithLogging() { Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); props.put(Environment.SHOW_SQL, "true"); StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).buildServiceRegistry(); JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); assertTrue(jdbcServices.getDialect() instanceof H2Dialect); assertTrue( jdbcServices .getConnectionProvider() .isUnwrappableAs(DriverManagerConnectionProviderImpl.class)); assertTrue(jdbcServices.getSqlStatementLogger().isLogToStdout()); serviceRegistry.destroy(); }
@Test public void testC3P0isDefaultWhenThereIsC3P0Properties() { JdbcServices jdbcServices = serviceRegistry().getService(JdbcServices.class); ConnectionProvider provider = jdbcServices.getConnectionProvider(); assertTrue(provider instanceof C3P0ConnectionProvider); }