}
@Test
public void ensureMultipleDriversWork() {
try {
JdbcDriverDescriptor pgsql = new JdbcDriverDescriptor("PostgreSQL", "postgresql", "org.postgresql.Driver",
BeginEndQuote.POSTGRES);
JdbcDriverDescriptor mysql = new JdbcDriverDescriptor("MySQL", "mysql", "com.mysql.jdbc.Driver",
BeginEndQuote.BLANK);
BeginEndQuote pgsqlQuotes = BeginEndQuote.fromStrings("|", "|");
Xml xml = new Xml();
xml.addDriver(pgsql, pgsqlQuotes);
xml.addDriver(mysql, null);
JdbcDriversConfig config = JdbcDriversConfig.fromXml(xml.toXml());
Map<String, JdbcDriverDescriptor> expectedDrivers = Maps.newHashMap();
expectedDrivers.put(pgsql.getName(), pgsql);
expectedDrivers.put(mysql.getName(), mysql);
Map<String, JdbcDriverDescriptor> configuredDrivers = Maps.newHashMap();
for (JdbcDriverDescriptor d : config.getRegisteredDrivers()) {
configuredDrivers.put(d.getName(), d);
}
for (Map.Entry<String, JdbcDriverDescriptor> e : expectedDrivers.entrySet()) {
JdbcDriverDescriptor driver = configuredDrivers.get(e.getKey());
assertNotNull(driver);
JdbcDriverDescriptor expectedDriver = e.getValue();
assertEquals(expectedDriver.getName(), driver.getName());
assertEquals(expectedDriver.getSubprotocol(), driver.getSubprotocol());
assertEquals(expectedDriver.getClass(), driver.getClass());
if (expectedDriver == pgsql) {
assertEquals(pgsqlQuotes, driver.getBeginEndQuotes());
} else if (expectedDriver == mysql) {
assertNull(driver.getBeginEndQuotes());
}