XMLDatabaseClusterConfigurationFactory implements DatabaseClusterConfigurationFactory<Z, D>, DatabaseClusterConfigurationWriter<Z, D>, Constants { @Override public <B extends DatabaseBuilder<Z, D>> DatabaseClusterConfiguration<Z, D> createConfiguration(DatabaseClusterConfigurationBuilder<Z, D, B> builder) throws SQLException { logger.log(Level.INFO, messages.init(Version.CURRENT, this.streamFactory)); try { XMLStreamReader reader = new PropertyReplacementFilter(XMLInputFactory.newFactory().createXMLStreamReader(this.streamFactory.createSource())); reader.nextTag(); String uri = reader.getNamespaceURI(); Namespace namespace = this.namespaces.get(uri); if (namespace == null) { throw new XMLStreamException(messages.unsupportedNamespace(reader)); } namespace.getReaderFactory().<Z, D, B>createReader().read(reader, builder); reader.close(); return builder.build(); } catch (XMLStreamException e) { throw new SQLException(e); } } XMLDatabaseClusterConfigurationFactory(String id, String resource);  XMLDatabaseClusterConfigurationFactory(String id, String resource, ClassLoader loader);  XMLDatabaseClusterConfigurationFactory(URL url);  XMLDatabaseClusterConfigurationFactory(XMLStreamFactory streamFactory); @Override DatabaseClusterConfiguration<Z, D> createConfiguration(DatabaseClusterConfigurationBuilder<Z, D, B> builder); @Override void added(D database, DatabaseClusterConfiguration<Z, D> configuration); @Override void removed(D database, DatabaseClusterConfiguration<Z, D> configuration); void export(DatabaseClusterConfiguration<Z, D> configuration); @Override void write(XMLStreamWriter writer, DatabaseClusterConfiguration<Z, D> config);  }
@Test public void createDriverBasedConfiguration() throws SQLException { Driver driver = new MockDriver(mock(Connection.class)); DriverManager.registerDriver(driver); try { String url1 = "jdbc:mock:db1"; Map.Entry<String, String> property1 = new SimpleImmutableEntry<>("name", "value1"); String url2 = "jdbc:mock:db2"; Map.Entry<String, String> property2 = new SimpleImmutableEntry<>("name", "value2"); DatabaseClusterConfiguration<Driver, DriverDatabase> configuration = createConfiguration(new DriverDatabaseClusterConfigurationBuilder(), url1, url2, property1, property2); DriverDatabase db1 = configuration.getDatabaseMap().get("db1"); assertSame(driver, db1.getConnectionSource()); assertEquals(url1, db1.getLocation()); assertEquals("value1", db1.getProperties().getProperty("name")); DriverDatabase db2 = configuration.getDatabaseMap().get("db2"); assertSame(driver, db2.getConnectionSource()); assertEquals(url2, db2.getLocation()); assertEquals("value2", db2.getProperties().getProperty("name")); } finally { DriverManager.deregisterDriver(driver); } }
@Test public void createDataSourceBasedConfiguration() throws SQLException { String location = MockDataSource.class.getName(); Map.Entry<String, String> property1 = new SimpleImmutableEntry<>("name", "db1"); Map.Entry<String, String> property2 = new SimpleImmutableEntry<>("name", "db2"); DatabaseClusterConfiguration<DataSource, DataSourceDatabase> configuration = createConfiguration(new DataSourceDatabaseClusterConfigurationBuilder(), location, location, property1, property2); DataSourceDatabase db1 = configuration.getDatabaseMap().get("db1"); assertTrue(db1.getConnectionSource().getClass().getName(), db1.getConnectionSource() instanceof MockDataSource); assertEquals("db1", ((MockDataSource) db1.getConnectionSource()).getName()); DataSourceDatabase db2 = configuration.getDatabaseMap().get("db2"); assertTrue(db2.getConnectionSource().getClass().getName(), db2.getConnectionSource() instanceof MockDataSource); assertEquals("db2", ((MockDataSource) db2.getConnectionSource()).getName()); }