DataSourceManager { public static DataSource create(DataSourceConfiguration configuration) throws SQLMissingDependencyException, SQLConfigurationException { configuration.validate(); DataSourceConfiguration config = (DataSourceConfiguration)configuration.clone(); try { Driver driver = (Driver)Class.forName(config.getDriver()).newInstance(); } catch (Exception e) { throw new SQLMissingDependencyException("Database driver '" + config.getDriver() + "' failed to load. Perhaps missing jar file?", e); } String adapterClass = config.getProvider().getAdapter(); DataSourceAdapter adapter = null; try { adapter = (DataSourceAdapter)Class.forName(adapterClass).newInstance(); } catch (Exception e) { throw new SQLMissingDependencyException("DataSourceAdapter '" + adapterClass + "' failed to load. Perhaps missing jar file?", e); } ManagedDataSource mds = adapter.create(config); if (config.getJmx()) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { ObjectName name = new ObjectName(config.getJmxDomain() + ":type=ManagedDataSource,name=" + config.getName()); mbs.registerMBean(mds, name); } catch (Exception e) { logger.error("Error while attempting to register ManagedDataSourceMBean '" + config.getName() + "'", e); } } return mds.getDataSource(); } private  DataSourceManager(); static void verify(DataSource ds); static DataSource create(DataSourceConfiguration configuration);  }
@Test public void createFailsWithMissingDefaultProperties() throws Exception { DataSourceConfiguration config = new DataSourceConfiguration(); try { DataSourceManager.create(config); Assert.fail("create() should have failed"); } catch (SQLConfigurationException e) { } config.setUsername("test"); try { DataSourceManager.create(config); Assert.fail("create() should have failed"); } catch (SQLConfigurationException e) { } config.setPassword("test"); try { DataSourceManager.create(config); Assert.fail("create() should have failed"); } catch (SQLConfigurationException e) { } config.setName("test"); try { DataSourceManager.create(config); Assert.fail("create() should have failed"); } catch (SQLConfigurationException e) { } config.setUrl("jdbc:mysql: }