JDBCDriverURLRecognizerEngine { public static JDBCDriverURLRecognizer getJDBCDriverURLRecognizer(final String url) { JDBCDriverURLRecognizer result = JDBC_DRIVER_URL_RECOGNIZERS.stream().filter(each -> isMatchURL(url, each)).findAny() .orElseThrow(() -> new ShardingSphereException("Cannot resolve JDBC url `%s`. Please implements `%s` and add to SPI.", url, JDBCDriverURLRecognizer.class.getName())); if (result instanceof JDBCDriverComposeURLRecognizer) { return ((JDBCDriverComposeURLRecognizer) result).getDriverURLRecognizer(url); } return result; }  static JDBCDriverURLRecognizer getJDBCDriverURLRecognizer(final String url);  }
@Test public void assertGetJDBCDriverURLRecognizerForMySQL() { assertThat(JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:mysql:xxx"), instanceOf(MySQLRecognizer.class)); }
@Test public void assertGetJDBCDriverURLRecognizerForPostgreSQL() { assertThat(JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:postgresql:xxx"), instanceOf(PostgreSQLRecognizer.class)); }
@Test public void assertGetJDBCDriverURLRecognizerForOracle() { assertThat(JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:oracle:xxx"), instanceOf(OracleRecognizer.class)); }
@Test public void assertGetJDBCDriverURLRecognizerForSQLServer() { assertThat(JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:sqlserver:xxx"), instanceOf(SQLServerRecognizer.class)); }
@Test public void assertGetJDBCDriverURLRecognizerForH2() { assertThat(JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:h2:xxx"), instanceOf(H2Recognizer.class)); }
@Test public void assertGetJDBCDriverURLRecognizerForP6spy() { JDBCDriverURLRecognizer driverURLRecognizer = JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("jdbc:p6spy:mysql:xxx"); assertThat(driverURLRecognizer.getDatabaseType(), is(new MySQLDatabaseType().getName())); assertThat(driverURLRecognizer.getDriverClassName(), is("com.p6spy.engine.spy.P6SpyDriver")); }
@Test(expected = ShardingSphereException.class) public void assertGetJDBCDriverURLRecognizerFailure() { JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer("xxx"); }